volume, seaweed-volume: re-forward a deleted EC read's delete to the holders that read it deleted (#12903)

* storage: re-forward a deleted EC read's delete to the holders that read it deleted

The retry used first-success routing, which can stop at another copy of
the primary shard (a quarantined local one, or a replica that never saw
the delete) and leave the reporting holder's other disk live. Probe each
primary shard holder with a one-byte read and forward to those answering
deleted; with no such holder, fall back to normal routing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* seaweed-volume: re-forward a deleted EC read's delete to the holders that read it deleted

Mirror Go: probe each primary shard holder with a one-byte read and
forward the delete to those answering deleted, so the retry cannot stop
at another copy and leave the reporting holder's other disk live; with
no such holder, fall back to normal routing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

* seaweed-volume: bound each delete-retry probe with the read-hint timeout

Mirror Go: a stalled holder's probe gives up after EC_READ_HINT_TIMEOUT
and the retry moves on to the next holder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* storage: bound each delete a retry forwards

A holder that answers the probe deleted but stalls on the delete held the
reply and the holders after it. The Rust server already bounds this call
at 10 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-22 22:18:40 -08:00
1 parent a98c9e2718
commit 381f8d2c94
5 files changed
+396 -25

No files matched your search

+93
View File
@@ -16038,6 +16038,99 @@ mod tests {
}
}
// The retry goes to the holder that answered the read deleted, not to the
// first holder that takes a delete.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_batch_delete_forwards_to_the_holder_reading_the_ec_needle_deleted() {
let (peer, peer_tmp) = make_service_with_two_disk_complete_ec_volume(7068);
let vid = VolumeId(7068);
let idx_dir = peer_tmp.path().join("data1");
let mut index_only = Vec::new();
for _ in 0..2 {
let (service, tmp) = make_local_service_with_volume("", None);
for name in ["7068.ecx", "7068.ecj", "7068.vif", "7068.ec13"] {
std::fs::copy(idx_dir.join(name), tmp.path().join(name)).unwrap();
}
service
.volume_ec_shards_mount(Request::new(
volume_server_pb::VolumeEcShardsMountRequest {
volume_id: 7068,
collection: String::new(),
shard_ids: vec![13],
source_disk_type: String::new(),
recover_missing_index: false,
},
))
.await
.unwrap();
index_only.push((service, tmp));
}
let (service, _tmp) = index_only.remove(0);
let (unreadable, _unreadable_tmp) = index_only.remove(0);
peer.state
.store
.write()
.unwrap()
.find_ec_volume_mut(vid)
.unwrap()
.journal_delete(NeedleId(3))
.unwrap();
let peer_state = peer.state.clone();
let unreadable_state = unreadable.state.clone();
let (port, _shutdown) = serve_source(peer).await;
let peer_addr = format!("127.0.0.1:{port}.{port}");
let (uport, _ushutdown) = serve_source(unreadable).await;
let unreadable_addr = format!("127.0.0.1:{uport}.{uport}");
{
let store = service.state.store.read().unwrap();
let ecv = store.find_ec_volume(vid).unwrap();
let (_, _, intervals) = ecv.locate_needle(NeedleId(3)).unwrap().unwrap();
let (primary, _) = ecv.interval_to_shard_id_and_offset(&intervals[0]);
ecv.merge_shard_locations(
(0u8..14)
.map(|sid| {
if sid == primary {
(sid, vec![unreadable_addr.clone(), peer_addr.clone()])
} else {
(sid, vec![peer_addr.clone()])
}
})
.collect(),
);
}
let fid = needle::FileId::new(vid, NeedleId(3), Cookie(3));
let resp = service
.batch_delete(Request::new(volume_server_pb::BatchDeleteRequest {
file_ids: vec![fid.to_string()],
skip_cookie_check: false,
fsync: false,
}))
.await
.unwrap()
.into_inner();
assert_eq!(resp.results[0].status, 404, "{:?}", resp.results);
{
let store = peer_state.store.read().unwrap();
for (i, ec_vol) in store.find_all_ec_volumes(vid).into_iter().enumerate() {
assert!(
ec_vol.is_needle_deleted(NeedleId(3)),
"peer copy {} still serves the deleted needle",
i
);
}
}
let store = unreadable_state.store.read().unwrap();
assert!(
!store
.find_ec_volume(vid)
.unwrap()
.is_needle_deleted(NeedleId(3)),
"the delete went to the holder that could not read the shard"
);
}
#[tokio::test]
async fn volume_delete_reports_absent_volume_as_not_found() {
let (service, _tmp) = make_service_with_seed_masters(&[]);
+78 -7
View File
@@ -441,16 +441,18 @@ pub async fn delete_ec_shard_needle_distributed(
)))
}
/// A delete whose read found no needle. A holder's read checks one disk's
/// deletion set, and a delete that failed part way can leave another of its
/// disks live, so forward again, best effort; holders skip copies already
/// recording it. Nothing is sent when this server's index has no live entry.
/// A delete whose read found the needle deleted, best effort. 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 primary shard holders whose
/// read answers deleted, which skip the disks already recording it. Normal
/// routing could stop at another copy instead; it is used only when no holder
/// answers deleted. `forwardEcDeleteOfDeletedNeedle` in Go.
pub async fn forward_ec_delete_of_deleted_needle(
state: &Arc<VolumeServerState>,
vid: VolumeId,
needle_id: NeedleId,
) {
if let Err(e) = delete_ec_shard_needle_distributed(state, vid, needle_id).await {
if let Err(e) = forward_ec_delete_to_holders_reading_deleted(state, vid, needle_id).await {
tracing::debug!(
"re-forward delete of deleted ec needle {}.{}: {}",
vid.0,
@@ -460,6 +462,74 @@ pub async fn forward_ec_delete_of_deleted_needle(
}
}
async fn forward_ec_delete_to_holders_reading_deleted(
state: &Arc<VolumeServerState>,
vid: VolumeId,
needle_id: NeedleId,
) -> io::Result<()> {
let (probe, holders, collection, version) = {
let store = state.store.read().unwrap();
let ecv = store.find_ec_volume(vid).ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
format!("ec volume {} not mounted", vid.0),
)
})?;
let (_, _, intervals) = ecv.locate_needle(needle_id)?.ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
format!("needle {} not in ec volume {}", needle_id, vid.0),
)
})?;
let (shard_id, shard_offset) = intervals
.first()
.map(|i| ecv.interval_to_shard_id_and_offset(i))
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "no intervals for needle"))?;
let (locations, _) = ecv.shard_locations_snapshot();
(
EcInterval {
vid,
needle_id,
shard_id,
shard_offset,
size: 1,
expected_encode_ts_ns: ecv.encode_ts_ns,
},
locations.get(&shard_id).cloned().unwrap_or_default(),
ecv.collection.clone(),
ecv.version,
)
};
let target = EcDeleteTarget {
vid,
collection: &collection,
version,
needle_id,
};
let mut reported = false;
let mut last_err = None;
for addr in &holders {
if !matches!(
tokio::time::timeout(
EC_READ_HINT_TIMEOUT,
do_read_remote_ec_shard_interval(state, addr, probe),
)
.await,
Ok(Ok((_, true)))
) {
continue;
}
reported = true;
if let Err(e) = delete_on_remote_ec_shard(state, addr, &target).await {
last_err = Some(e);
}
}
if !reported {
return delete_ec_shard_needle_distributed(state, vid, needle_id).await;
}
last_err.map_or(Ok(()), Err)
}
/// `doDeleteNeedleFromRemoteEcShardServers` in Go. `Ok(false)` is the
/// shard-missing signal — no live holder anywhere — that triggers the
/// caller's fallback walk over the remaining shards.
@@ -1374,8 +1444,9 @@ struct EcShardMap<'a> {
parity_shards: usize,
}
/// Bounds asking a delisted holder, which may have stopped answering, before
/// the read reconstructs the shard (Go's `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 (Go's `ecReadHintTimeout`).
const EC_READ_HINT_TIMEOUT: Duration = Duration::from_secs(5);
/// Try direct peer read; on failure, reconstruct via Reed-Solomon
+3 -2
View File
@@ -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
+51 -7
View File
@@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
"slices"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb"
@@ -21,12 +23,9 @@ func (s *Store) DeleteEcShardNeedle(ecVolume *erasure_coding.EcVolume, n *needle
count, err := s.ReadEcShardNeedle(ecVolume.VolumeId, n, nil)
if errors.Is(err, ErrorDeleted) {
// The read sees one disk's deletion set, and a delete that failed
// part way can leave a sibling disk of the holder still live, so
// forward again; the holder skips the copies that already record it.
// A failed parse can overwrite n.Id, so use the requested id.
if _, size, locErr := ecVolume.FindNeedleFromEcx(needleId); locErr == nil && !size.IsDeleted() {
if fwdErr := s.doDeleteNeedleFromAtLeastOneRemoteEcShards(ecVolume, needleId); fwdErr != nil {
if fwdErr := s.forwardEcDeleteOfDeletedNeedle(ecVolume, needleId); fwdErr != nil {
glog.V(1).Infof("re-forward delete of deleted ec needle %d.%s: %v", ecVolume.VolumeId, needleId, fwdErr)
}
}
@@ -49,6 +48,51 @@ 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
// primary shard holders whose read answers deleted, which skip the disks
// already recording it. Normal routing could stop at another copy instead.
func (s *Store) forwardEcDeleteOfDeletedNeedle(ecVolume *erasure_coding.EcVolume, needleId types.NeedleId) error {
_, _, intervals, err := ecVolume.LocateEcShardNeedle(needleId, ecVolume.Version)
if err != nil {
return err
}
if len(intervals) == 0 {
return erasure_coding.NotFoundError
}
shardId, offset := ecVolume.IntervalToShardIdAndOffset(intervals[0])
ecVolume.ShardLocationsLock.RLock()
holders := slices.Clone(ecVolume.ShardLocations[shardId])
ecVolume.ShardLocationsLock.RUnlock()
reported := false
var errs []error
for _, holder := range holders {
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
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)
}
}
if !reported {
return s.doDeleteNeedleFromAtLeastOneRemoteEcShards(ecVolume, needleId)
}
return errors.Join(errs...)
}
// errEcShardMissing indicates that no data node in the topology currently
// holds the requested EC shard. Callers use this to trigger fallback to
// another shard, distinguishing "no home for this shard" from "the shard
@@ -106,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
@@ -117,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),
+171 -9
View File
@@ -396,15 +396,7 @@ func TestDeleteEcShardNeedleForwardsWhenReadSaysDeleted(t *testing.T) {
}
peer := &partlyDeletedEcShardPeer{}
lis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("listen: %v", err)
}
srv := grpc.NewServer()
volume_server_pb.RegisterVolumeServerServer(srv, peer)
go srv.Serve(lis)
t.Cleanup(srv.Stop)
seedShardLocations(ecVolume, pb.NewServerAddressWithGrpcPort("127.0.0.1:1", lis.Addr().(*net.TCPAddr).Port))
seedShardLocations(ecVolume, serveEcShardPeer(t, peer))
got := new(needle.Needle)
got.Id = n.Id
@@ -418,3 +410,173 @@ func TestDeleteEcShardNeedleForwardsWhenReadSaysDeleted(t *testing.T) {
t.Errorf("forwarded the delete of needle %s, want %s", got, n.Id)
}
}
// unreadableEcShardPeer fails its shard reads, as a quarantined copy does, and
// counts the deletes forwarded to it.
type unreadableEcShardPeer struct {
volume_server_pb.UnimplementedVolumeServerServer
deletes atomic.Int64
}
func (p *unreadableEcShardPeer) VolumeEcShardRead(req *volume_server_pb.VolumeEcShardReadRequest, stream volume_server_pb.VolumeServer_VolumeEcShardReadServer) error {
return status.Error(codes.Unavailable, "shard unreadable")
}
func (p *unreadableEcShardPeer) VolumeEcBlobDelete(ctx context.Context, req *volume_server_pb.VolumeEcBlobDeleteRequest) (*volume_server_pb.VolumeEcBlobDeleteResponse, error) {
p.deletes.Add(1)
return &volume_server_pb.VolumeEcBlobDeleteResponse{}, nil
}
func serveEcShardPeer(t *testing.T, peer volume_server_pb.VolumeServerServer) pb.ServerAddress {
t.Helper()
lis, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("listen: %v", err)
}
srv := grpc.NewServer()
volume_server_pb.RegisterVolumeServerServer(srv, peer)
go srv.Serve(lis)
t.Cleanup(srv.Stop)
return pb.NewServerAddressWithGrpcPort("127.0.0.1:1", lis.Addr().(*net.TCPAddr).Port)
}
// The retry goes to the holder that answered the read deleted, not to the
// first holder that takes a delete.
func TestDeleteEcShardNeedleForwardsToTheHolderReadingDeleted(t *testing.T) {
store := newTestStore(t, 1)
store.grpcDialOption = grpc.WithTransportCredentials(insecure.NewCredentials())
const vid = needle.VolumeId(9)
_, 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")
}
unreadable := &unreadableEcShardPeer{}
reporter := &partlyDeletedEcShardPeer{}
reporterAddr := serveEcShardPeer(t, reporter)
seedShardLocations(ecVolume, reporterAddr)
ecVolume.ShardLocationsLock.Lock()
ecVolume.ShardLocations[0] = []pb.ServerAddress{serveEcShardPeer(t, unreadable), reporterAddr}
ecVolume.ShardLocationsLock.Unlock()
got := new(needle.Needle)
got.Id = n.Id
if _, err := store.DeleteEcShardNeedle(ecVolume, got, n.Cookie); err != ErrorDeleted {
t.Fatalf("delete of a needle read as deleted returned %v, want %v", err, ErrorDeleted)
}
if reporter.deletes.Load() != 1 {
t.Errorf("forwarded %d deletes to the holder reading it deleted, want 1", reporter.deletes.Load())
}
if unreadable.deletes.Load() != 0 {
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())
}
}
// 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())
}
}