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.

92 lines
2.4 KiB

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