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 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-25 06:10:20 -08:00
1 parent e79996437f
commit a034d3f7a3
4 files changed
+27 -18

No files matched your search

@@ -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
@@ -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()
@@ -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
@@ -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
}