From 58ede90bbe5c8991c7cbdf140859ebfe2ee1cb67 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sun, 22 Nov 2026 18:08:39 -0800 Subject: [PATCH] storage: bound each delete-retry probe with the read-hint timeout A holder that keeps the stream open without answering held the delete's reply, even after the reporting holder took the delete. Co-Authored-By: Claude Opus 5.5 --- weed/storage/store_ec.go | 5 ++- weed/storage/store_ec_delete.go | 5 ++- weed/storage/store_ec_recover_fanout_test.go | 46 ++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/weed/storage/store_ec.go b/weed/storage/store_ec.go index f12af00555..f88894d33d 100644 --- a/weed/storage/store_ec.go +++ b/weed/storage/store_ec.go @@ -1277,8 +1277,9 @@ func (s *Store) cachedLookupEcShardLocations(ecVolume *erasure_coding.EcVolume) // to peers or reconstruction first. var errShardQuarantined = fmt.Errorf("ec shard on a quarantined disk: %w", errShardNotLocal) -// ecReadHintTimeout bounds asking a delisted holder, which may have stopped -// answering, before the read reconstructs the shard. +// ecReadHintTimeout bounds a one-byte probe of a holder that may have stopped +// answering: a delisted holder before the read reconstructs the shard, or a +// holder a delete retry asks. var ecReadHintTimeout = 5 * time.Second // askEcShardReadHints reports whether a delisted holder of the shard journaled diff --git a/weed/storage/store_ec_delete.go b/weed/storage/store_ec_delete.go index 52db034c11..3d53e4b7a0 100644 --- a/weed/storage/store_ec_delete.go +++ b/weed/storage/store_ec_delete.go @@ -68,7 +68,10 @@ func (s *Store) forwardEcDeleteOfDeletedNeedle(ecVolume *erasure_coding.EcVolume reported := false var errs []error for _, holder := range holders { - if _, deleted, _ := s.doReadRemoteEcShardInterval(context.Background(), holder, needleId, ecVolume.VolumeId, shardId, make([]byte, 1), offset, ecVolume.EncodeTsNs); !deleted { + ctx, cancel := context.WithTimeout(context.Background(), ecReadHintTimeout) + _, deleted, _ := s.doReadRemoteEcShardInterval(ctx, holder, needleId, ecVolume.VolumeId, shardId, make([]byte, 1), offset, ecVolume.EncodeTsNs) + cancel() + if !deleted { continue } reported = true diff --git a/weed/storage/store_ec_recover_fanout_test.go b/weed/storage/store_ec_recover_fanout_test.go index eb671007ca..c101e4fe95 100644 --- a/weed/storage/store_ec_recover_fanout_test.go +++ b/weed/storage/store_ec_recover_fanout_test.go @@ -477,3 +477,49 @@ func TestDeleteEcShardNeedleForwardsToTheHolderReadingDeleted(t *testing.T) { t.Errorf("forwarded %d deletes to the unreadable holder, want 0", unreadable.deletes.Load()) } } + +// A holder that stops answering after the reporter took the delete does not +// hold the delete's answer. +func TestDeleteEcShardNeedleProbeSkipsAStalledHolder(t *testing.T) { + store := newTestStore(t, 1) + store.grpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials()) + const vid = needle.VolumeId(10) + _, 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) { ecReadHintTimeout = old }(ecReadHintTimeout) + ecReadHintTimeout = 200 * time.Millisecond + + reporter := &partlyDeletedEcShardPeer{} + reporterAddr := serveEcShardPeer(t, reporter) + seedShardLocations(ecVolume, reporterAddr) + ecVolume.ShardLocationsLock.Lock() + ecVolume.ShardLocations[0] = []pb.ServerAddress{reporterAddr, serveEcShardPeer(t, stalledPeer{})} + 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(10 * time.Second): + t.Fatal("delete still waiting on the stalled holder") + } + if reporter.deletes.Load() != 1 { + t.Errorf("forwarded %d deletes to the holder reading it deleted, want 1", reporter.deletes.Load()) + } +}