diff --git a/weed/storage/store_ec_delete.go b/weed/storage/store_ec_delete.go index 3d53e4b7a0..45e4d96218 100644 --- a/weed/storage/store_ec_delete.go +++ b/weed/storage/store_ec_delete.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "slices" + "time" "github.com/seaweedfs/seaweedfs/weed/pb" @@ -47,6 +48,10 @@ func (s *Store) DeleteEcShardNeedle(ecVolume *erasure_coding.EcVolume, n *needle } +// ecDeleteRetryTimeout bounds each delete a retry sends, so a holder that +// stops answering does not hold the reply or the holders after it. +var ecDeleteRetryTimeout = 10 * time.Second + // forwardEcDeleteOfDeletedNeedle retries a delete whose read found the needle // deleted. A holder's read checks one disk's deletion set, and a delete that // failed part way can leave its other disks live, so the delete goes to the @@ -75,7 +80,10 @@ func (s *Store) forwardEcDeleteOfDeletedNeedle(ecVolume *erasure_coding.EcVolume continue } reported = true - if err := s.doDeleteNeedleFromRemoteEcShard(holder, ecVolume.VolumeId, ecVolume.Collection, ecVolume.Version, needleId); err != nil { + ctx, cancel = context.WithTimeout(context.Background(), ecDeleteRetryTimeout) + err := s.doDeleteNeedleFromRemoteEcShard(ctx, holder, ecVolume.VolumeId, ecVolume.Collection, ecVolume.Version, needleId) + cancel() + if err != nil { errs = append(errs, err) } } @@ -142,7 +150,7 @@ func (s *Store) doDeleteNeedleFromRemoteEcShardServers(shardId erasure_coding.Sh var lastErr error for _, sourceDataNode := range sourceDataNodes { glog.V(4).Infof("delete from remote ec shard %d.%d from %s", ecVolume.VolumeId, shardId, sourceDataNode) - if err := s.doDeleteNeedleFromRemoteEcShard(sourceDataNode, ecVolume.VolumeId, ecVolume.Collection, ecVolume.Version, needleId); err == nil { + if err := s.doDeleteNeedleFromRemoteEcShard(context.Background(), sourceDataNode, ecVolume.VolumeId, ecVolume.Collection, ecVolume.Version, needleId); err == nil { return nil } else { lastErr = err @@ -153,12 +161,12 @@ func (s *Store) doDeleteNeedleFromRemoteEcShardServers(shardId erasure_coding.Sh } -func (s *Store) doDeleteNeedleFromRemoteEcShard(sourceDataNode pb.ServerAddress, vid needle.VolumeId, collection string, version needle.Version, needleId types.NeedleId) error { +func (s *Store) doDeleteNeedleFromRemoteEcShard(ctx context.Context, sourceDataNode pb.ServerAddress, vid needle.VolumeId, collection string, version needle.Version, needleId types.NeedleId) error { return operation.WithVolumeServerClient(false, sourceDataNode, s.grpcDialOption, func(client volume_server_pb.VolumeServerClient) error { // copy data slice - _, err := client.VolumeEcBlobDelete(context.Background(), &volume_server_pb.VolumeEcBlobDeleteRequest{ + _, err := client.VolumeEcBlobDelete(ctx, &volume_server_pb.VolumeEcBlobDeleteRequest{ VolumeId: uint32(vid), Collection: collection, FileKey: uint64(needleId), diff --git a/weed/storage/store_ec_recover_fanout_test.go b/weed/storage/store_ec_recover_fanout_test.go index c101e4fe95..4e3b567fd8 100644 --- a/weed/storage/store_ec_recover_fanout_test.go +++ b/weed/storage/store_ec_recover_fanout_test.go @@ -523,3 +523,60 @@ func TestDeleteEcShardNeedleProbeSkipsAStalledHolder(t *testing.T) { t.Errorf("forwarded %d deletes to the holder reading it deleted, want 1", reporter.deletes.Load()) } } + +// stalledDeleteEcShardPeer reads the needle as deleted but never answers a +// delete. +type stalledDeleteEcShardPeer struct { + deletingEcShardPeer +} + +func (p *stalledDeleteEcShardPeer) VolumeEcBlobDelete(ctx context.Context, req *volume_server_pb.VolumeEcBlobDeleteRequest) (*volume_server_pb.VolumeEcBlobDeleteResponse, error) { + <-ctx.Done() + return nil, ctx.Err() +} + +// A holder that reads the needle deleted but stalls on the delete holds +// neither the reply nor the holders after it. +func TestDeleteEcShardNeedleRetrySkipsAStalledDelete(t *testing.T) { + store := newTestStore(t, 1) + store.grpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials()) + const vid = needle.VolumeId(11) + _, n := writeEcVolumeFiles(t, store.Locations[0].Directory, vid) + for shardId := 1; shardId < erasure_coding.TotalShardsCount; shardId++ { + if err := store.MountEcShards("", vid, erasure_coding.ShardId(shardId), ""); err != nil { + t.Fatalf("mount shard %d: %v", shardId, err) + } + } + ecVolume, found := store.Locations[0].FindEcVolume(vid) + if !found { + t.Fatal("ec volume not mounted") + } + defer func(old time.Duration) { ecDeleteRetryTimeout = old }(ecDeleteRetryTimeout) + ecDeleteRetryTimeout = 200 * time.Millisecond + + reporter := &partlyDeletedEcShardPeer{} + reporterAddr := serveEcShardPeer(t, reporter) + seedShardLocations(ecVolume, reporterAddr) + ecVolume.ShardLocationsLock.Lock() + ecVolume.ShardLocations[0] = []pb.ServerAddress{serveEcShardPeer(t, &stalledDeleteEcShardPeer{}), reporterAddr} + ecVolume.ShardLocationsLock.Unlock() + + done := make(chan error, 1) + go func() { + got := new(needle.Needle) + got.Id = n.Id + _, err := store.DeleteEcShardNeedle(ecVolume, got, n.Cookie) + done <- err + }() + select { + case err := <-done: + if err != ErrorDeleted { + t.Fatalf("delete of a needle read as deleted returned %v, want %v", err, ErrorDeleted) + } + case <-time.After(5 * time.Second): + t.Fatal("delete still waiting on the holder stalled in its delete") + } + if reporter.deletes.Load() != 1 { + t.Errorf("forwarded %d deletes to the holder after the stalled one, want 1", reporter.deletes.Load()) + } +}