fix: preserve missing probe confidence with retained durable progress

This commit is contained in:
pingqiu committed 2026-11-20 05:17:12 -08:00
1 parent 364118a28e
commit 68da02fb5f
11 files changed
+61 -12

No files matched your search

+11
View File
@@ -298,6 +298,7 @@ func applyRecoveryFacts(st *ReplicaState, e RecoveryFactsObserved, r *ApplyResul
// Within one identity, delayed probes cannot undo completed durable work.
// An identity-changing assignment resets the recovery facts.
st.Recovery.R = max(st.Recovery.R, e.R)
st.Recovery.FactsMissing = !e.ProgressFact().PrimaryBoundsKnown
st.Recovery.S = e.S
st.Recovery.H = e.H
@@ -311,6 +312,10 @@ func applyDurableAck(st *ReplicaState, e DurableAckObserved, r *ApplyResult, tra
return
}
fact := e.ProgressFact()
if st.Recovery.FactsMissing {
st.Recovery.S, st.Recovery.H = fact.PrimaryS, fact.PrimaryH
st.Recovery.FactsMissing = false
}
updateDurableAckLagState(st, fact)
if fact.ReplicaR > st.Recovery.DurableAckR || !st.Recovery.DurableAckKnown {
st.Recovery.DurableAckR = fact.ReplicaR
@@ -443,6 +448,12 @@ func decide(st *ReplicaState, r *ApplyResult, trace func(string, string)) {
trace("decision", "unknown (not reachable)")
return
}
if st.Recovery.FactsMissing {
st.Recovery.Decision = DecisionUnknown
st.Recovery.DecisionReason = "no_boundaries"
trace("decision", "unknown (missing probe facts)")
return
}
fact := RecoveryFactsObserved{
ReplicaID: st.Identity.ReplicaID,
@@ -14,6 +14,21 @@ func TestRecoveryProbeKeepsCompletedRButAllowsNewWorkAndIdentity(t *testing.T) {
if st.Recovery.R != 100 {
t.Fatalf("old probe lowered completed R: %d", st.Recovery.R)
}
// An unknown probe must not turn the retained R into invented primary
// boundaries or publish healthy. A later valid observation recovers it.
r = Apply(st, RecoveryFactsObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1})
if r.Projection.RecoveryDecision != DecisionUnknown {
t.Fatalf("retained R fabricated known boundaries: %+v", r.Projection)
}
r = Apply(st, ProbeSucceeded{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1})
if r.Projection.RecoveryDecision != DecisionUnknown {
t.Fatal("reachability fabricated missing recovery facts")
}
assertNoCommand(t, r, "PublishHealthy")
r = Apply(st, DurableAckObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, DurableLSN: 100, PrimaryTailLSN: 10, PrimaryHeadLSN: 100})
if r.Projection.RecoveryDecision != DecisionNone || st.Recovery.FactsMissing {
t.Fatalf("valid ack did not restore known facts: %+v", r.Projection)
}
// A higher primary head remains real new work, starting after durable R.
r = Apply(st, RecoveryFactsObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, R: 50, S: 10, H: 150})
start := findStartCatchUp(t, r.Commands)
+3
View File
@@ -82,6 +82,9 @@ const (
// RecoveryTruth: what recovery is needed. Authority: primary.
type RecoveryTruth struct {
// FactsMissing preserves an all-zero probe's unknown confidence even
// while R retains already-confirmed durable progress.
FactsMissing bool
R uint64 // replica durable/achieved boundary
S uint64 // primary recoverable start boundary (WAL tail)
H uint64 // primary target boundary (head)
+1 -1
View File
@@ -127,7 +127,7 @@ stateDiagram-v2
| (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 | member, reachable, caught up, fenced at the current epoch, post-rebuild durable acknowledgement delivered; for RF=3 also a fresh probe and coverage of the required frontier: known, or proven by at least P-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` |
**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. 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.
**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.
**Peer state, as the primary sees each replica** (type `ReplicaState` in `core/replication/peer.go`). A new peer starts `Healthy` (`NewReplicaPeer`).
+1 -1
View File
@@ -319,4 +319,4 @@ end-to-end wall-clock latency guarantee. Keep long model runs off tp04.
HostBudget also models guarded configuration initialization: staged bytes are invisible until atomic publication; an initializer crash permits a successor. `HostBudget_partial_config.cfg` must violate NoPartialConfig. The syscall-level crash boundary is covered by TestKilledInitializerDoesNotPublishPartialConfiguration.
## Replica apply ordering
`ReplicaApplyOrder.tla` models two admitted sessions on one LBA with three versions, plus the two events of one probe and a delayed post-completion probe. `R292_safe` checks `NoRegression` and `NoDuplicateRecovery`; the three `R292_red_*` configurations remove one guard each. It abstracts successful physical applies only: it does not establish restart persistence, authority, byte-level framing, or I/O deadlines.
`ReplicaApplyOrder.tla` models two admitted sessions on one LBA with three versions, plus the two events of one probe and a delayed post-completion probe. `R292_safe` checks `NoRegression`, `NoDuplicateRecovery` and `NoFalseKnown`; the four `R292_red_*` configurations remove one guard each. It abstracts successful physical applies only: it does not establish restart persistence, authority, byte-level framing, or I/O deadlines.
+19 -9
View File
@@ -4,13 +4,14 @@ EXTENDS Integers, TLC
\* Two admitted sessions, one LBA, three versions. Bytes are represented by
\* their LSN. Storage faults, restart persistence and authority are external
\* obligations; this model checks successful apply ordering and probe dedupe.
CONSTANTS SharedVersions, PrepareEachEvent, MonotoneFacts
VARIABLES applied, local, bytes, seen, stage, active, starts, replicaR
vars == <<applied, local, bytes, seen, stage, active, starts, replicaR>>
CONSTANTS SharedVersions, PrepareEachEvent, MonotoneFacts, PreserveUnknownConfidence
VARIABLES applied, local, bytes, seen, stage, active, starts, replicaR, factsKnown, knownDecision
vars == <<applied, local, bytes, seen, stage, active, starts, replicaR, factsKnown, knownDecision>>
Max(a,b) == IF a > b THEN a ELSE b
Init == /\ applied = 0 /\ local = [s \in 1..2 |-> 0]
/\ bytes = 0 /\ seen = 0 /\ stage = 0
/\ active = FALSE /\ starts = 0 /\ replicaR = 0
/\ factsKnown = TRUE /\ knownDecision = TRUE
\* One shared mutex covers stale check, physical apply and version publication.
Apply(s,n) == LET floor == IF SharedVersions THEN applied ELSE local[s]
@@ -18,27 +19,36 @@ Apply(s,n) == LET floor == IF SharedVersions THEN applied ELSE local[s]
/\ applied' = Max(applied,n)
/\ local' = [local EXCEPT ![s] = Max(@,n)]
/\ seen' = Max(seen,n)
/\ UNCHANGED <<stage, active, starts, replicaR>>
/\ UNCHANGED <<stage, active, starts, replicaR, factsKnown, knownDecision>>
\* A probe's two semantic events must observe the same reserved session.
FirstEvent == /\ stage = 0 /\ stage' = 1 /\ starts' = 1
/\ active' = PrepareEachEvent
/\ UNCHANGED <<applied, local, bytes, seen, replicaR>>
/\ UNCHANGED <<applied, local, bytes, seen, replicaR, factsKnown, knownDecision>>
SecondEvent == /\ stage = 1 /\ stage' = 2
/\ starts' = IF active THEN starts ELSE starts + 1
/\ active' = TRUE
/\ UNCHANGED <<applied, local, bytes, seen, replicaR>>
/\ UNCHANGED <<applied, local, bytes, seen, replicaR, factsKnown, knownDecision>>
Complete == /\ stage = 2 /\ stage' = 3 /\ replicaR' = 3
/\ active' = FALSE
/\ UNCHANGED <<applied, local, bytes, seen, starts>>
/\ UNCHANGED <<applied, local, bytes, seen, starts, factsKnown, knownDecision>>
DelayedProbe == /\ stage = 3 /\ stage' = 4
/\ replicaR' = IF MonotoneFacts THEN replicaR ELSE 1
/\ starts' = IF replicaR' < 3 THEN starts + 1 ELSE starts
/\ active' = (replicaR' < 3)
/\ UNCHANGED <<applied, local, bytes, seen>>
/\ UNCHANGED <<applied, local, bytes, seen, factsKnown, knownDecision>>
\* Retaining durable R does not give an all-zero probe known confidence.
MissingProbe == /\ stage = 3 /\ stage' = 5
/\ factsKnown' = FALSE
/\ knownDecision' = ~PreserveUnknownConfidence
/\ UNCHANGED <<applied, local, bytes, seen, active, starts, replicaR>>
FreshAck == /\ stage = 5 /\ stage' = 3
/\ factsKnown' = TRUE /\ knownDecision' = TRUE
/\ UNCHANGED <<applied, local, bytes, seen, active, starts, replicaR>>
Next == (\E s \in 1..2, n \in 1..3 : Apply(s,n))
\/ FirstEvent \/ SecondEvent \/ Complete \/ DelayedProbe
\/ FirstEvent \/ SecondEvent \/ Complete \/ DelayedProbe \/ MissingProbe \/ FreshAck
Spec == Init /\ [][Next]_vars
NoRegression == bytes = seen
NoDuplicateRecovery == starts <= 1
NoFalseKnown == ~factsKnown => ~knownDecision
=============================================================================
@@ -2,4 +2,5 @@ SPECIFICATION Spec
CONSTANTS SharedVersions = TRUE
PrepareEachEvent = FALSE
MonotoneFacts = TRUE
PreserveUnknownConfidence = TRUE
INVARIANT NoDuplicateRecovery
@@ -2,4 +2,5 @@ SPECIFICATION Spec
CONSTANTS SharedVersions = TRUE
PrepareEachEvent = TRUE
MonotoneFacts = FALSE
PreserveUnknownConfidence = TRUE
INVARIANT NoDuplicateRecovery
@@ -2,4 +2,5 @@ SPECIFICATION Spec
CONSTANTS SharedVersions = FALSE
PrepareEachEvent = TRUE
MonotoneFacts = TRUE
PreserveUnknownConfidence = TRUE
INVARIANT NoRegression
@@ -0,0 +1,6 @@
SPECIFICATION Spec
CONSTANTS SharedVersions = TRUE
PrepareEachEvent = TRUE
MonotoneFacts = TRUE
PreserveUnknownConfidence = FALSE
INVARIANT NoFalseKnown
+2 -1
View File
@@ -2,4 +2,5 @@ SPECIFICATION Spec
CONSTANTS SharedVersions = TRUE
PrepareEachEvent = TRUE
MonotoneFacts = TRUE
INVARIANTS NoRegression NoDuplicateRecovery
PreserveUnknownConfidence = TRUE
INVARIANTS NoRegression NoDuplicateRecovery NoFalseKnown