You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. package filesys
  2. import (
  3. "context"
  4. "time"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. )
  8. func (wfs *WFS) loopProcessingDeletion() {
  9. ticker := time.NewTicker(2 * time.Second)
  10. wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  11. var fileIds []string
  12. for {
  13. select {
  14. case fids := <-wfs.fileIdsDeletionChan:
  15. fileIds = append(fileIds, fids...)
  16. if len(fileIds) >= 1024 {
  17. glog.V(1).Infof("deleting fileIds len=%d", len(fileIds))
  18. deleteFileIds(context.Background(), client, fileIds)
  19. fileIds = fileIds[:0]
  20. }
  21. case <-ticker.C:
  22. if len(fileIds) > 0 {
  23. glog.V(1).Infof("timed deletion fileIds len=%d", len(fileIds))
  24. deleteFileIds(context.Background(), client, fileIds)
  25. fileIds = fileIds[:0]
  26. }
  27. }
  28. }
  29. })
  30. }
  31. func (wfs *WFS) deleteFileChunks(chunks []*filer_pb.FileChunk) {
  32. if len(chunks) == 0 {
  33. return
  34. }
  35. var fileIds []string
  36. for _, chunk := range chunks {
  37. fileIds = append(fileIds, chunk.FileId)
  38. }
  39. var async = false
  40. if async {
  41. wfs.fileIdsDeletionChan <- fileIds
  42. return
  43. }
  44. wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  45. deleteFileIds(context.Background(), client, fileIds)
  46. return nil
  47. })
  48. }