From a034d3f7a398440a440b294d94cf2e7ff0ac5502 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 25 Nov 2026 06:10:20 -0800 Subject: [PATCH] master: a fenced answer counts only on evidence that was read An answer whose epoch table is absent, or whose evidence could not be read, reported no table and so was never marked invalid: it counted toward N-K+1 with end 0 and could let a lower end become the target. A fenced answer (and the heal's own answer) now counts only when its evidence was read on a present, valid table, from the attested store. Co-Authored-By: Claude Opus 5.5 --- .../core/host/master/fence_fakes_test.go | 1 + .../core/host/master/fence_gate_test.go | 31 ++++++++++--------- seaweed-block/core/host/master/probe_round.go | 5 +-- .../core/host/master/product_loop.go | 8 +++-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/seaweed-block/core/host/master/fence_fakes_test.go b/seaweed-block/core/host/master/fence_fakes_test.go index 0a8e4239bd..9f9df0fc14 100644 --- a/seaweed-block/core/host/master/fence_fakes_test.go +++ b/seaweed-block/core/host/master/fence_fakes_test.go @@ -9,6 +9,7 @@ func fenceObeyed(current authority.AuthorityBasis, survivors []PromotionCandidat out := make([]PromotionCandidateEvidence, len(survivors)) for i, s := range survivors { s.Floor = current.Epoch + 1 + s.TableValid = true // a replica that obeys reads its evidence out[i] = s } return PromotionProbeResult{FencedEpoch: current.Epoch + 1, Candidates: out}, nil diff --git a/seaweed-block/core/host/master/fence_gate_test.go b/seaweed-block/core/host/master/fence_gate_test.go index 05b9ef379b..045cb9550b 100644 --- a/seaweed-block/core/host/master/fence_gate_test.go +++ b/seaweed-block/core/host/master/fence_gate_test.go @@ -83,25 +83,28 @@ func TestPromotionGate_DecidesOnTheFencingRound(t *testing.T) { want map[string]uint64 // allowed replica -> its evidence LSN }{ {"both fenced: the highest fenced end, not the plain one", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: 2}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: 2, TableValid: true}), map[string]uint64{"r3": 12}}, {"one fenced, one silent: too few", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}), map[string]uint64{}}, {"one answered at a higher floor (superseded): not counted", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: 3}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: 3, TableValid: true}), map[string]uint64{}}, {"one answered without the fence (another store: its floor did not move)", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: 1}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: 1, TableValid: true}), map[string]uint64{}}, {"r3 lagging (not ready) with a lower fenced end: counted, r2 is the target", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", DurableLSN: 8, Floor: 2}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", DurableLSN: 8, Floor: 2, TableValid: true}), map[string]uint64{"r2": 10}}, {"r3 lagging (not ready) holds the highest fenced end: wait", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", DurableLSN: 12, Floor: 2}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", DurableLSN: 12, Floor: 2, TableValid: true}), map[string]uint64{}}, {"r3 on an invalid table: not counted", - fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", DurableLSN: 8, Floor: 2, TableInvalid: true}), + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", DurableLSN: 8, Floor: 2, TableInvalid: true}), + map[string]uint64{}}, + {"r3 fenced but its evidence unreadable (table absent): not counted", + fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", Floor: 2}), map[string]uint64{}}, {"the fencing round failed", func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) { @@ -144,8 +147,8 @@ func TestPromotionGate_EmptyVolumePrimaryLost(t *testing.T) { fenced func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) want int }{ - "both fenced at end 0": {fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, Floor: 2}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, Floor: 2}), 2}, - "one fenced": {fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, Floor: 2}), 0}, + "both fenced at end 0": {fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, Floor: 2, TableValid: true}, PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, Floor: 2, TableValid: true}), 2}, + "one fenced": {fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, Floor: 2, TableValid: true}), 0}, } { t.Run(name, func(t *testing.T) { h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 3}) @@ -179,9 +182,9 @@ func TestPromotionGate_HealsAFailedFencingRoundOnTheCurrentPrimary(t *testing.T) p := &fenceProbe{ plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1"}, Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 10}, {ReplicaID: "r3", Ready: true, DurableLSN: 10}}}, - fenced: fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}), // r3 silent + fenced: fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}), // r3 silent heal: PromotionProbeResult{CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: ready, DurableLSN: 11, - LastDataEpoch: 1, LastDataFirstLSN: 1, StoreID: store}}, + LastDataEpoch: 1, LastDataFirstLSN: 1, StoreID: store, TableValid: true}}, } h.SetPromotionEvidenceProvider(p) snap := rf3DeadPrimary() @@ -214,13 +217,13 @@ func TestPromotionGate_HealsAFailedFencingRoundOnTheCurrentPrimary(t *testing.T) // survivor answering above the line triggers the same heal. func TestPromotionGate_HealsOnALaterTick(t *testing.T) { store := storage.StoreID{7} - healed := PromotionProbeResult{CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true, DurableLSN: 11, StoreID: store}} + healed := PromotionProbeResult{CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true, DurableLSN: 11, StoreID: store, TableValid: true}} t.Run("remembered failed round", func(t *testing.T) { h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 3}) defer closeTestMaster(t, h) p := &fenceProbe{ plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 10}, {ReplicaID: "r3", Ready: true, DurableLSN: 10}}}, - fenced: fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}), + fenced: fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}), } h.SetPromotionEvidenceProvider(p) snap := rf3DeadPrimary() @@ -242,7 +245,7 @@ func TestPromotionGate_HealsOnALaterTick(t *testing.T) { defer closeTestMaster(t, h) h.SetPromotionEvidenceProvider(&fenceProbe{ plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true}, - Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2}, {ReplicaID: "r3", Ready: true, DurableLSN: 10, Floor: 1}}}, + Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: 2, TableValid: true}, {ReplicaID: "r3", Ready: true, DurableLSN: 10, Floor: 1, TableValid: true}}}, heal: healed, }) snap := rf3DeadPrimary() diff --git a/seaweed-block/core/host/master/probe_round.go b/seaweed-block/core/host/master/probe_round.go index b1ba616ae0..c98bcee79c 100644 --- a/seaweed-block/core/host/master/probe_round.go +++ b/seaweed-block/core/host/master/probe_round.go @@ -154,7 +154,7 @@ func (p *roundEvidenceProvider) FencePromotionCandidates(volumeID string, curren // table, is no evidence: it carries no floor for the gate to count. for i := range result.Candidates { c := &result.Candidates[i] - if ref, ok := stores[c.ReplicaID]; !ok || ref.IsZero() || c.StoreID != ref || c.TableInvalid { + if ref, ok := stores[c.ReplicaID]; !ok || ref.IsZero() || c.StoreID != ref || !c.TableValid { c.Floor = 0 } } @@ -228,7 +228,7 @@ done: // The current primary's own evidence (a heal continues it on it): // ready as a serving primary, on a valid table. result.Current = PromotionCandidateEvidence{ReplicaID: current.ReplicaID, Ready: a.GetPrimaryReady(), DurableLSN: a.GetDurableEnd(), - LastDataEpoch: a.GetLastDataEpoch(), LastDataFirstLSN: a.GetLastDataFirstLsn(), TableInvalid: a.GetTablePresent() && !a.GetTableValid(), + LastDataEpoch: a.GetLastDataEpoch(), LastDataFirstLSN: a.GetLastDataFirstLsn(), TableInvalid: a.GetTablePresent() && !a.GetTableValid(), TableValid: a.GetTablePresent() && a.GetTableValid(), StoreID: store, Floor: a.GetFloor()} } else { result.Current = PromotionCandidateEvidence{ReplicaID: current.ReplicaID, ProbeAddr: "no answer"} @@ -256,6 +256,7 @@ done: LastDataEpoch: a.GetLastDataEpoch(), LastDataFirstLSN: a.GetLastDataFirstLsn(), TableInvalid: invalid, + TableValid: a.GetTablePresent() && a.GetTableValid(), StoreID: store, Floor: a.GetFloor(), // A promotion target answers as a ready replica, from a store diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index 0d82094d26..27608411ec 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -37,6 +37,10 @@ type PromotionCandidateEvidence struct { // TableInvalid: a recovery left the candidate's table without a known // history; such a candidate is never Ready (never a promotion survivor). TableInvalid bool + // TableValid: the candidate's evidence was read, on a present and valid + // epoch table. Only such an answer is evidence: one whose table is + // absent or could not be read says nothing about its end. + TableValid bool // StoreID is the candidate's probed store (its superblock UUID). A // candidate is Ready only when it equals the store the volume's primary // last attested for it (Host.AttestedStore): a replaced store, or one @@ -382,7 +386,7 @@ func (h *Host) fencedDecision(volumeID string, current authority.AuthorityBasis, var highest uint64 for i := range fenced.Candidates { c := &fenced.Candidates[i] - if c.ReplicaID != "" && c.Floor == fenced.FencedEpoch && !c.TableInvalid { + if c.ReplicaID != "" && c.Floor == fenced.FencedEpoch && c.TableValid { counted[c.ReplicaID] = true if c.DurableLSN > highest { highest = c.DurableLSN @@ -484,7 +488,7 @@ func (h *Host) healAfterFailedFence(volumeID string, current authority.Authority h.promotionMu.RUnlock() res, err := prober.ProbePromotionCandidates(volumeID, current, nil) c := res.Current - if err != nil || !res.CurrentKnown || c.ReplicaID != current.ReplicaID || !c.Ready || c.TableInvalid || c.StoreID.IsZero() { + if err != nil || !res.CurrentKnown || c.ReplicaID != current.ReplicaID || !c.Ready || !c.TableValid || c.StoreID.IsZero() { h.log.Printf("blockmaster: promotion gate volume=%s heal: primary %s did not answer ready (%v); waiting", volumeID, current.ReplicaID, err) return authority.AssignmentAsk{}, false }