wfs_deletion.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package filesys
  2. import (
  3. "context"
  4. "google.golang.org/grpc"
  5. "github.com/chrislusf/seaweedfs/weed/filer2"
  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. fileIds = append(fileIds, chunk.GetFileIdString())
  17. }
  18. wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  19. wfs.deleteFileIds(wfs.option.GrpcDialOption, client, fileIds)
  20. return nil
  21. })
  22. }
  23. func (wfs *WFS) deleteFileIds(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(context.Background(), &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: wfs.AdjustedUrl(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. }