mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
d0265eae9c
commit
b935d0a73b
5 files changed
+89
-4
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user