wfs_deletion.go 1.7 KB

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