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.

69 lines
1.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  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(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 := resp.LocationsMap[vid]
  43. for _, loc := range locations.Locations {
  44. lr.Locations = append(lr.Locations, operation.Location{
  45. Url: loc.Url,
  46. PublicUrl: loc.PublicUrl,
  47. })
  48. }
  49. m[vid] = lr
  50. }
  51. return m, err
  52. }
  53. _, err := operation.DeleteFilesWithLookupVolumeId(grpcDialOption, fileIds, lookupFunc)
  54. return err
  55. }