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.

87 lines
2.2 KiB

6 years ago
6 years ago
  1. package filer2
  2. import (
  3. "time"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/operation"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. )
  8. func (f *Filer) loopProcessingDeletion() {
  9. lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
  10. m := make(map[string]operation.LookupResult)
  11. for _, vid := range vids {
  12. locs, _ := f.MasterClient.GetVidLocations(vid)
  13. var locations []operation.Location
  14. for _, loc := range locs {
  15. locations = append(locations, operation.Location{
  16. Url: loc.Url,
  17. PublicUrl: loc.PublicUrl,
  18. })
  19. }
  20. m[vid] = operation.LookupResult{
  21. VolumeId: vid,
  22. Locations: locations,
  23. }
  24. }
  25. return m, nil
  26. }
  27. var deletionCount int
  28. for {
  29. deletionCount = 0
  30. f.fileIdDeletionQueue.Consume(func(fileIds []string) {
  31. deletionCount = len(fileIds)
  32. deleteResults, err := operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
  33. if err != nil {
  34. glog.V(0).Infof("deleting fileIds len=%d error: %v", deletionCount, err)
  35. } else {
  36. glog.V(1).Infof("deleting fileIds len=%d", deletionCount)
  37. }
  38. if len(deleteResults) != deletionCount {
  39. glog.V(0).Infof("delete %d fileIds actual %d", deletionCount, len(deleteResults))
  40. }
  41. })
  42. if deletionCount == 0 {
  43. time.Sleep(1123 * time.Millisecond)
  44. }
  45. }
  46. }
  47. func (f *Filer) DeleteChunks(chunks []*filer_pb.FileChunk) {
  48. for _, chunk := range chunks {
  49. f.fileIdDeletionQueue.EnQueue(chunk.GetFileIdString())
  50. }
  51. }
  52. // DeleteFileByFileId direct delete by file id.
  53. // Only used when the fileId is not being managed by snapshots.
  54. func (f *Filer) DeleteFileByFileId(fileId string) {
  55. f.fileIdDeletionQueue.EnQueue(fileId)
  56. }
  57. func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) {
  58. if oldEntry == nil {
  59. return
  60. }
  61. if newEntry == nil {
  62. f.DeleteChunks(oldEntry.Chunks)
  63. }
  64. var toDelete []*filer_pb.FileChunk
  65. newChunkIds := make(map[string]bool)
  66. for _, newChunk := range newEntry.Chunks {
  67. newChunkIds[newChunk.GetFileIdString()] = true
  68. }
  69. for _, oldChunk := range oldEntry.Chunks {
  70. if _, found := newChunkIds[oldChunk.GetFileIdString()]; !found {
  71. toDelete = append(toDelete, oldChunk)
  72. }
  73. }
  74. f.DeleteChunks(toDelete)
  75. }