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.

83 lines
2.0 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  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. if !chunk.IsChunkManifest {
  17. fileIds = append(fileIds, chunk.GetFileIdString())
  18. continue
  19. }
  20. dataChunks, manifestResolveErr := filer2.ResolveOneChunkManifest(filer2.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. }
  28. wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  29. wfs.deleteFileIds(wfs.option.GrpcDialOption, client, fileIds)
  30. return nil
  31. })
  32. }
  33. func (wfs *WFS) deleteFileIds(grpcDialOption grpc.DialOption, client filer_pb.SeaweedFilerClient, fileIds []string) error {
  34. var vids []string
  35. for _, fileId := range fileIds {
  36. vids = append(vids, filer2.VolumeId(fileId))
  37. }
  38. lookupFunc := func(vids []string) (map[string]operation.LookupResult, error) {
  39. m := make(map[string]operation.LookupResult)
  40. glog.V(4).Infof("deleteFileIds lookup volume id locations: %v", vids)
  41. resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
  42. VolumeIds: vids,
  43. })
  44. if err != nil {
  45. return m, err
  46. }
  47. for _, vid := range vids {
  48. lr := operation.LookupResult{
  49. VolumeId: vid,
  50. Locations: nil,
  51. }
  52. locations, found := resp.LocationsMap[vid]
  53. if !found {
  54. continue
  55. }
  56. for _, loc := range locations.Locations {
  57. lr.Locations = append(lr.Locations, operation.Location{
  58. Url: wfs.AdjustedUrl(loc.Url),
  59. PublicUrl: loc.PublicUrl,
  60. })
  61. }
  62. m[vid] = lr
  63. }
  64. return m, err
  65. }
  66. _, err := operation.DeleteFilesWithLookupVolumeId(grpcDialOption, fileIds, lookupFunc)
  67. return err
  68. }