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.

84 lines
2.1 KiB

6 years ago
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/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.Url),
  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. }