Merge pull request #625 from seaweedfs/feat/manual-failover-fenced

fix(master): manual failover of a lost primary decides on the fencing round (RF2 and RF3)
This commit is contained in:
Ping Qiu authored and GitHub committed 2026-11-25 18:03:43 -08:00
commit aba6a9f040
6 files changed
+655 -4

No files matched your search

@@ -0,0 +1,563 @@
package master
import (
"context"
"errors"
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"
"github.com/seaweedfs/seaweed-block/core/adapter"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/storage"
)
// ackedFenceProbe is a fenceProbe that reports its ack profile, as the
// round provider does (plannedMoveEvidence reads it).
type ackedFenceProbe struct{ *fenceProbe }
func (p ackedFenceProbe) AckProfile() string { return p.plain.AckProfile }
// rf3LineOnR1 is a master whose RF3 volume's line is on r1, bound by a
// product tick.
func rf3LineOnR1(t *testing.T) (*Host, authority.AuthorityBasis) {
t.Helper()
return rf3LineOnR1With(t, newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 3}))
}
func rf3LineOnR1With(t *testing.T, h *Host) (*Host, authority.AuthorityBasis) {
t.Helper()
h.SetPromotionEvidenceProvider(staticPromotionProbe{result: PromotionProbeResult{
AckProfile: "sync_quorum",
Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 1}, {ReplicaID: "r3", Ready: true, DurableLSN: 1}},
}})
seedRF3PlacementForServersWithAddrs(t, h, "vol-rf3", "node-a", "node-b", "node-c")
ingestRF3Observation(t, h, true, true, true)
if _, err := h.RunLifecycleProductTick(); err != nil {
t.Fatalf("initial product tick: %v", err)
}
line := waitAuthorityLine(t, h.Publisher(), "vol-rf3")
if line.ReplicaID != "r1" {
t.Fatalf("initial line=%+v want r1", line)
}
return h, line
}
func failoverTo(h *Host, current authority.AuthorityBasis, target string) error {
return failoverVolumeTo(h, "vol-rf3", current, target)
}
func failoverVolumeTo(h *Host, volumeID string, current authority.AuthorityBasis, target string) error {
addr := map[string][2]string{"r2": {"127.0.0.1:19201", "127.0.0.1:19202"}, "r3": {"127.0.0.1:19301", "127.0.0.1:19302"}}[target]
_, err := h.FailbackAuthorityRuntime().ExecuteFailback(context.Background(), authority.FailbackRuntimeRequest{
VolumeID: volumeID, ReplicaID: target, TargetDataAddr: addr[0], TargetCtrlAddr: addr[1],
ExpectedCurrentReplicaID: current.ReplicaID, ExpectedCurrentEpoch: current.Epoch,
AckEligible: true, FrontendFencedBeforeFailback: true, DurableFrontierCovered: true, NoCrossVolumeIdentityChange: true,
})
return err
}
// The operator's failover of an RF3 sync_quorum volume whose primary is
// unreachable (its host powered off: no fresh heartbeat) runs the fencing
// round, which is the seal a planned move there lacks, and the
// decision is the round's (Fence model Open/Answer/Decide). Survivors answer
// at floor e+1, both of them (N-K+1 = 2), so the old primary can no longer
// collect an acknowledgement; the target must hold the highest fenced end and
// be ready; the published line carries basis Fenced at e+1. Anything less
// publishes nothing and leaves the fence pending, so a returning primary is
// healed at e+1 (the product loop's heal).
func TestManualFailoverRF3SyncQuorumDecidesOnTheFencingRound(t *testing.T) {
plain := PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{
{ReplicaID: "r2", Ready: true, DurableLSN: 10},
{ReplicaID: "r3", Ready: true, DurableLSN: 9},
}}
at := func(r string, lsn uint64, floorAbove uint64, ready bool) PromotionCandidateEvidence {
return PromotionCandidateEvidence{ReplicaID: r, Ready: ready, DurableLSN: lsn, Floor: floorAbove, TableValid: true}
}
for _, c := range []struct {
name string
target string
fenced func(e uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error)
want uint64 // the promoted line's evidence LSN; 0 = refused
}{
{"both fenced; the target holds the highest fenced end", "r3",
func(e uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fencedAs(at("r2", 10, e+1, true), at("r3", 12, e+1, true))
}, 12},
{"the target is below the other survivor's fenced end", "r2",
func(e uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fencedAs(at("r2", 10, e+1, true), at("r3", 12, e+1, true))
}, 0},
{"one survivor silent: too few fenced answers", "r2",
func(e uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fencedAs(at("r2", 10, e+1, true))
}, 0},
{"one answered at a higher floor (superseded): not counted", "r2",
func(e uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fencedAs(at("r2", 10, e+1, true), at("r3", 9, e+2, true))
}, 0},
{"the target holds the highest end but is not ready", "r3",
func(e uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fencedAs(at("r2", 10, e+1, true), at("r3", 12, e+1, false))
}, 0},
{"the fencing round failed", "r2",
func(uint64) func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return PromotionProbeResult{}, errors.New("no stream")
}
}, 0},
} {
t.Run(c.name, func(t *testing.T) {
h, line := rf3LineOnR1(t)
defer closeTestMaster(t, h)
ingestRF3Observation(t, h, false, true, true) // r1's host is gone
p := &fenceProbe{plain: plain, fenced: c.fenced(line.Epoch)}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
err := failoverTo(h, line, c.target)
if len(p.survivors) != 2 {
t.Fatalf("fenced %v; want both survivors r2, r3 fenced before any decision", p.survivors)
}
after, _ := h.Publisher().VolumeAuthorityLine("vol-rf3")
if c.want == 0 {
if err == nil || after != line {
t.Fatalf("err=%v line=%+v; want refused, line %+v unchanged", err, after, line)
}
if !h.pendingFence("vol-rf3", line.Epoch) {
t.Fatal("a refused fenced failover left no pending fence: a returning primary would not be healed at e+1")
}
return
}
if err != nil {
t.Fatalf("failover to %s: %v", c.target, err)
}
if after.ReplicaID != c.target || after.Epoch != line.Epoch+1 {
t.Fatalf("line=%+v; want %s at %d", after, c.target, line.Epoch+1)
}
})
}
}
// The evidence the fenced failover hands the publisher: kind PROMOTION,
// basis Fenced, the round's epoch (e+1), the target's fenced end.
func TestManualFailoverRF3EvidenceIsTheFencingRounds(t *testing.T) {
h, line := rf3LineOnR1(t)
defer closeTestMaster(t, h)
ingestRF3Observation(t, h, false, true, true)
p := &fenceProbe{
plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{
{ReplicaID: "r2", Ready: true, DurableLSN: 10}, {ReplicaID: "r3", Ready: true, DurableLSN: 12}}},
fenced: fencedAs(
PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: line.Epoch + 1, TableValid: true},
PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: line.Epoch + 1, TableValid: true}),
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
ev, err := h.plannedMoveEvidence("vol-rf3", "r3")
if err != nil {
t.Fatal(err)
}
if ev.Kind != adapter.PrimaryKindPromotion || ev.Basis != adapter.BasisFenced || ev.FencedEpoch != line.Epoch+1 || ev.DurableLSN != 12 {
t.Fatalf("evidence %+v; want PROMOTION, basis fenced at %d, end 12", ev, line.Epoch+1)
}
}
// rf2LineOnR1 is a master whose RF2 volume's line is on r1, bound by a
// product tick under the given ack profile.
func rf2LineOnR1(t *testing.T, profile string) (*Host, authority.AuthorityBasis) {
t.Helper()
h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 2})
h.SetPromotionEvidenceProvider(staticPromotionProbe{result: PromotionProbeResult{
AckProfile: profile,
Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 1}},
}})
seedRF2Placement(t, h)
ingestRF2Observation(t, h, true, true)
if _, err := h.RunLifecycleProductTick(); err != nil {
t.Fatalf("initial product tick: %v", err)
}
line := waitAuthorityLine(t, h.Publisher(), "vol-rf2")
if line.ReplicaID != "r1" {
t.Fatalf("initial line=%+v want r1", line)
}
return h, line
}
// The operator's failover of an RF2 volume whose primary is unreachable (its
// host powered off: no fresh heartbeat) is decided on the fencing round too,
// one path with RF3 (Fence model Open/Answer/Decide; the count is a
// parameter: RF2 needs the one survivor's answer). The survivor must answer
// at floor e+1, on a valid table, ready; the line carries basis Fenced at
// e+1. Anything less publishes nothing and leaves the fence pending.
func TestManualFailoverRF2UnreachablePrimaryDecidesOnTheFencingRound(t *testing.T) {
for _, profile := range []string{"sync_quorum", "sync_all"} {
for _, c := range []struct {
name string
survivor func(e uint64) PromotionCandidateEvidence
fail bool
promoted bool
}{
{"the survivor fenced at e+1, ready", func(e uint64) PromotionCandidateEvidence {
return PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 5, Floor: e + 1, TableValid: true}
}, false, true},
{"the survivor answered at a higher floor (superseded)", func(e uint64) PromotionCandidateEvidence {
return PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 5, Floor: e + 2, TableValid: true}
}, false, false},
{"the survivor is not ready", func(e uint64) PromotionCandidateEvidence {
return PromotionCandidateEvidence{ReplicaID: "r2", DurableLSN: 5, Floor: e + 1, TableValid: true}
}, false, false},
{"the survivor's table is invalid", func(e uint64) PromotionCandidateEvidence {
return PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 5, Floor: e + 1, TableInvalid: true}
}, false, false},
{"the fencing round failed", nil, true, false},
} {
t.Run(profile+"/"+c.name, func(t *testing.T) {
h, line := rf2LineOnR1(t, profile)
defer closeTestMaster(t, h)
ingestRF2Observation(t, h, false, true) // r1's host is gone
p := &fenceProbe{plain: PromotionProbeResult{AckProfile: profile, SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 5}}}}
if c.fail {
p.fenced = func(authority.AuthorityBasis, []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return PromotionProbeResult{}, errors.New("no stream")
}
} else {
p.fenced = fencedAs(c.survivor(line.Epoch))
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
if c.promoted {
ev, err := h.plannedMoveEvidence("vol-rf2", "r2")
if err != nil || ev.Basis != adapter.BasisFenced || ev.FencedEpoch != line.Epoch+1 || ev.DurableLSN != 5 {
t.Fatalf("evidence %+v err=%v; want basis fenced at %d, end 5", ev, err, line.Epoch+1)
}
}
err := failoverVolumeTo(h, "vol-rf2", line, "r2")
if len(p.survivors) == 0 || p.survivors[len(p.survivors)-1] != "r2" {
t.Fatalf("fenced %v; want the survivor r2 fenced before any decision", p.survivors)
}
after, _ := h.Publisher().VolumeAuthorityLine("vol-rf2")
if !c.promoted {
if err == nil || after != line {
t.Fatalf("err=%v line=%+v; want refused, line %+v unchanged", err, after, line)
}
if !h.pendingFence("vol-rf2", line.Epoch) {
t.Fatal("a refused fenced failover left no pending fence")
}
return
}
if err != nil || after.ReplicaID != "r2" || after.Epoch != line.Epoch+1 {
t.Fatalf("err=%v line=%+v; want r2 at %d", err, after, line.Epoch+1)
}
})
}
}
}
// best_effort acknowledges a write without any replica, so no round can
// prove the survivor holds every acknowledged write: the operator's failover
// of an unreachable best_effort primary is refused (never basis Fenced),
// and no fencing round runs.
func TestManualFailoverRF2BestEffortIsNeverFenced(t *testing.T) {
h, line := rf2LineOnR1(t, "best_effort")
defer closeTestMaster(t, h)
ingestRF2Observation(t, h, false, true)
p := &fenceProbe{
plain: PromotionProbeResult{AckProfile: "best_effort", Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 5}}},
fenced: fencedAs(PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 5, Floor: line.Epoch + 1, TableValid: true}),
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
if _, err := h.plannedMoveEvidence("vol-rf2", "r2"); !errors.Is(err, ErrPlannedMoveBestEffort) || len(p.survivors) != 0 {
t.Fatalf("err=%v fenced=%v; want ErrPlannedMoveBestEffort and no fencing round", err, p.survivors)
}
}
// An RF2 sync_quorum failover from a reachable primary stays a planned move
// (its target is in every acknowledgement set): no fencing round, basis
// Planned.
func TestManualFailoverRF2ReachablePrimaryStaysPlanned(t *testing.T) {
h, _ := rf2LineOnR1(t, "sync_quorum")
defer closeTestMaster(t, h)
p := &fenceProbe{
plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 5}}},
fenced: fencedAs(),
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
ev, err := h.plannedMoveEvidence("vol-rf2", "r2")
if err != nil {
t.Fatal(err)
}
if ev.Basis != adapter.BasisPlanned || ev.FencedEpoch != 0 || len(p.survivors) != 0 {
t.Fatalf("evidence %+v fenced=%v; want a planned move with no fencing round", ev, p.survivors)
}
}
// A reachable RF3 sync_quorum primary's move is a planned move, and a planned
// move there needs a seal v1 does not have: refused, with no fencing round.
// Only the failover of an unreachable primary is fenced.
func TestManualFailoverRF3ReachablePrimaryIsRefused(t *testing.T) {
h, line := rf3LineOnR1(t)
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: 12}}},
fenced: fencedAs(),
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
err := failoverTo(h, line, "r3")
if !errors.Is(err, ErrPlannedMoveNeedsSeal) || len(p.survivors) != 0 {
t.Fatalf("err=%v fenced=%v; want ErrPlannedMoveNeedsSeal and no fencing round", err, p.survivors)
}
if after, _ := h.Publisher().VolumeAuthorityLine("vol-rf3"); after != line {
t.Fatalf("line=%+v; want %+v unchanged", after, line)
}
}
// meetingFenceProbe holds each fencing round until two have arrived, so two
// callers decide the same volume at the same time. A caller that waits past
// the bound gets an error (no decision) and marks the probe late: the test
// then fails, it never proceeds with one caller alone.
type meetingFenceProbe struct {
*fenceProbe
mu sync.Mutex
arrived int
late bool
bound time.Duration
both chan struct{}
}
func (p *meetingFenceProbe) FencePromotionCandidates(v string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
p.mu.Lock()
p.arrived++
if p.arrived == 2 {
close(p.both)
}
p.mu.Unlock()
select {
case <-p.both:
case <-time.After(p.bound):
p.mu.Lock()
p.late = true
p.mu.Unlock()
return PromotionProbeResult{}, errors.New("meetingFenceProbe: the other caller did not arrive")
}
p.mu.Lock()
defer p.mu.Unlock()
return p.fenceProbe.FencePromotionCandidates(v, current, survivors)
}
func (p *meetingFenceProbe) AckProfile() string { return p.plain.AckProfile }
// The operator's failover and the master's own promotion loop decide the
// same volume at once: both fence at the same next epoch and both allow the
// target, but exactly one line is published (the line's conditional update
// refuses the second), so the epoch moves once.
func TestManualFailoverAndThePromotionLoopPublishOneLine(t *testing.T) {
h, line := rf3LineOnR1(t)
defer closeTestMaster(t, h)
ingestRF3Observation(t, h, false, true, true)
e := line.Epoch
p := &meetingFenceProbe{both: make(chan struct{}), bound: 5 * time.Second, fenceProbe: &fenceProbe{
// The primary answered not ready: the loop's own promotion applies.
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: 12}}},
fenced: fencedAs(
PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: e + 1, TableValid: true},
PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: e + 1, TableValid: true}),
}}
h.SetPromotionEvidenceProvider(p)
var wg sync.WaitGroup
var opErr, loopErr error
wg.Add(2)
go func() { defer wg.Done(); opErr = failoverTo(h, line, "r3") }()
go func() { defer wg.Done(); _, loopErr = h.RunLifecycleProductTick() }()
wg.Wait()
if loopErr != nil {
t.Fatalf("product tick: %v", loopErr)
}
p.mu.Lock()
met, late := p.arrived, p.late
p.mu.Unlock()
if met != 2 || late {
t.Fatalf("%d fencing rounds, late=%t; want both callers held together before either decided", met, late)
}
after := waitAuthorityReplica(t, h.Publisher(), "vol-rf3", "r3")
deadline := time.Now().Add(500 * time.Millisecond)
for time.Now().Before(deadline) {
if cur, _ := h.Publisher().VolumeAuthorityLine("vol-rf3"); cur.Epoch != e+1 || cur.ReplicaID != "r3" {
t.Fatalf("line=%+v; want exactly one publication: r3 at %d (operator err=%v)", cur, e+1, opErr)
}
time.Sleep(20 * time.Millisecond)
}
if after.Epoch != e+1 {
t.Fatalf("line=%+v; want r3 at %d", after, e+1)
}
}
// The barrier's negative control: with one caller only, the round is refused
// at the bound and the probe is marked late, so a test that relies on two
// callers held together cannot pass with one.
func TestMeetingFenceProbeFailsWhenTheOtherCallerIsLate(t *testing.T) {
p := &meetingFenceProbe{both: make(chan struct{}), bound: 50 * time.Millisecond, fenceProbe: &fenceProbe{fenced: fencedAs()}}
if _, err := p.FencePromotionCandidates("v", authority.AuthorityBasis{Epoch: 1}, nil); err == nil || !p.late {
t.Fatalf("err=%v late=%t; want a refusal and late", err, p.late)
}
}
// storeFault makes every authority record write of one volume fail (a
// directory where the store writes the record's temp file; open fails
// before any rename, as a full or failing disk would) until cleared.
func storeFault(t *testing.T, h *Host, volumeID string) (arm, clear func()) {
t.Helper()
var record string
matches, _ := filepath.Glob(filepath.Join(h.cfg.AuthorityStoreDir, volumeID+".*"))
for _, m := range matches {
if !strings.HasSuffix(m, ".tmp") {
record = m
}
}
if record == "" {
t.Fatalf("no authority record for %s in %s (%v)", volumeID, h.cfg.AuthorityStoreDir, matches)
}
tmp := record + ".tmp"
arm = func() {
if err := os.Mkdir(tmp, 0o700); err != nil {
t.Fatal(err)
}
}
clear = func() { _ = os.Remove(tmp) }
t.Cleanup(clear)
return arm, clear
}
// waitLine polls until the volume's line is replica at epoch, else fails.
func waitLine(t *testing.T, h *Host, volumeID, replica string, epoch uint64) {
t.Helper()
deadline := time.Now().Add(3 * time.Second)
for {
cur, _ := h.Publisher().VolumeAuthorityLine(volumeID)
if cur.ReplicaID == replica && cur.Epoch == epoch {
return
}
if time.Now().After(deadline) {
t.Fatalf("line=%+v; want %s at %d", cur, replica, epoch)
}
time.Sleep(20 * time.Millisecond)
}
}
// healedR1 is the line's own primary answering a heal round ready.
var healedR1 = PromotionProbeResult{CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true, DurableLSN: 11,
LastDataEpoch: 1, LastDataFirstLSN: 1, StoreID: storage.StoreID{7}, TableValid: true}}
// back puts r1 back ready and the fenced survivors not ready for primary
// (they refuse r1 at e); with r3Missing its server reports no slot for the
// volume (a partial inventory: the volume is unsupported).
func back(t *testing.T, h *Host, r3Missing bool) {
t.Helper()
now := time.Now().UTC()
slot := func(r, d, c string, ready bool) []authority.SlotFact {
return []authority.SlotFact{{VolumeID: "vol-rf3", ReplicaID: r, DataAddr: d, CtrlAddr: c, Reachable: true, ReadyForPrimary: ready, Eligible: true, EvidenceScore: 10}}
}
r3 := slot("r3", "127.0.0.1:19301", "127.0.0.1:19302", false)
if r3Missing {
r3 = nil
}
for _, obs := range []authority.Observation{
{ServerID: "node-a", ObservedAt: now, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: slot("r1", "127.0.0.1:19101", "127.0.0.1:19102", true)},
{ServerID: "node-b", ObservedAt: now, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: slot("r2", "127.0.0.1:19201", "127.0.0.1:19202", false)},
{ServerID: "node-c", ObservedAt: now, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: r3},
} {
if err := h.ObservationHost().Ingest(obs); err != nil {
t.Fatal(err)
}
}
}
// End to end: the operator's failover is allowed by its fencing round, and
// the publication fails (the authority store refuses the write). The line is
// still r1 at e, but its survivors are fenced at e+1. When r1 is back, a
// normal product tick publishes r1 at e+1 (the heal, through the same
// dispatch as every tick), and a further tick adds no epoch.
func TestManualFailoverPublicationFailureIsHealedByTheNextTick(t *testing.T) {
h, line := rf3LineOnR1(t)
defer closeTestMaster(t, h)
ingestRF3Observation(t, h, false, true, true)
e := line.Epoch
p := &fenceProbe{
plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 10}, {ReplicaID: "r3", Ready: true, DurableLSN: 12}}},
fenced: fencedAs(
PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: e + 1, TableValid: true},
PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: e + 1, TableValid: true}),
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
arm, clear := storeFault(t, h, "vol-rf3")
arm()
if err := failoverTo(h, line, "r3"); err == nil {
t.Fatal("the failover published through a failing authority store")
}
clear()
if cur, _ := h.Publisher().VolumeAuthorityLine("vol-rf3"); cur != line || len(p.survivors) != 2 {
t.Fatalf("after the fault line=%+v fenced=%v; want %+v unchanged and both survivors fenced", cur, p.survivors, line)
}
back(t, h, false)
p.heal = healedR1
if _, err := h.RunLifecycleProductTick(); err != nil {
t.Fatalf("product tick: %v", err)
}
waitLine(t, h, "vol-rf3", "r1", e+1)
if _, err := h.RunLifecycleProductTick(); err != nil {
t.Fatalf("product tick: %v", err)
}
time.Sleep(200 * time.Millisecond)
waitLine(t, h, "vol-rf3", "r1", e+1)
}
// The unsupported path: the operator's failover is refused (the target is
// below the highest fenced end), so its survivors are fenced at e+1 and
// nothing is published. r1 is back while the volume is unsupported (a
// partial inventory: the report is built as the other unsupported-gate tests
// build it). The gate's heal ask goes through the tick's own dispatch
// (SubmitAssignmentAsk) and r1 is published at e+1; a further gate pass
// asks nothing (the pending fence is cleared by that line).
func TestManualFailoverRefusedFenceIsHealedAndPublishedOnTheUnsupportedPath(t *testing.T) {
h, line := rf3LineOnR1(t)
defer closeTestMaster(t, h)
ingestRF3Observation(t, h, false, true, true)
e := line.Epoch
p := &fenceProbe{
plain: PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", Ready: true, DurableLSN: 10}, {ReplicaID: "r3", Ready: true, DurableLSN: 12}}},
fenced: fencedAs(
PromotionCandidateEvidence{ReplicaID: "r2", Ready: true, DurableLSN: 10, Floor: e + 1, TableValid: true},
PromotionCandidateEvidence{ReplicaID: "r3", Ready: true, DurableLSN: 12, Floor: e + 1, TableValid: true}),
}
h.SetPromotionEvidenceProvider(ackedFenceProbe{p})
if err := failoverTo(h, line, "r2"); err == nil {
t.Fatal("a failover to the survivor below the highest fenced end was allowed")
}
back(t, h, true)
p.plain = PromotionProbeResult{AckProfile: "sync_quorum", SyncAckKnown: true, CurrentKnown: true, Current: PromotionCandidateEvidence{ReplicaID: "r1", Ready: true},
Candidates: []PromotionCandidateEvidence{{ReplicaID: "r2", DurableLSN: 10}}}
p.heal = healedR1
report := authority.SupportabilityReport{Unsupported: map[string]authority.VolumeUnsupportedEvidence{
"vol-rf3": {VolumeID: "vol-rf3", Reasons: []string{authority.ReasonPartialInventory}},
}}
_, _, asks := h.applyUnsupportedPromotionEvidenceGate(h.Lifecycle().Placements.ListPlacements(), report, nil)
if len(asks) != 1 {
t.Fatalf("asks %+v; want the heal of r1", asks)
}
for _, a := range asks {
if err := h.ctrl.SubmitAssignmentAsk(a); err != nil {
t.Fatalf("dispatch %+v: %v", a, err)
}
}
waitLine(t, h, "vol-rf3", "r1", e+1)
if _, _, again := h.applyUnsupportedPromotionEvidenceGate(h.Lifecycle().Placements.ListPlacements(), report, nil); len(again) != 0 {
t.Fatalf("a second pass asks %+v; want none (the line reached the fenced epoch)", again)
}
waitLine(t, h, "vol-rf3", "r1", e+1)
}
+68 -1
View File
@@ -3,10 +3,12 @@ package master
import (
"errors"
"fmt"
"sort"
"strings"
"github.com/seaweedfs/seaweed-block/core/adapter"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/lifecycle"
)
// ErrPlannedMoveNeedsSeal: under this ack profile and replica count a write
@@ -71,7 +73,16 @@ func (h *Host) plannedMoveEvidence(volumeID, target string) (adapter.PrimaryEvid
targetServer = s.ServerID
}
}
if err := plannedMoveAllowed(profile, len(placement.Slots)); err != nil {
// The primary is unreachable (a lost host stops heartbeating): the move
// is the operator's failover, not a planned move from a live primary, and
// it is decided on the fencing round at every replica count, where the
// planned guard refuses only for want of a seal. A reachable primary's
// move stays a planned move under its guard.
if err := plannedMoveAllowed(profile, len(placement.Slots)); err != nil && !errors.Is(err, ErrPlannedMoveNeedsSeal) {
return adapter.PrimaryEvidence{}, err
} else if h.primaryUnreachable(volumeID) {
return h.fencedMoveEvidence(volumeID, target, profile, placement.Slots)
} else if err != nil {
return adapter.PrimaryEvidence{}, err
}
result, err := prober.ProbePromotionCandidates(volumeID, authority.AuthorityBasis{}, []authority.ReplicaCandidate{{ReplicaID: target, ServerID: targetServer}})
@@ -87,3 +98,59 @@ func (h *Host) plannedMoveEvidence(volumeID, target string) (adapter.PrimaryEvid
}
return adapter.PrimaryEvidence{}, fmt.Errorf("planned move: replica %s did not answer the probe round ready (caught up, epoch table valid)", target)
}
// primaryUnreachable: the line's primary has no fresh, reachable heartbeat
// slot. A volume without a line has no primary to lose.
func (h *Host) primaryUnreachable(volumeID string) bool {
current, ok := h.Publisher().VolumeAuthorityLine(volumeID)
if !ok {
return false
}
slot, fresh := h.freshCurrentSlot(volumeID, current.ReplicaID)
return !fresh || !slot.Reachable
}
// fencedMoveEvidence is the operator's failover of an unreachable primary,
// at any replica count. The fencing round seals the old primary: every other replica is fenced at the line's
// next epoch, so the old primary, dead or alive, can no longer collect an
// acknowledgement, and the decision is read from the round alone
// (fencedDecision: enough counted answers, the target holds the highest
// fenced end and is ready). A round that does not allow the target publishes
// nothing and leaves the fence pending, so a primary that answers again is
// continued at e+1 (healAfterFailedFence) by the product loop.
func (h *Host) fencedMoveEvidence(volumeID, target, profile string, slots []lifecycle.PlacementSlotIntent) (adapter.PrimaryEvidence, error) {
current, ok := h.Publisher().VolumeAuthorityLine(volumeID)
if !ok {
return adapter.PrimaryEvidence{}, fmt.Errorf("fenced move: volume %s has no authority line", volumeID)
}
h.promotionMu.RLock()
prober := h.promotionProber
h.promotionMu.RUnlock()
var candidates []authority.ReplicaCandidate
for _, s := range slots {
if s.ReplicaID != current.ReplicaID {
candidates = append(candidates, authority.ReplicaCandidate{ReplicaID: s.ReplicaID, ServerID: s.ServerID})
}
}
plain, err := prober.ProbePromotionCandidates(volumeID, current, candidates)
if err != nil {
return adapter.PrimaryEvidence{}, fmt.Errorf("fenced move: probe round: %w", err)
}
if plain.AckProfile == "" {
plain.AckProfile = profile
}
// Pending from the attempt on: the round may fence survivors above the
// line whatever it decides, and an allowed decision may still fail to
// publish. It is forgotten once a line reaches that epoch.
h.noteFencePending(volumeID, current.Epoch+1)
fenced, allowed := h.fencedDecision(volumeID, current, plain, len(candidates))
if allowed[target] {
return promotionEvidenceFor(fenced, target), nil
}
others := make([]string, 0, len(allowed))
for r := range allowed {
others = append(others, r)
}
sort.Strings(others)
return adapter.PrimaryEvidence{}, fmt.Errorf("fenced move: the fencing round at epoch %d does not allow %s (allowed: %v): it must hold the highest fenced end and be ready, with enough fenced survivors", current.Epoch+1, target, others)
}
@@ -529,6 +529,17 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
// and every start counts toward flap history (#128). The
// promotion rules below are unchanged.
h.recordCurrentBootFact(placement.VolumeID)
// A fencing round fenced survivors above this line and nothing was
// published (e.g. the operator's refused failover): continue the
// line's own primary at e+1 when it is back and answers ready,
// before any candidate check, as the supported gate does.
if line, ok := h.Publisher().VolumeAuthorityLine(placement.VolumeID); ok && line.Assigned &&
h.pendingFence(placement.VolumeID, line.Epoch) && h.freshPrimaryAcceptable(placement.VolumeID, line.ReplicaID) {
if heal, healed := h.healAfterFailedFence(placement.VolumeID, line); healed {
directAsks = append(directAsks, heal)
continue
}
}
if len(placement.Slots) < 2 || !placementIsConcreteExistingReplica(placement) || !unsupportedReasonsAllowPromotionProbe(evidence.Reasons) {
continue
}
@@ -1058,6 +1069,13 @@ func (h *Host) recordCurrentBootFact(volumeID string) {
// freshCurrentSlot returns the replica's own fresh heartbeat slot from
// the observation store (server facts folded in).
// freshPrimaryAcceptable: the replica has a fresh heartbeat slot that is
// reachable, eligible and not withdrawn.
func (h *Host) freshPrimaryAcceptable(volumeID, replicaID string) bool {
s, ok := h.freshCurrentSlot(volumeID, replicaID)
return ok && s.Reachable && s.Eligible && !s.Withdrawn
}
func (h *Host) freshCurrentSlot(volumeID, replicaID string) (authority.ReplicaCandidate, bool) {
if h.obs == nil {
return authority.ReplicaCandidate{}, false
+1 -1
View File
@@ -210,7 +210,7 @@ This alpha MVP does not yet claim:
- production-ready durability
- multi-node Kubernetes operation
- failover while a pod remains mounted
- automatic failover when the primary node or pod is lost: blockmaster does not reassign on a primary it cannot read; failover is a manual admin action (a `SwBlockReplicaFailback` with the expected current line, applied for the failback executor, which calls blockmaster's admin `ExecuteFailback`)
- automatic failover when the primary node or pod is lost: blockmaster does not reassign on a primary it cannot read; failover is a manual admin action (a `SwBlockReplicaFailback` with the expected current line, applied for the failback executor, which calls blockmaster's admin `ExecuteFailback`); when the primary is unreachable that failover runs the fencing round first and moves only to a ready replica holding the highest fenced end (a `best_effort` volume, and a reachable RF3 `sync_quorum` primary, are refused; the round stops the old primary's writes, not its reads, so confirm the old node is off or cut from its clients first)
- real operator reconciliation
- backend data shredding on delete
- snapshots, clone, resize, block mode, topology spread, or NVMe-oF
+2 -1
View File
@@ -230,6 +230,7 @@ RF2 qualification limitation until ordered-live certification is wired (#297). S
| any | role admission failed | the listener cannot be fenced or its floor cannot be persisted; the role is not adopted and the projection is not healthy | `core/host/volume/host.go` `latchRoleAdmission` | `INV-FENCE-FLOOR-DURABLE-001` |
| (every inbound frame) | — | a mutating frame is refused on a primary, below the floor, or before a role is known; the rebuild port applies the same rules; a failed apply closes the connection | `core/transport/replica.go` `acceptMutationLineage`, `admitMutation`, `EnterDualLane`, `handleConn` | `INV-FENCE-SELF-ON-PROMOTE-001`, `INV-FENCE-FLOOR-DURABLE-001`, `INV-REPL-REBUILD-PORT-FENCE-001`, `INV-REPL-APPLY-FAIL-001` |
| Supporting | promotion candidate | no active recovery session; member, reachable, caught up, fenced at the current epoch, post-rebuild durable acknowledgement delivered; for RF=2 and up also a fresh probe and coverage of the required frontier: known, or proven by at least N_peers-K+1 fresh ready peers when it is unknown | `core/engine/promotion_ready.go` `BuildPromotionReadyFact`; `core/host/master/product_loop.go` `applyPromotionEvidenceGate` | `INV-REPL-PROMOTION-READY-001`, `INV-PROMOTE-FRONTIER-001`, `INV-PROMOTE-FRONTIER-PROBE-001`, `INV-PROMOTE-FRONTIER-UNKNOWN-001` |
| Primary (unreachable) | another replica Primary at e+1 | the operator's failover (`ExecuteFailback`) of a line whose primary has no fresh, reachable heartbeat slot: the fence is pending from the attempt; the fencing round fences every other replica at e+1; only `fencedDecision`'s allowed target is published, basis Fenced at e+1, through the line's conditional update (a concurrent promotion-loop decision at the same epoch is refused); a refused or unpublished round is healed by either gate (the line's own primary continued at e+1); `best_effort` is refused, and a reachable RF3 `sync_quorum` primary's move stays refused (needs a seal) | `core/host/master/planned_move.go` `plannedMoveEvidence`, `primaryUnreachable`, `fencedMoveEvidence`; `core/host/master/product_loop.go` `applyPromotionEvidenceGate`, `applyUnsupportedPromotionEvidenceGate` | `INV-PROMOTE-UNKNOWN-CURRENT-001` |
**Recovery observation and apply ordering.** A probe publishes its fresh boundaries before reachability, and each emitted recovery is prepared under the adapter mutex before the next event. Same-identity delayed probes retain completed durable R; missing probe boundaries remain unknown until a valid observation arrives. Every lane and session shares one replica-wide per-LBA applied-LSN map under the apply mutex; session close releases coverage only. Recovery skips stale data while advancing its own coverage; stale live data fails without advancing recovery coverage.
@@ -954,7 +955,7 @@ Notes:
| `INV-PROMOTE-FRONTIER-001` | With a known required acknowledgement frontier under `sync_quorum` or `sync_all`, the RF=3 promotion gate allows only probed-ready candidates whose durable LSN is at least the required LSN. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas`, `applyPromotionEvidenceGate`; `core/host/master/probe_round.go` (`SyncAckKnown`); `core/engine/promotion_ready.go` `BuildPromotionReadyFact` | `TestMountedFailover_ProductLoopRF3PromotesCandidateCoveringSyncAckProbe` (`core/host/master/product_loop_test.go`); `TestPromotionAllowedReplicas_RequiredFrontierCoverage`, `TestWorkloadPlanProvider_RequiredFrontierKnownness` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-PROMOTE-CREATION-WAIT-001` | A primary that answers the promotion probe not ready is excused from replacement only by its own answer that its assignment at the current line's epoch awaits replica stores (read before its readiness), and only while its own fresh slot is acceptable; the master keeps no state for it. | GUARD (the promotion models have no bring-up) | `core/host/master/product_loop.go` `probePromotionCandidatesCurrent`; `core/host/master/probe_round.go`; `core/host/volume/probe_round.go` `probeAnswer`; `core/host/volume/workspace_startup.go` `awaitingStoresEpoch` | `TestPrimaryAwaitingReplicaStoresIsNotReplacedForNotReady`, `TestMasterRestartInTheGapDoesNotReassign`, `TestPrimaryNotReadyForAnotherReasonIsReplaced`, `TestAwaitingAnswerForAnotherLineExcusesNothing` (`core/host/master/creating_primary_gate_test.go`); `TestProbeRound_CarriesThePrimarysAwaitingStoresEpoch` (`core/host/master/probe_round_test.go`); `TestProbeAnswerReadsTheWaitBeforeReadiness`, `TestProbeAnswerAfterTheWaitNamesNothing` (`core/host/volume/replica_stores_wait_test.go`) | — | ACTIVE |
| `INV-PROMOTE-FRONTIER-PROBE-001` | For a replicated volume (two or more slots), the gate allows no candidate unless this tick's promotion probe succeeded with a known ack profile. | M3 Supporting → promotion candidate (the gate, RF=2 and up) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate`, `promotionAllowedReplicas` | `TestMountedFailover_ProductLoopRF3BlocksFailoverWithoutFreshPromotionProbe` (`core/host/master/product_loop_test.go`); `TestMountedFailover_ProductLoopRF2DecidesOnThePromotionGate` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-PROMOTE-UNKNOWN-CURRENT-001` | A current primary whose status cannot be read (probe refused, timed out, pod gone) is unknown, never failed: no promotion path reassigns on it; a direct reassign needs the primary's own not-ready report. | M3 Primary → promotion candidate (both promotion paths) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate` (supported path), `applyUnsupportedPromotionEvidenceGate` (unsupported path) | `TestUnsupportedPathNeverReassignsOnAnUnansweredPrimary` (`core/host/master/primary_boot_grace_gate_test.go`); `TestMountedFailover_ProductLoopRF3DoesNotReassignWhenCurrentSlotMissing` (`core/host/master/product_loop_test.go`). Limits: Kubernetes alpha failover on node or pod loss is a manual admin action in this release | — | ACTIVE |
| `INV-PROMOTE-UNKNOWN-CURRENT-001` | A current primary whose status cannot be read (probe refused, timed out, pod gone) is unknown, never failed: no promotion path reassigns on it; a direct reassign needs the primary's own not-ready report. | M3 Primary → promotion candidate (both promotion paths) | `core/host/master/product_loop.go` `applyPromotionEvidenceGate` (supported path), `applyUnsupportedPromotionEvidenceGate` (unsupported path) | `TestUnsupportedPathNeverReassignsOnAnUnansweredPrimary` (`core/host/master/primary_boot_grace_gate_test.go`); `TestMountedFailover_ProductLoopRF3DoesNotReassignWhenCurrentSlotMissing` (`core/host/master/product_loop_test.go`). Limits: Kubernetes alpha failover on node or pod loss is a manual admin action in this release; the admin's failover runs the fencing round and publishes only on its decision (basis Fenced) when the primary is unreachable (no fresh, reachable heartbeat; any replica count); a reachable RF3 `sync_quorum` primary's move stays refused (it needs a seal) and `best_effort` stays refused (`core/host/master/planned_move.go` `fencedMoveEvidence`; `TestManualFailoverRF3SyncQuorumDecidesOnTheFencingRound`, `TestManualFailoverRF2UnreachablePrimaryDecidesOnTheFencingRound`, `TestManualFailoverRF2BestEffortIsNeverFenced`, `TestManualFailoverRF3ReachablePrimaryIsRefused`, `TestManualFailoverAndThePromotionLoopPublishOneLine`) | — | ACTIVE |
| `INV-PROMOTE-FRONTIER-UNKNOWN-001` | With an unknown frontier under `sync_quorum` or `sync_all`, the gate allows the highest-durable ready candidate only if at least N_peers-K+1 of the N_peers peers are probed ready this tick and have a fresh heartbeat (K as in `waitForSyncAcks`); else none. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas`, `unknownFrontierSurvivorsNeeded`, `freshPromotionPeers`; `core/replication/async_ack.go` `waitForSyncAcks` | `TestMountedFailover_ProductLoopRF3UnknownRequiredLSNFallsBackToHighestDurableLSN` (`core/host/master/product_loop_test.go`); `TestProductLoop_MissingRequiredFrontierRefusesRF3Promotion` (`core/host/master/promotion_missing_frontier_regression_test.go`); `TestUnknownFrontierSurvivorsNeeded`, `TestFreshPromotionPeers_UsesObservationFreshness`, `TestProductLoop_UnknownFrontierSurvivorReadyLastTickMissingNowRefused` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-PROMOTE-FRONTIER-BEST-EFFORT-001` | Under `best_effort`, the gate allows no candidate when a nonzero required frontier is given, and otherwise allows the highest-durable ready candidate. | M3 Supporting → promotion candidate (RF=3 gate) | `core/host/master/product_loop.go` `promotionAllowedReplicas` | `TestMountedFailover_ProductLoopRF3BestEffortUnknownRequiredLSNCanSelectHighestDurableLSN`, `TestMountedFailover_ProductLoopRF3RejectsBestEffortProbeForHA` (`core/host/master/product_loop_test.go`); `TestPromotionAllowedReplicas_RequiredFrontierCoverage` (`core/host/master/promotion_frontier_coverage_test.go`) | — | ACTIVE |
| `INV-CSI-CONSUMES-AUTHORITY-001` | CSI never imports authority code or builds assignment facts; it takes the publish target from blockmaster and refreshes it before a stage, and blockmaster mints the IDs of the events CSI reports. | M2 (read side) | `core/csi/master_backend.go` `LookupPublishTarget`; `core/csi/node.go` `refreshPublishContext`; `core/host/master/observation_service.go` `ReportClusterEvent` | `TestG15a_CSI_DoesNotImportAuthorityOrConstructAssignmentFacts` (`core/csi/boundary_guard_test.go`); `TestG15e_CSIReattachUsesFreshPublishTargetAfterUnstage` (`core/csi/node_test.go`); `TestObservationService_ReportClusterEventAppearsInVolumeTimeline` (`core/host/master/observation_service_test.go`) | — | ACTIVE |
@@ -210,7 +210,7 @@ The volume computes whether it may become primary; blockmaster decides; only the
**RF=3 gate** (`core/host/master/promotion_probe.go`, `promotionAllowedReplicas`, `chooseAllowedPromotionTarget`): no promotion when the probe failed or is not installed, or the ack profile is unknown; a candidate is skipped when it is not `replica_ready` with a known frontier, or its durable LSN is below the required frontier. The decision is recorded as an ops event (`candidate_covers_required_frontier`, `candidate_frontier_behind`, `no_promotion_ready_candidate`). The required frontier per volume (`RequiredLSNByVolume`) is not set by `cmd/blockmaster` today, so the frontier is unknown and coverage is proven from the survivors instead: with `sync_quorum` or `sync_all`, the ready candidate with the highest durable LSN is promoted only when at least P-K+1 of the P peers are probed ready (known durable LSN) and have a fresh heartbeat, where K is the number of peer acks a write needs (`waitForSyncAcks`: P for `sync_all`, (P+1)/2 for `sync_quorum`). Any P-K+1 peers include one that holds every acknowledged write that their sampled frontiers represent. The probes of one tick are snapshots, not a fence: a primary that is still running can acknowledge after a sample was taken (for example, r3 reports 70 in a held probe response, the old primary then acknowledges 71, and r2 at 70 is still selected). That is the missing primary lease below (§12, #195). For RF=3 that is both peers under `sync_quorum` and one under `sync_all`; with fewer, nothing is promoted. An unknown frontier is never read as zero. `best_effort` is unchanged (§12).
**A current primary that does not answer is unknown, not failed.** When its status cannot be read (a pod gone, a partition), blockmaster does not reassign on either path, however ready the survivors: on a partition the primary may still be serving. Only the primary's own not-ready report moves the line automatically; otherwise failover is a manual admin action in this release.
**A current primary that does not answer is unknown, not failed.** When its status cannot be read (a pod gone, a partition), blockmaster does not reassign on either path, however ready the survivors: on a partition the primary may still be serving. Only the primary's own not-ready report moves the line automatically; otherwise failover is a manual admin action in this release. The admin's failover of an unreachable primary (no fresh, reachable heartbeat) is decided on the fencing round, at any replica count: every other replica is fenced at N+1, the target must hold the highest fenced end and be ready, and the line carries basis Fenced; a round that publishes nothing leaves the fence pending, and the line's own primary is continued at N+1 when it answers ready again. The round stops the old primary's writes, not its reads: confirm the old node is off or cut from its clients first.
**What blocks a promotion:** any engine reason above; a current primary whose status cannot be read; `unhealthy_reason` set or withdrawn; an unreachable or ineligible server; boot grace still holding; a current primary whose probe is ready; a snapshot rejected for slot count; slots that changed while the probe ran.
@@ -222,6 +222,8 @@ stateDiagram-v2
Suspect --> Blocked: no promotion-ready candidate
Blocked --> Suspect: next product tick
Suspect --> Reassigned: candidate chosen, IntentReassign
Suspect --> Reassigned: admin failover of an unreachable primary, fencing round allows the target (basis Fenced)
Suspect --> Serving: fencing round refused or unpublished, own primary answers ready (heal at N+1)
Reassigned --> Serving: publisher persists epoch N+1, new primary fences and serves
```