2019-06-20 07:55:30 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
|
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
2019-06-20 07:55:30 +00:00
|
|
|
)
|
|
|
|
|
2020-02-26 06:23:59 +00:00
|
|
|
func (s *Store) DeleteEcShardNeedle(ecVolume *erasure_coding.EcVolume, n *needle.Needle, cookie types.Cookie) (int64, error) {
|
2019-06-20 07:55:30 +00:00
|
|
|
|
2021-08-09 06:25:16 +00:00
|
|
|
count, err := s.ReadEcShardNeedle(ecVolume.VolumeId, n, nil)
|
2019-06-20 07:55:30 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if cookie != n.Cookie {
|
|
|
|
return 0, fmt.Errorf("unexpected cookie %x", cookie)
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
if err = s.doDeleteNeedleFromAtLeastOneRemoteEcShards(ecVolume, n.Id); err != nil {
|
2019-06-20 07:55:30 +00:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return int64(count), nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func (s *Store) doDeleteNeedleFromAtLeastOneRemoteEcShards(ecVolume *erasure_coding.EcVolume, needleId types.NeedleId) error {
|
2019-06-20 07:55:30 +00:00
|
|
|
|
|
|
|
_, _, intervals, err := ecVolume.LocateEcShardNeedle(needleId, ecVolume.Version)
|
|
|
|
|
|
|
|
if len(intervals) == 0 {
|
|
|
|
return erasure_coding.NotFoundError
|
|
|
|
}
|
|
|
|
|
|
|
|
shardId, _ := intervals[0].ToShardIdAndOffset(erasure_coding.ErasureCodingLargeBlockSize, erasure_coding.ErasureCodingSmallBlockSize)
|
|
|
|
|
|
|
|
hasDeletionSuccess := false
|
2020-02-26 05:50:12 +00:00
|
|
|
err = s.doDeleteNeedleFromRemoteEcShardServers(shardId, ecVolume, needleId)
|
2019-06-20 07:55:30 +00:00
|
|
|
if err == nil {
|
|
|
|
hasDeletionSuccess = true
|
|
|
|
}
|
|
|
|
|
|
|
|
for shardId = erasure_coding.DataShardsCount; shardId < erasure_coding.TotalShardsCount; shardId++ {
|
2020-02-26 05:50:12 +00:00
|
|
|
if parityDeletionError := s.doDeleteNeedleFromRemoteEcShardServers(shardId, ecVolume, needleId); parityDeletionError == nil {
|
2019-06-20 07:55:30 +00:00
|
|
|
hasDeletionSuccess = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if hasDeletionSuccess {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-26 05:50:12 +00:00
|
|
|
func (s *Store) doDeleteNeedleFromRemoteEcShardServers(shardId erasure_coding.ShardId, ecVolume *erasure_coding.EcVolume, needleId types.NeedleId) error {
|
2019-06-20 07:55:30 +00:00
|
|
|
|
|
|
|
ecVolume.ShardLocationsLock.RLock()
|
|
|
|
sourceDataNodes, hasShardLocations := ecVolume.ShardLocations[shardId]
|
|
|
|
ecVolume.ShardLocationsLock.RUnlock()
|
|
|
|
|
|
|
|
if !hasShardLocations {
|
|
|
|
return fmt.Errorf("ec shard %d.%d not located", ecVolume.VolumeId, shardId)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sourceDataNode := range sourceDataNodes {
|
|
|
|
glog.V(4).Infof("delete from remote ec shard %d.%d from %s", ecVolume.VolumeId, shardId, sourceDataNode)
|
2020-02-26 05:50:12 +00:00
|
|
|
err := s.doDeleteNeedleFromRemoteEcShard(sourceDataNode, ecVolume.VolumeId, ecVolume.Collection, ecVolume.Version, needleId)
|
2019-06-20 07:55:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
glog.V(1).Infof("delete from remote ec shard %d.%d from %s: %v", ecVolume.VolumeId, shardId, sourceDataNode, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-13 05:47:52 +00:00
|
|
|
func (s *Store) doDeleteNeedleFromRemoteEcShard(sourceDataNode pb.ServerAddress, vid needle.VolumeId, collection string, version needle.Version, needleId types.NeedleId) error {
|
2019-06-20 07:55:30 +00:00
|
|
|
|
2021-12-26 08:15:03 +00:00
|
|
|
return operation.WithVolumeServerClient(false, sourceDataNode, s.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
|
2019-06-20 07:55:30 +00:00
|
|
|
|
|
|
|
// copy data slice
|
2020-02-26 05:50:12 +00:00
|
|
|
_, err := client.VolumeEcBlobDelete(context.Background(), &volume_server_pb.VolumeEcBlobDeleteRequest{
|
2019-06-20 07:55:30 +00:00
|
|
|
VolumeId: uint32(vid),
|
|
|
|
Collection: collection,
|
|
|
|
FileKey: uint64(needleId),
|
|
|
|
Version: uint32(version),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to delete from ec shard %d on %s: %v", vid, sourceDataNode, err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|