wip: master side of the fencing round, and the heal after a failed one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-25 03:51:58 -08:00
1 parent e636957f4d
commit 939fe74a8b
8 files changed
+237 -32

No files matched your search

+4
View File
@@ -58,6 +58,10 @@ type PrimaryEvidence struct {
DataEpoch uint64 // the target's epoch-table row at DurableLSN
DataFirstLSN uint64
StoreID [16]byte // the probed store's id (its superblock UUID)
// FencedEpoch: the survivors made this epoch their durable floor before
// answering (a fencing round); the line is minted only at this epoch.
// 0: no fencing round (a planned move).
FencedEpoch uint64
}
// ProbeResult is the outcome of a transport probe.
@@ -588,6 +588,13 @@ func (p *Publisher) applyWithWorkspaceMove(ask AssignmentAsk, grant *workspaceGr
if reservedEpoch != 0 {
next.Epoch = reservedEpoch
}
// A decision made on a fencing round holds only for the epoch its
// survivors were fenced at: the line must still be at the epoch
// below it.
if ask.Evidence.FencedEpoch != 0 && next.Epoch != ask.Evidence.FencedEpoch {
p.mu.Unlock()
return fmt.Errorf("%w: volume %s fenced at %d, the next epoch is %d", ErrFenceSuperseded, ask.VolumeID, ask.Evidence.FencedEpoch, next.Epoch)
}
default:
p.mu.Unlock()
@@ -79,6 +79,10 @@ type AssignmentAsk struct {
// promotion-gate evidence, not a forced move); the publisher mints no line.
var ErrReassignWithoutKind = errors.New("authority: a reassign needs a primary kind (promotion evidence or a forced move)")
// ErrFenceSuperseded: a primary change decided on a fencing round at epoch
// e+1 arrived after the volume's line left e; the publisher mints nothing.
var ErrFenceSuperseded = errors.New("authority: the fencing round's epoch is no longer the next epoch of the line")
// Directive is the input side of the authority route. A Directive
// emits one AssignmentAsk at a time. The publisher's Run loop calls
// Next repeatedly until ctx cancellation.
@@ -27,6 +27,16 @@ func (readyGate) ProbePromotionCandidates(_ string, _ authority.AuthorityBasis,
return res, nil
}
// FencePromotionCandidates: every survivor obeys the fence.
func (readyGate) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []master.PromotionCandidateEvidence) (master.PromotionProbeResult, error) {
res := master.PromotionProbeResult{FencedEpoch: current.Epoch + 1}
for _, s := range survivors {
s.Floor = current.Epoch + 1
res.Candidates = append(res.Candidates, s)
}
return res, nil
}
func reopenWait(t *testing.T, what string, fn func() bool) {
t.Helper()
end := time.Now().Add(5 * time.Second)
@@ -0,0 +1,38 @@
package master
import "github.com/seaweedfs/seaweed-block/core/authority"
// fenceObeyed is a fencing round in which every survivor obeys the fence: it
// makes the line's next epoch its durable floor and answers as it did in the
// plain round.
func fenceObeyed(current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
out := make([]PromotionCandidateEvidence, len(survivors))
for i, s := range survivors {
s.Floor = current.Epoch + 1
out[i] = s
}
return PromotionProbeResult{FencedEpoch: current.Epoch + 1, Candidates: out}, nil
}
func (s staticPromotionProbe) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
if s.err != nil {
return PromotionProbeResult{}, s.err
}
return fenceObeyed(current, survivors)
}
func (p *switchProbe) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fenceObeyed(current, survivors)
}
func (p *swapPromotionProbe) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fenceObeyed(current, survivors)
}
func (p reviewHeldPromotion) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fenceObeyed(current, survivors)
}
func (p *workloadPlanPromotionEvidenceProvider) FencePromotionCandidates(_ string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
return fenceObeyed(current, survivors)
}
+45 -3
View File
@@ -73,7 +73,16 @@ func (h *probeHub) close(roundID uint64) {
// ask sends the round for replicaID to its node; false when the node has no
// open round stream (it cannot answer: the replica is not ready).
func (h *probeHub) ask(roundID uint64, r *openRound, serverID, replicaID string) bool {
msg := &control.ProbeRound{VolumeId: r.volumeID, ReplicaId: replicaID, RoundId: roundID}
return h.send(r, serverID, replicaID, &control.ProbeRound{VolumeId: r.volumeID, ReplicaId: replicaID, RoundId: roundID})
}
// askFence asks a replica in a fencing round: it makes fenceEpoch its durable
// floor first (when its store is store), then answers.
func (h *probeHub) askFence(roundID uint64, r *openRound, serverID, replicaID string, fenceEpoch uint64, store storage.StoreID) bool {
return h.send(r, serverID, replicaID, &control.ProbeRound{VolumeId: r.volumeID, ReplicaId: replicaID, RoundId: roundID, FenceEpoch: fenceEpoch, ExpectedStoreId: append([]byte(nil), store[:]...)})
}
func (h *probeHub) send(r *openRound, serverID, replicaID string, msg *control.ProbeRound) bool {
h.mu.Lock()
defer h.mu.Unlock()
r.asked[replicaID] = serverID
@@ -120,6 +129,26 @@ type roundEvidenceProvider struct {
attested func(volumeID, replicaID string) (storage.StoreID, bool)
}
// FencePromotionCandidates is the fencing round of a decision to replace the
// primary at line epoch e: each survivor is asked to make e+1 its durable
// floor on its probed store FIRST and then answer (the answer is its promise
// to refuse the old primary). The answers are read as a probe round's; the
// gate counts only those whose floor is e+1.
func (p *roundEvidenceProvider) FencePromotionCandidates(volumeID string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error) {
fence := current.Epoch + 1
candidates := make([]authority.ReplicaCandidate, 0, len(survivors))
stores := map[string]storage.StoreID{}
for _, s := range survivors {
candidates = append(candidates, authority.ReplicaCandidate{ReplicaID: s.ReplicaID})
stores[s.ReplicaID] = s.StoreID
}
result, err := p.round(volumeID, authority.AuthorityBasis{}, candidates, func(roundID uint64, r *openRound, serverID, replicaID string) bool {
return p.hub.askFence(roundID, r, serverID, replicaID, fence, stores[replicaID])
})
result.FencedEpoch = fence
return result, err
}
func newRoundID() uint64 {
var b [8]byte
for {
@@ -133,6 +162,10 @@ func newRoundID() uint64 {
}
func (p *roundEvidenceProvider) ProbePromotionCandidates(volumeID string, current authority.AuthorityBasis, candidates []authority.ReplicaCandidate) (PromotionProbeResult, error) {
return p.round(volumeID, current, candidates, p.hub.ask)
}
func (p *roundEvidenceProvider) round(volumeID string, current authority.AuthorityBasis, candidates []authority.ReplicaCandidate, ask func(roundID uint64, r *openRound, serverID, replicaID string) bool) (PromotionProbeResult, error) {
required, requiredKnown := p.required[volumeID]
result := PromotionProbeResult{
AckProfile: p.ackProfile,
@@ -149,7 +182,7 @@ func (p *roundEvidenceProvider) ProbePromotionCandidates(volumeID string, curren
if serverID == "" {
serverID = p.serverOf(volumeID, replicaID)
}
if serverID != "" && p.hub.ask(roundID, r, serverID, replicaID) {
if serverID != "" && ask(roundID, r, serverID, replicaID) {
want[replicaID] = true
}
}
@@ -175,7 +208,15 @@ done:
if current.ReplicaID != "" {
if a := got[current.ReplicaID]; a != nil {
result.CurrentKnown = true
result.Current = PromotionCandidateEvidence{ReplicaID: current.ReplicaID, Ready: a.GetPrimaryReady(), DurableLSN: a.GetDurableEnd()}
var store storage.StoreID
if len(a.GetStoreId()) == len(store) {
copy(store[:], a.GetStoreId())
}
// 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(),
StoreID: store, Floor: a.GetFloor()}
} else {
result.Current = PromotionCandidateEvidence{ReplicaID: current.ReplicaID, ProbeAddr: "no answer"}
}
@@ -203,6 +244,7 @@ done:
LastDataFirstLSN: a.GetLastDataFirstLsn(),
TableInvalid: invalid,
StoreID: store,
Floor: a.GetFloor(),
// A promotion target answers as a ready replica, from a store
// whose epoch table is present and valid, and whose id is the
// store its primary attested (counted toward its write ACKs).
+101 -4
View File
@@ -2,10 +2,11 @@ package master
import (
"fmt"
"github.com/seaweedfs/seaweed-block/core/storage"
"reflect"
"strings"
"github.com/seaweedfs/seaweed-block/core/storage"
"github.com/seaweedfs/seaweed-block/core/adapter"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/lifecycle"
@@ -41,11 +42,17 @@ type PromotionCandidateEvidence struct {
// last attested for it (Host.AttestedStore): a replaced store, or one
// never attested, is not a survivor.
StoreID storage.StoreID
// Floor is the candidate's durable epoch floor when it answered; in a
// fencing round it is counted only at the round's FencedEpoch.
Floor uint64
}
type PromotionProbeResult struct {
AckProfile string
SyncAckLSN uint64
// FencedEpoch: this is a fencing round's result at that epoch (0: a plain
// probe).
FencedEpoch uint64
AckProfile string
SyncAckLSN uint64
// SyncAckKnown reports that SyncAckLSN is a known required
// acknowledgement frontier, which may be zero. A nonzero SyncAckLSN
// is always a known frontier; a zero SyncAckLSN without SyncAckKnown
@@ -58,6 +65,11 @@ type PromotionProbeResult struct {
type PromotionEvidenceProvider interface {
ProbePromotionCandidates(volumeID string, current authority.AuthorityBasis, candidates []authority.ReplicaCandidate) (PromotionProbeResult, error)
// FencePromotionCandidates runs the fencing round of a decision to
// replace the primary of line current: survivors (ready in the plain
// round, with their probed store) make current.Epoch+1 their durable
// floor, then answer. The result's FencedEpoch is current.Epoch+1.
FencePromotionCandidates(volumeID string, current authority.AuthorityBasis, survivors []PromotionCandidateEvidence) (PromotionProbeResult, error)
}
func (h *Host) SetPromotionEvidenceProvider(p PromotionEvidenceProvider) {
@@ -245,6 +257,23 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int,
probeCount++
result, ok := h.probePromotionCandidatesCurrent(vol.VolumeID, vol.Authority, candidates)
allowed := promotionAllowedReplicas(result, ok, len(candidates), h.freshPromotionPeers(vol.VolumeID, candidates))
// Replacing the primary (it is not acceptable, or answered not
// ready): the decision is read from a fencing round, never from the
// plain answers, so no write the old primary gets acknowledged after
// a survivor answered can be missing from the target.
if len(allowed) > 0 && (!currentAcceptable || (result.CurrentKnown && !result.Current.Ready)) {
result, allowed = h.fencedDecision(vol.VolumeID, vol.Authority, result, len(candidates))
if len(allowed) == 0 {
// The fencing round ended without a publication: survivors may
// now refuse the primary at e. Continue that primary at e+1 if
// it answers ready, else the volume waits (visibly).
if heal, ok := h.healAfterFailedFence(vol.VolumeID, vol.Authority); ok {
directAsks = append(directAsks, heal)
} else {
h.recordVolumeBlockedEvent(vol.VolumeID, ops.ReasonFenceRoundIncomplete)
}
}
}
if ok {
h.log.Printf("blockmaster: promotion gate volume=%s current=%s current_known=%t current_ready=%t ack_profile=%s required_lsn=%d candidates=%v allowed=%v",
vol.VolumeID, vol.Authority.ReplicaID, result.CurrentKnown, result.Current.Ready, result.AckProfile, result.SyncAckLSN, result.Candidates, allowed)
@@ -299,6 +328,74 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int,
return probeCount, blockedCount, directAsks
}
// fencedDecision runs the fencing round for the survivors the plain round
// found ready and decides on its answers alone: at least
// unknownFrontierSurvivorsNeeded of them must have made the line's next
// epoch their durable floor (an answer with a higher floor was fenced by a
// newer decision and does not count), and the target is the highest durable
// end among those. Too few: nothing is allowed this tick.
func (h *Host) fencedDecision(volumeID string, current authority.AuthorityBasis, plain PromotionProbeResult, peerCount int) (PromotionProbeResult, map[string]bool) {
h.promotionMu.RLock()
prober := h.promotionProber
h.promotionMu.RUnlock()
var survivors []PromotionCandidateEvidence
for _, c := range plain.Candidates {
if c.Ready {
survivors = append(survivors, c)
}
}
fenced, err := prober.FencePromotionCandidates(volumeID, current, survivors)
if err != nil || fenced.FencedEpoch != current.Epoch+1 {
h.log.Printf("blockmaster: promotion gate volume=%s fencing round at %d failed: %v", volumeID, current.Epoch+1, err)
return plain, map[string]bool{}
}
fenced.AckProfile, fenced.SyncAckLSN, fenced.SyncAckKnown = plain.AckProfile, plain.SyncAckLSN, plain.SyncAckKnown
fenced.CurrentKnown, fenced.Current = plain.CurrentKnown, plain.Current
counted := map[string]bool{}
for i := range fenced.Candidates {
c := &fenced.Candidates[i]
if c.Ready && c.Floor == fenced.FencedEpoch {
counted[c.ReplicaID] = true
} else {
c.Ready = false
}
}
if need := unknownFrontierSurvivorsNeeded(plain.AckProfile, peerCount); len(counted) < need {
h.log.Printf("blockmaster: promotion gate volume=%s fencing round at %d: %d fenced survivors, need %d; nothing published", volumeID, fenced.FencedEpoch, len(counted), need)
return fenced, map[string]bool{}
}
return fenced, promotionAllowedReplicas(fenced, true, peerCount, counted)
}
// healAfterFailedFence continues the line's own primary at e+1 after a
// fencing round that published nothing, on that primary's answer to a round
// opened for the heal (a plain one: it needs no fence against itself). The
// current primary holds every write it acknowledged, so continuing it at e+1
// loses nothing; the replicas, at floor e+1 already or later, rejoin by
// reconciliation against its table. Its line is a PROMOTION whose evidence
// is that primary's own answer; the target check is the usual one.
func (h *Host) healAfterFailedFence(volumeID string, current authority.AuthorityBasis) (authority.AssignmentAsk, bool) {
h.promotionMu.RLock()
prober := h.promotionProber
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() {
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
}
h.log.Printf("blockmaster: promotion gate volume=%s heal: continuing %s at epoch %d", volumeID, current.ReplicaID, current.Epoch+1)
return authority.AssignmentAsk{
VolumeID: volumeID,
ReplicaID: current.ReplicaID,
DataAddr: current.DataAddr,
CtrlAddr: current.CtrlAddr,
Intent: authority.IntentReassign,
Evidence: adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: c.DurableLSN, DataEpoch: c.LastDataEpoch, DataFirstLSN: c.LastDataFirstLSN,
StoreID: c.StoreID, FencedEpoch: current.Epoch + 1},
}, true
}
func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.PlacementIntent, report authority.SupportabilityReport, supported map[string]bool) (int, int, []authority.AssignmentAsk) {
if len(report.Unsupported) == 0 {
return 0, 0, nil
@@ -696,7 +793,7 @@ func promotionAllowedReplicas(result PromotionProbeResult, ok bool, peerCount in
func promotionEvidenceFor(result PromotionProbeResult, replicaID string) adapter.PrimaryEvidence {
for _, c := range result.Candidates {
if c.ReplicaID == replicaID {
return adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: c.DurableLSN, DataEpoch: c.LastDataEpoch, DataFirstLSN: c.LastDataFirstLSN, StoreID: c.StoreID}
return adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion, DurableLSN: c.DurableLSN, DataEpoch: c.LastDataEpoch, DataFirstLSN: c.LastDataFirstLSN, StoreID: c.StoreID, FencedEpoch: result.FencedEpoch}
}
}
return adapter.PrimaryEvidence{Kind: adapter.PrimaryKindPromotion}
+28 -25
View File
@@ -21,31 +21,34 @@ const (
ReasonPrimaryNodeLost = "primary_node_lost"
ReasonCandidateCoversRequiredFrontier = "candidate_covers_required_frontier"
ReasonNoPromotionReadyCandidate = "no_promotion_ready_candidate"
ReasonDurableFrontierMissing = "durable_frontier_missing"
ReasonCandidateFrontierBehind = "candidate_frontier_behind"
ReasonStatusEndpointUnreachable = "status_endpoint_unreachable"
ReasonCSINodeImagePullFailed = "csi_node_image_pull_failed"
ReasonCSIDriverNotRegistered = "csi_driver_not_registered"
ReasonCSINodePodNotReady = "csi_node_pod_not_ready"
ReasonImageMissingOnNode = "image_missing_on_node"
ReasonISCSIPrereqMissing = "iscsi_prereq_missing"
ReasonMultipathPrereqMissing = "multipath_prereq_missing"
ReasonNodeReady = "node_ready"
ReasonNodeNotReady = "node_not_ready"
ReasonNodeSchedulingDisabled = "node_scheduling_disabled"
ReasonGeneratedDeploymentMissing = "generated_deployment_missing"
ReasonObservedReplicasBelowDesired = "observed_replicas_below_desired"
ReasonLoopbackFrontendRejected = "loopback_frontend_rejected"
ReasonStalePrimaryFenced = "stale_primary_fenced"
ReasonWALIntegrityFault = "wal_integrity_fault"
ReasonReturnedReplicaFrontendFenced = "returned_replica_frontend_fenced"
ReasonReturnedReplicaUnsafeFrontend = "returned_replica_unsafe_frontend_ready"
ReasonInstallDriftAligned = "install_drift_aligned"
ReasonInstallDriftMismatch = "install_drift_mismatch"
ReasonInstallDriftEvidenceMissing = "install_drift_evidence_missing"
ReasonNVMeIdentityIncomplete = "nvme_identity_incomplete"
ReasonNVMePathIdentityMismatch = "nvme_path_identity_mismatch"
ReasonNVMeMultipathPathMissing = "nvme_multipath_path_missing"
// A fencing round ended without a publication and the line's primary
// did not answer ready to continue: the volume waits for either.
ReasonFenceRoundIncomplete = "fence_round_incomplete"
ReasonDurableFrontierMissing = "durable_frontier_missing"
ReasonCandidateFrontierBehind = "candidate_frontier_behind"
ReasonStatusEndpointUnreachable = "status_endpoint_unreachable"
ReasonCSINodeImagePullFailed = "csi_node_image_pull_failed"
ReasonCSIDriverNotRegistered = "csi_driver_not_registered"
ReasonCSINodePodNotReady = "csi_node_pod_not_ready"
ReasonImageMissingOnNode = "image_missing_on_node"
ReasonISCSIPrereqMissing = "iscsi_prereq_missing"
ReasonMultipathPrereqMissing = "multipath_prereq_missing"
ReasonNodeReady = "node_ready"
ReasonNodeNotReady = "node_not_ready"
ReasonNodeSchedulingDisabled = "node_scheduling_disabled"
ReasonGeneratedDeploymentMissing = "generated_deployment_missing"
ReasonObservedReplicasBelowDesired = "observed_replicas_below_desired"
ReasonLoopbackFrontendRejected = "loopback_frontend_rejected"
ReasonStalePrimaryFenced = "stale_primary_fenced"
ReasonWALIntegrityFault = "wal_integrity_fault"
ReasonReturnedReplicaFrontendFenced = "returned_replica_frontend_fenced"
ReasonReturnedReplicaUnsafeFrontend = "returned_replica_unsafe_frontend_ready"
ReasonInstallDriftAligned = "install_drift_aligned"
ReasonInstallDriftMismatch = "install_drift_mismatch"
ReasonInstallDriftEvidenceMissing = "install_drift_evidence_missing"
ReasonNVMeIdentityIncomplete = "nvme_identity_incomplete"
ReasonNVMePathIdentityMismatch = "nvme_path_identity_mismatch"
ReasonNVMeMultipathPathMissing = "nvme_multipath_path_missing"
EventTypeCSIReattachObserved = "csi_reattach_observed"
)