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.

105 lines
3.3 KiB

  1. package storage
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/joeslay/seaweedfs/weed/glog"
  6. "github.com/joeslay/seaweedfs/weed/operation"
  7. "github.com/joeslay/seaweedfs/weed/pb/volume_server_pb"
  8. "github.com/joeslay/seaweedfs/weed/storage/erasure_coding"
  9. "github.com/joeslay/seaweedfs/weed/storage/needle"
  10. "github.com/joeslay/seaweedfs/weed/storage/types"
  11. )
  12. func (s *Store) DeleteEcShardNeedle(ctx context.Context, ecVolume *erasure_coding.EcVolume, n *needle.Needle, cookie types.Cookie) (int64, error) {
  13. count, err := s.ReadEcShardNeedle(ctx, ecVolume.VolumeId, n)
  14. if err != nil {
  15. return 0, err
  16. }
  17. if cookie != n.Cookie {
  18. return 0, fmt.Errorf("unexpected cookie %x", cookie)
  19. }
  20. if err = s.doDeleteNeedleFromAtLeastOneRemoteEcShards(ctx, ecVolume, n.Id); err != nil {
  21. return 0, err
  22. }
  23. return int64(count), nil
  24. }
  25. func (s *Store) doDeleteNeedleFromAtLeastOneRemoteEcShards(ctx context.Context, ecVolume *erasure_coding.EcVolume, needleId types.NeedleId) error {
  26. _, _, intervals, err := ecVolume.LocateEcShardNeedle(needleId, ecVolume.Version)
  27. if len(intervals) == 0 {
  28. return erasure_coding.NotFoundError
  29. }
  30. shardId, _ := intervals[0].ToShardIdAndOffset(erasure_coding.ErasureCodingLargeBlockSize, erasure_coding.ErasureCodingSmallBlockSize)
  31. hasDeletionSuccess := false
  32. err = s.doDeleteNeedleFromRemoteEcShardServers(ctx, shardId, ecVolume, needleId)
  33. if err == nil {
  34. hasDeletionSuccess = true
  35. }
  36. for shardId = erasure_coding.DataShardsCount; shardId < erasure_coding.TotalShardsCount; shardId++ {
  37. if parityDeletionError := s.doDeleteNeedleFromRemoteEcShardServers(ctx, shardId, ecVolume, needleId); parityDeletionError == nil {
  38. hasDeletionSuccess = true
  39. }
  40. }
  41. if hasDeletionSuccess {
  42. return nil
  43. }
  44. return err
  45. }
  46. func (s *Store) doDeleteNeedleFromRemoteEcShardServers(ctx context.Context, shardId erasure_coding.ShardId, ecVolume *erasure_coding.EcVolume, needleId types.NeedleId) error {
  47. ecVolume.ShardLocationsLock.RLock()
  48. sourceDataNodes, hasShardLocations := ecVolume.ShardLocations[shardId]
  49. ecVolume.ShardLocationsLock.RUnlock()
  50. if !hasShardLocations {
  51. return fmt.Errorf("ec shard %d.%d not located", ecVolume.VolumeId, shardId)
  52. }
  53. for _, sourceDataNode := range sourceDataNodes {
  54. glog.V(4).Infof("delete from remote ec shard %d.%d from %s", ecVolume.VolumeId, shardId, sourceDataNode)
  55. err := s.doDeleteNeedleFromRemoteEcShard(ctx, sourceDataNode, ecVolume.VolumeId, ecVolume.Collection, ecVolume.Version, needleId)
  56. if err != nil {
  57. return err
  58. }
  59. glog.V(1).Infof("delete from remote ec shard %d.%d from %s: %v", ecVolume.VolumeId, shardId, sourceDataNode, err)
  60. }
  61. return nil
  62. }
  63. func (s *Store) doDeleteNeedleFromRemoteEcShard(ctx context.Context, sourceDataNode string, vid needle.VolumeId, collection string, version needle.Version, needleId types.NeedleId) error {
  64. return operation.WithVolumeServerClient(sourceDataNode, s.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
  65. // copy data slice
  66. _, err := client.VolumeEcBlobDelete(ctx, &volume_server_pb.VolumeEcBlobDeleteRequest{
  67. VolumeId: uint32(vid),
  68. Collection: collection,
  69. FileKey: uint64(needleId),
  70. Version: uint32(version),
  71. })
  72. if err != nil {
  73. return fmt.Errorf("failed to delete from ec shard %d on %s: %v", vid, sourceDataNode, err)
  74. }
  75. return nil
  76. })
  77. }