authority, master: filter superseded facts once at ingestion; record every unsupported pass; decide after the probe

Review of #130 r3 (three P2s; the same class as r1/r2, so fixed
structurally rather than per branch):

- Controller: a supported snapshot that carries any superseded slot
  fact (older than the newest recorded for that replica, or equal-time
  with another incarnation) is a stale snapshot. It records nothing and
  no decision branch runs on it (readiness, endpoint refresh, rebalance,
  failover, fallback); any existing desired is kept, as for a stale
  authority basis. Fresh facts, including fresh unhealthy and expiry
  decisions, are unchanged.
- Unsupported-volume gate: the current primary's own fresh slot fact is
  recorded for every unsupported volume, before the promotion-reason
  allow-list and concrete-placement filters, so ready reports and starts
  under any reason are counted. The promotion rules are unchanged.
- Both gates decide after the blocking probe from the current primary's
  fresh slot read at that point (primaryBootGraceHoldsNow), so a newer
  unhealthy report or a heartbeat that expired during the probe is seen;
  the unsupported gate also skips if the authority line moved during the
  probe.

Lock order unchanged: state under TopologyController.mu; the gates read
the publisher line and the store snapshot (their own locks, released)
before calling the controller; no new locks.

Refs #128

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-15 12:10:10 -08:00
1 parent 3acab5b0c8
commit bb377502ea
3 files changed
+88 -30

No files matched your search

+11 -1
View File
@@ -230,7 +230,12 @@ func (c *TopologyController) processSupportedVolumeLocked(
// S4 behavior; stuck evidence has its own lifecycle and is
// NOT cleared here — §10 clearing rule 4.)
delete(c.unsupported, vol.VolumeID)
c.observeIncarnationsLocked(vol, serverIndex)
// A snapshot carrying a superseded slot fact is stale (#128): it
// records nothing and decides nothing, below.
staleFacts := c.supersededFactsLocked(vol)
if !staleFacts {
c.observeIncarnationsLocked(vol, serverIndex)
}
c.confirmDesiredLocked(vol, currentLine, hasLine)
@@ -260,6 +265,11 @@ func (c *TopologyController) processSupportedVolumeLocked(
if !basisMatchesLine(vol.Authority, currentLine, hasLine) {
return
}
// Stale slot facts: likewise keep any existing desired and emit
// nothing from this snapshot.
if staleFacts {
return
}
ask, reason, emit := c.decideVolume(vol, serverIndex, currentLine, hasLine, currentLoad, projectedLoad)
if !emit {
@@ -27,8 +27,13 @@ import "time"
// strictly newer than the last fact recorded for that replica, so a
// delayed or superseded snapshot can never count a restart, reset a
// grace, or end one. A superseded fact (older, or equal-time with a
// different incarnation) is not a decision input either: the decision
// follows the newest recorded fact, and its endpoint is never used. A slot without an incarnation (an older volume
// different incarnation) is not a decision input either. In the
// controller this is enforced once, at ingestion: a supported snapshot
// that carries any superseded slot fact is a stale snapshot, and no
// decision branch runs on it (supersededFactsLocked). The master's
// promotion gates read the observation store, which keeps only the
// newest fact per server; for them a superseded fact defers to the
// newest recorded one and its endpoint is never used. A slot without an incarnation (an older volume
// binary) or without an observation time gets no grace. All state is
// guarded by TopologyController.mu.
@@ -43,6 +48,27 @@ type primaryBootGrace struct {
func bootGraceKey(volumeID, replicaID string) string { return volumeID + "/" + replicaID }
// supersededFactsLocked reports whether any slot fact in vol is older
// than the newest fact recorded for that replica, or has the same
// observation time with another incarnation. Such a snapshot is stale:
// it must neither change history nor drive any decision.
func (c *TopologyController) supersededFactsLocked(vol VolumeTopologySnapshot) bool {
for _, slot := range vol.Slots {
if slot.Incarnation == "" || slot.ObservedAt.IsZero() {
continue
}
g := c.bootGrace[bootGraceKey(vol.VolumeID, slot.ReplicaID)]
if g == nil {
continue
}
if slot.ObservedAt.Before(g.lastObservedAt) ||
(slot.ObservedAt.Equal(g.lastObservedAt) && slot.Incarnation != g.incarnation) {
return true
}
}
return false
}
// observeIncarnationsLocked records each slot's boot fact.
func (c *TopologyController) observeIncarnationsLocked(vol VolumeTopologySnapshot, servers map[string]ServerObservation) {
for _, slot := range vol.Slots {
+49 -27
View File
@@ -183,7 +183,10 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int,
slot.ReadyForPrimary = false
}
}
if enabledCandidate && result.CurrentKnown && !result.Current.Ready && h.primaryBootGraceHolds(vol.VolumeID, withServerFacts(vol.Slots[currentIdx], serverIndex)) {
// After the (blocking) probe, judge the current primary from its
// own fresh heartbeat slot as it is now, not from the snapshot
// taken before the probe.
if enabledCandidate && result.CurrentKnown && !result.Current.Ready && h.primaryBootGraceHoldsNow(vol.VolumeID, vol.Authority.ReplicaID) {
h.log.Printf("blockmaster: promotion gate volume=%s current=%s not ready but in boot grace; no direct reassign", vol.VolumeID, vol.Authority.ReplicaID)
} else if enabledCandidate && result.CurrentKnown && !result.Current.Ready {
current := &vol.Slots[currentIdx]
@@ -215,25 +218,26 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
probeCount, blockedCount := 0, 0
var directAsks []authority.AssignmentAsk
for _, placement := range placements {
if supported[placement.VolumeID] || len(placement.Slots) < 3 || !placementIsConcreteExistingReplica(placement) {
if supported[placement.VolumeID] {
continue
}
evidence, ok := report.Unsupported[placement.VolumeID]
if !ok || !unsupportedReasonsAllowPromotionProbe(evidence.Reasons) {
if !ok {
continue
}
// Record the current primary's own fresh slot fact for every
// unsupported volume, whatever the reason and whether or not a
// promotion is considered, so a ready report ends its boot grace
// and every start counts toward flap history (#128). The
// promotion rules below are unchanged.
h.recordCurrentBootFact(placement.VolumeID)
if len(placement.Slots) < 3 || !placementIsConcreteExistingReplica(placement) || !unsupportedReasonsAllowPromotionProbe(evidence.Reasons) {
continue
}
current, ok := h.Publisher().VolumeAuthorityLine(placement.VolumeID)
if !ok || !current.Assigned {
continue
}
// Record the current primary's own fresh slot fact on every
// pass, not only when a promotion is considered, so a ready
// report ends its boot grace and every start counts toward
// flap history (#128).
cur, curFresh := h.freshCurrentSlot(placement.VolumeID, current.ReplicaID)
if curFresh && h.ctrl != nil {
h.ctrl.RecordPrimaryBootFact(placement.VolumeID, cur)
}
vol, ok := topologyFromUnsupportedPlacement(placement, current)
if !ok {
continue
@@ -270,7 +274,14 @@ func (h *Host) applyUnsupportedPromotionEvidenceGate(placements []lifecycle.Plac
// Unsupported does not mean the current primary is unhealthy:
// a different slot may be stale. Judge the current primary
// from its own fresh heartbeat slot, never from placement.
if curFresh && h.primaryBootGraceHolds(vol.VolumeID, cur) {
// After the (blocking) probe: the authority must still be the
// one probed, and the current primary is judged from its own
// fresh heartbeat slot as it is now.
if now, ok := h.Publisher().VolumeAuthorityLine(vol.VolumeID); !ok || now.ReplicaID != current.ReplicaID || now.Epoch != current.Epoch || now.EndpointVersion != current.EndpointVersion {
h.log.Printf("blockmaster: promotion gate unsupported volume=%s authority moved during the probe; no direct reassign", vol.VolumeID)
continue
}
if h.primaryBootGraceHoldsNow(vol.VolumeID, current.ReplicaID) {
h.log.Printf("blockmaster: promotion gate unsupported volume=%s current=%s not ready but in boot grace; no direct reassign", vol.VolumeID, current.ReplicaID)
continue
}
@@ -580,15 +591,35 @@ func (h *Host) assignmentAskAlreadyCurrent(volumeID, replicaID, dataAddr, ctrlAd
line.CtrlAddr == ctrlAddr
}
// primaryBootGraceHolds reports whether the current primary is a
// restarted primary that is merely not ready yet: placeable by its own
// fresh report and inside its boot grace (#128). An explicit unhealthy
// report (unreachable, ineligible, withdrawn) never holds.
func (h *Host) primaryBootGraceHolds(volumeID string, current authority.ReplicaCandidate) bool {
// primaryBootGraceHoldsNow reports whether the current primary is a
// restarted primary that is merely not ready yet, judged from its own
// fresh heartbeat slot read now: placeable by that report and inside its
// boot grace (#128). No fresh slot, or an explicit unhealthy report
// (unreachable, ineligible, withdrawn), never holds.
func (h *Host) primaryBootGraceHoldsNow(volumeID, replicaID string) bool {
if h.ctrl == nil {
return false
}
return h.ctrl.PrimaryBootGraceHolds(volumeID, current)
cur, ok := h.freshCurrentSlot(volumeID, replicaID)
if !ok {
return false
}
return h.ctrl.PrimaryBootGraceHolds(volumeID, cur)
}
// recordCurrentBootFact records the current primary's own fresh slot
// fact for the volume, if it has an authority line and a fresh slot.
func (h *Host) recordCurrentBootFact(volumeID string) {
if h.ctrl == nil {
return
}
line, ok := h.Publisher().VolumeAuthorityLine(volumeID)
if !ok || !line.Assigned {
return
}
if cur, ok := h.freshCurrentSlot(volumeID, line.ReplicaID); ok {
h.ctrl.RecordPrimaryBootFact(volumeID, cur)
}
}
// freshCurrentSlot returns the replica's own fresh heartbeat slot from
@@ -599,12 +630,3 @@ func (h *Host) freshCurrentSlot(volumeID, replicaID string) (authority.ReplicaCa
}
return h.obs.Store().Snapshot().FreshSlotCandidate(volumeID, replicaID)
}
// withServerFacts folds the reporting server's reachability and
// eligibility into a slot; a server absent from the index is neither.
func withServerFacts(slot authority.ReplicaCandidate, servers map[string]authority.ServerObservation) authority.ReplicaCandidate {
srv, ok := servers[slot.ServerID]
slot.Reachable = slot.Reachable && ok && srv.Reachable
slot.Eligible = slot.Eligible && ok && srv.Eligible
return slot
}