From b935d0a73bbca76ebcce3c85b88c52f89a234528 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 26 Nov 2026 15:39:02 -0800 Subject: [PATCH] fix: one read conditions the RF1 refresh; a re-based refresh is a new ask restartedHolderRefresh decides only when the line it reads is this replica's at exactly the ask's addresses, and builds ExpectCurrent from that read, so a move between the tick's address check and this read yields no refresh rather than one expecting the moved line. The controller's same-ask dedupe compares the expected line: a refresh refused because an earlier refresh moved the line is asked again against the new line instead of being suppressed as a duplicate (red locally without this: TestControllerReasksARefreshRefusedAfterTheLineMoved times out waiting for the re-ask). The host-level stale-refresh test now waits for the publication path's own refusal of that ask (bounded), instead of a sleep. block-design.md's authority diagram shows the conditional refresh. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/controller.go | 13 +++++- .../authority/refresh_expected_line_test.go | 33 +++++++++++++++ .../core/host/master/product_loop.go | 5 ++- .../host/master/rf1_restart_reissue_test.go | 41 ++++++++++++++++++- seaweed-block/docs/design/block-design.md | 1 + 5 files changed, 89 insertions(+), 4 deletions(-) diff --git a/seaweed-block/core/authority/controller.go b/seaweed-block/core/authority/controller.go index 5d27dd9c4c..b24c81008d 100644 --- a/seaweed-block/core/authority/controller.go +++ b/seaweed-block/core/authority/controller.go @@ -756,7 +756,18 @@ func sameAsk(a, b AssignmentAsk) bool { a.DataAddr == b.DataAddr && a.CtrlAddr == b.CtrlAddr && a.Intent == b.Intent && - a.Incarnation == b.Incarnation + a.Incarnation == b.Incarnation && + sameExpectedLine(a.ExpectCurrent, b.ExpectCurrent) +} + +// sameExpectedLine: two asks conditional on different lines are different +// asks (one refused because the line moved is asked again against the new +// line, not suppressed as a duplicate). +func sameExpectedLine(a, b *ExpectedLine) bool { + if a == nil || b == nil { + return a == b + } + return *a == *b } // plannedEvidence is a rebalance's evidence: the gate's probe of the target, diff --git a/seaweed-block/core/authority/refresh_expected_line_test.go b/seaweed-block/core/authority/refresh_expected_line_test.go index ec41168492..a7197e3e9c 100644 --- a/seaweed-block/core/authority/refresh_expected_line_test.go +++ b/seaweed-block/core/authority/refresh_expected_line_test.go @@ -3,6 +3,7 @@ package authority import ( "errors" "testing" + "time" "github.com/seaweedfs/seaweed-block/core/adapter" ) @@ -57,3 +58,35 @@ func TestControllerRefreshNamesTheLineItWasDecidedAgainst(t *testing.T) { t.Fatalf("refresh expects %+v; want the line r1@3 at d/c", ask.ExpectCurrent) } } + +// A conditional refresh refused because an earlier refresh changed the line +// is asked again against the new line: line D0; a refresh to D1 (expecting +// D0) is dequeued; a newer report queues one to D2 (expecting D0); D1 mints, +// so the D2 refresh is refused. The next snapshot (line D1, reported D2) +// must emit a refresh to D2 expecting D1: an ask that differs only in its +// expected line is not "the same ask". +func TestControllerReasksARefreshRefusedAfterTheLineMoved(t *testing.T) { + g := newBootGraceRig(t) + g.reissued = false + g.steadyPrimary() + g.submit(r1Slot("r1-a", "d1", "c1", true)) + d1 := nextAskOrFail(t, g.ctrl) + if d1.Intent != IntentRefreshEndpoint || d1.DataAddr != "d1" || d1.ExpectCurrent == nil || d1.ExpectCurrent.DataAddr != "d1-old" { + t.Fatalf("first refresh %+v; want d1 expecting the line at d1-old", d1) + } + g.now = g.now.Add(time.Second) + g.submit(r1Slot("r1-a", "d2", "c2", true)) + d2 := nextAskOrFail(t, g.ctrl) + if d2.DataAddr != "d2" || d2.ExpectCurrent == nil || d2.ExpectCurrent.DataAddr != "d1-old" { + t.Fatalf("second refresh %+v; want d2 expecting the line at d1-old", d2) + } + // D1 mints (the publisher would refuse the d2 refresh: d1-old is gone). + g.line.DataAddr, g.line.CtrlAddr, g.line.EndpointVersion = "d1", "c1", g.line.EndpointVersion+1 + g.reader.Set("v1", "r1", g.line) + g.now = g.now.Add(time.Second) + g.submit(r1Slot("r1-a", "d2", "c2", true)) + again := nextAskOrFail(t, g.ctrl) + if again.DataAddr != "d2" || again.ExpectCurrent == nil || again.ExpectCurrent.DataAddr != "d1" { + t.Fatalf("re-ask %+v (expecting %+v); want d2 expecting the line now at d1", again, again.ExpectCurrent) + } +} diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index 6b5d56bf0f..7bdba4c5d0 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -187,8 +187,11 @@ func (h *Host) restartedHolderRefresh(ask authority.AssignmentAsk) (authority.As if h.obs == nil { return authority.AssignmentAsk{}, false } + // One read decides and conditions the refresh: the line must be this + // replica's at exactly the addresses the refresh writes, so its + // expectation can never name a line a move put elsewhere. line, ok := h.Publisher().VolumeAuthorityLine(ask.VolumeID) - if !ok { + if !ok || !line.Assigned || line.ReplicaID != ask.ReplicaID || line.DataAddr != ask.DataAddr || line.CtrlAddr != ask.CtrlAddr { return authority.AssignmentAsk{}, false } slot, ok := h.obs.Store().SlotFactAt(ask.VolumeID, ask.ReplicaID, ask.DataAddr, ask.CtrlAddr) diff --git a/seaweed-block/core/host/master/rf1_restart_reissue_test.go b/seaweed-block/core/host/master/rf1_restart_reissue_test.go index a15e50e04f..87a3591e4f 100644 --- a/seaweed-block/core/host/master/rf1_restart_reissue_test.go +++ b/seaweed-block/core/host/master/rf1_restart_reissue_test.go @@ -1,7 +1,12 @@ package master import ( + "bytes" "context" + "io" + "log" + "strings" + "sync" "testing" "time" @@ -206,12 +211,44 @@ func TestRF1RefreshDecidedBeforeACrossHostMoveIsNotApplied(t *testing.T) { t.Fatalf("a refresh %+v (expecting %+v) was decided for the source after the move", refresh, refresh.ExpectCurrent) } - // Then the stale refresh is submitted. + // Then the stale refresh is submitted. Witness: the publisher's own + // refusal of exactly this ask (its run loop logs every rejected ask), + // within a bound; a refresh never dequeued fails here, not silently. + witness := &syncLogBuffer{} + prevLog := log.Writer() + log.SetOutput(io.MultiWriter(prevLog, witness)) + defer log.SetOutput(prevLog) if err := h.ctrl.SubmitAssignmentAsk(stale); err != nil { t.Fatal(err) } - time.Sleep(500 * time.Millisecond) + refused := func() bool { + out := witness.String() + return strings.Contains(out, "authority: rejected ask") && strings.Contains(out, "Incarnation:proc-b") && strings.Contains(out, src.DataAddr) + } + for deadline := time.Now().Add(5 * time.Second); !refused(); time.Sleep(20 * time.Millisecond) { + if time.Now().After(deadline) { + t.Fatalf("the stale refresh was not refused by the publication path within 5 s; log: %s", witness.String()) + } + } if after, _ := h.Publisher().VolumeAuthorityLine("rt"); after.Epoch != moved.Epoch || after.EndpointVersion != moved.EndpointVersion || after.DataAddr != dst.DataAddr || after.CtrlAddr != dst.CtrlAddr { t.Fatalf("line %+v after the stale refresh; want the moved line %+v (the target's addresses)", after, moved) } } + +// syncLogBuffer is a log sink safe for the publisher's goroutine. +type syncLogBuffer struct { + mu sync.Mutex + buf bytes.Buffer +} + +func (b *syncLogBuffer) Write(p []byte) (int, error) { + b.mu.Lock() + defer b.mu.Unlock() + return b.buf.Write(p) +} + +func (b *syncLogBuffer) String() string { + b.mu.Lock() + defer b.mu.Unlock() + return b.buf.String() +} diff --git a/seaweed-block/docs/design/block-design.md b/seaweed-block/docs/design/block-design.md index 59763af99c..ed0f47d0a5 100644 --- a/seaweed-block/docs/design/block-design.md +++ b/seaweed-block/docs/design/block-design.md @@ -255,6 +255,7 @@ stateDiagram-v2 [*] --> Unbound Unbound --> Bound: IntentBind (epoch 1) Bound --> Bound: same assignment republished + Bound --> Bound: IntentRefreshEndpoint (endpoint version + 1), only on the line it was decided against Bound --> Reassigned: IntentReassign (max epoch + 1) Reassigned --> Bound: new primary serves at the new epoch Bound --> Deleting: deletion reservation (id never reused)