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.

88 lines
2.3 KiB

6 years ago
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. ticker := time.NewTicker(5 * time.Second)
  10. lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
  11. m := make(map[string]operation.LookupResult)
  12. for _, vid := range vids {
  13. locs := f.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. var fileIds []string
  29. for {
  30. select {
  31. case fid := <-f.fileIdDeletionChan:
  32. fileIds = append(fileIds, fid)
  33. if len(fileIds) >= 4096 {
  34. glog.V(1).Infof("deleting fileIds len=%d", len(fileIds))
  35. operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
  36. fileIds = fileIds[:0]
  37. }
  38. case <-ticker.C:
  39. if len(fileIds) > 0 {
  40. glog.V(1).Infof("timed deletion fileIds len=%d", len(fileIds))
  41. operation.DeleteFilesWithLookupVolumeId(f.GrpcDialOption, fileIds, lookupFunc)
  42. fileIds = fileIds[:0]
  43. }
  44. }
  45. }
  46. }
  47. func (f *Filer) DeleteChunks(fullpath FullPath, chunks []*filer_pb.FileChunk) {
  48. for _, chunk := range chunks {
  49. glog.V(3).Infof("deleting %s chunk %s", fullpath, chunk.String())
  50. f.fileIdDeletionChan <- chunk.GetFileIdString()
  51. }
  52. }
  53. // DeleteFileByFileId direct delete by file id.
  54. // Only used when the fileId is not being managed by snapshots.
  55. func (f *Filer) DeleteFileByFileId(fileId string) {
  56. f.fileIdDeletionChan <- fileId
  57. }
  58. func (f *Filer) deleteChunksIfNotNew(oldEntry, newEntry *Entry) {
  59. if oldEntry == nil {
  60. return
  61. }
  62. if newEntry == nil {
  63. f.DeleteChunks(oldEntry.FullPath, oldEntry.Chunks)
  64. }
  65. var toDelete []*filer_pb.FileChunk
  66. newChunkIds := make(map[string]bool)
  67. for _, newChunk := range newEntry.Chunks {
  68. newChunkIds[newChunk.GetFileIdString()] = true
  69. }
  70. for _, oldChunk := range oldEntry.Chunks {
  71. if _, found := newChunkIds[oldChunk.GetFileIdString()]; !found {
  72. toDelete = append(toDelete, oldChunk)
  73. }
  74. }
  75. f.DeleteChunks(oldEntry.FullPath, toDelete)
  76. }