From 44bdfa6ca795bea19b82db41f49b33bbe8c507e5 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 14:21:45 -0800 Subject: [PATCH 1/3] master: test that an old probe round's late answer is refused by a new round Co-Authored-By: Claude Opus 5.5 --- .../master/probe_round_late_answer_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 seaweed-block/core/host/master/probe_round_late_answer_test.go diff --git a/seaweed-block/core/host/master/probe_round_late_answer_test.go b/seaweed-block/core/host/master/probe_round_late_answer_test.go new file mode 100644 index 0000000000..cf3eece67e --- /dev/null +++ b/seaweed-block/core/host/master/probe_round_late_answer_test.go @@ -0,0 +1,53 @@ +package master + +import ( + "sync" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/rpc/control" +) + +// An answer to an OLD round that arrives late, while a NEW round of the same +// volume and replica is open, is refused: it is evidence of another moment, +// so the new round never counts it (the new round sees no answer from r2). +func TestProbeRound_AnOldRoundsLateAnswerIsRefusedByTheNewRound(t *testing.T) { + hub := newProbeHub() + p := &roundEvidenceProvider{hub: hub, serverOf: func(_, r string) string { return "s2" }, ackProfile: "sync_quorum", wait: 200 * time.Millisecond, attested: attestedAs} + + var mu sync.Mutex + var held *control.ProbeAnswer // round A's answer, held back + delivered := make(chan bool, 1) + roundNode(t, hub, "s2", func(r *control.ProbeRound) *control.ProbeAnswer { + mu.Lock() + defer mu.Unlock() + if held == nil { + held = readyAnswer("s2")(r) // round A: answer later + held.DurableEnd = 99 + return nil + } + // round B: only round A's answer arrives now; B's own never does. + delivered <- hub.deliver(held) + return nil + }) + + ask := []authority.ReplicaCandidate{{ReplicaID: "r2", ServerID: "s2"}} + a, err := p.ProbePromotionCandidates("v1", authority.AuthorityBasis{}, ask) + if err != nil { + t.Fatal(err) + } + if len(a.Candidates) != 1 || a.Candidates[0].Ready { + t.Fatalf("round A (no answer in time): %+v", a.Candidates) + } + b, err := p.ProbePromotionCandidates("v1", authority.AuthorityBasis{}, ask) + if err != nil { + t.Fatal(err) + } + if ok := <-delivered; ok { + t.Fatal("the hub accepted round A's answer while round B was open") + } + if len(b.Candidates) != 1 || b.Candidates[0].Ready || b.Candidates[0].DurableLSN != 0 { + t.Fatalf("round B counted round A's late answer: %+v", b.Candidates) + } +} From dcbcb0c7b0c99721e244444dfabc90c0233c49c9 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 14:25:16 -0800 Subject: [PATCH 2/3] master: the late-answer test proves a newer round is open at the delivery Co-Authored-By: Claude Opus 5.5 --- .../master/probe_round_late_answer_test.go | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/seaweed-block/core/host/master/probe_round_late_answer_test.go b/seaweed-block/core/host/master/probe_round_late_answer_test.go index cf3eece67e..ba963776b4 100644 --- a/seaweed-block/core/host/master/probe_round_late_answer_test.go +++ b/seaweed-block/core/host/master/probe_round_late_answer_test.go @@ -18,7 +18,11 @@ func TestProbeRound_AnOldRoundsLateAnswerIsRefusedByTheNewRound(t *testing.T) { var mu sync.Mutex var held *control.ProbeAnswer // round A's answer, held back - delivered := make(chan bool, 1) + type delivery struct { + accepted, newerOpen bool + roundA, roundB uint64 + } + delivered := make(chan delivery, 1) roundNode(t, hub, "s2", func(r *control.ProbeRound) *control.ProbeAnswer { mu.Lock() defer mu.Unlock() @@ -28,7 +32,14 @@ func TestProbeRound_AnOldRoundsLateAnswerIsRefusedByTheNewRound(t *testing.T) { return nil } // round B: only round A's answer arrives now; B's own never does. - delivered <- hub.deliver(held) + // Round B must be open (registered) at that moment and distinct + // from A, so the refusal is the new round's, not a closed hub's. + hub.mu.Lock() + _, open := hub.rounds[r.RoundId] + hub.mu.Unlock() + d := delivery{roundA: held.RoundId, roundB: r.RoundId, newerOpen: open && r.RoundId != held.RoundId} + d.accepted = hub.deliver(held) + delivered <- d return nil }) @@ -44,8 +55,20 @@ func TestProbeRound_AnOldRoundsLateAnswerIsRefusedByTheNewRound(t *testing.T) { if err != nil { t.Fatal(err) } - if ok := <-delivered; ok { - t.Fatal("the hub accepted round A's answer while round B was open") + var d delivery + select { + case d = <-delivered: + case <-time.After(2 * time.Second): + t.Fatal("round A's answer was never delivered during round B") + } + mu.Lock() + captured := held != nil + mu.Unlock() + if !captured || !d.newerOpen { + t.Fatalf("no newer round open at the late delivery: captured=%v delivery=%+v", captured, d) + } + if d.accepted { + t.Fatalf("the hub accepted round A's answer (round %d) while round B (round %d) was open", d.roundA, d.roundB) } if len(b.Candidates) != 1 || b.Candidates[0].Ready || b.Candidates[0].DurableLSN != 0 { t.Fatalf("round B counted round A's late answer: %+v", b.Candidates) From 24a433038464de3dd2bd436ff628882c91b30e10 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 14:29:06 -0800 Subject: [PATCH 3/3] master: check the newer round is open after the late delivery is refused Co-Authored-By: Claude Opus 5.5 --- .../core/host/master/probe_round_late_answer_test.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/seaweed-block/core/host/master/probe_round_late_answer_test.go b/seaweed-block/core/host/master/probe_round_late_answer_test.go index ba963776b4..6542b53fb0 100644 --- a/seaweed-block/core/host/master/probe_round_late_answer_test.go +++ b/seaweed-block/core/host/master/probe_round_late_answer_test.go @@ -32,13 +32,16 @@ func TestProbeRound_AnOldRoundsLateAnswerIsRefusedByTheNewRound(t *testing.T) { return nil } // round B: only round A's answer arrives now; B's own never does. - // Round B must be open (registered) at that moment and distinct - // from A, so the refusal is the new round's, not a closed hub's. + // Round B must be open at the refusal and distinct from A, so the + // refusal is the new round's, not a closed hub's. Checked AFTER the + // delivery: a round is never reopened, so B still registered then + // proves it was open when A's answer was refused. + d := delivery{roundA: held.RoundId, roundB: r.RoundId} + d.accepted = hub.deliver(held) hub.mu.Lock() _, open := hub.rounds[r.RoundId] hub.mu.Unlock() - d := delivery{roundA: held.RoundId, roundB: r.RoundId, newerOpen: open && r.RoundId != held.RoundId} - d.accepted = hub.deliver(held) + d.newerOpen = open && r.RoundId != held.RoundId delivered <- d return nil })