wfs_deletion.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package filesys
  2. import (
  3. "context"
  4. "google.golang.org/grpc"
  5. "github.com/chrislusf/seaweedfs/weed/filer"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/operation"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. )
  10. func (wfs *WFS) deleteFileChunks(chunks []*filer_pb.FileChunk) {
  11. if len(chunks) == 0 {
  12. return
  13. }
  14. var fileIds []string
  15. for _, chunk := range chunks {
  16. if !chunk.IsChunkManifest {
  17. fileIds = append(fileIds, chunk.GetFileIdString())
  18. continue
  19. }
  20. dataChunks, manifestResolveErr := filer.ResolveOneChunkManifest(filer.LookupFn(wfs), chunk)
  21. if manifestResolveErr != nil {
  22. glog.V(0).Infof("failed to resolve manifest %s: %v", chunk.FileId, manifestResolveErr)
  23. }
  24. for _, dChunk := range dataChunks {
  25. fileIds = append(fileIds, dChunk.GetFileIdString())
  26. }
  27. fileIds = append(fileIds, chunk.GetFileIdString())
  28. }
  29. wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  30. wfs.deleteFileIds(wfs.option.GrpcDialOption, client, fileIds)
  31. return nil
  32. })
  33. }
  34. func (wfs *WFS) deleteFileIds(grpcDialOption grpc.DialOption, client filer_pb.SeaweedFilerClient, fileIds []string) error {
  35. var vids []string
  36. for _, fileId := range fileIds {
  37. vids = append(vids, filer.VolumeId(fileId))
  38. }
  39. lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
  40. m := make(map[string]operation.LookupResult)
  41. glog.V(4).Infof("deleteFileIds lookup volume id locations: %v", vids)
  42. resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
  43. VolumeIds: vids,
  44. })
  45. if err != nil {
  46. return m, err
  47. }
  48. for _, vid := range vids {
  49. lr := operation.LookupResult{
  50. VolumeId: vid,
  51. Locations: nil,
  52. }
  53. locations, found := resp.LocationsMap[vid]
  54. if !found {
  55. continue
  56. }
  57. for _, loc := range locations.Locations {
  58. lr.Locations = append(lr.Locations, operation.Location{
  59. Url: wfs.AdjustedUrl(loc),
  60. PublicUrl: loc.PublicUrl,
  61. })
  62. }
  63. m[vid] = lr
  64. }
  65. return m, err
  66. }
  67. _, err := operation.DeleteFilesWithLookupVolumeId(grpcDialOption, fileIds, lookupFunc)
  68. return err
  69. }