docs: align replica lifecycle and promotion guard models

This commit is contained in:
pingqiu committed 2026-11-20 05:23:15 -08:00
1 parent 704eedac67
commit db07ef2c16
11 files changed
+78 -4

No files matched your search

+2
View File
@@ -42,6 +42,8 @@ const (
// not derive source coverage from Sync. Admission is checked at the effect.
type SessionRetirer interface{ CloseSession(sessionID uint64) }
// RecoveryPrefixHook accepts explicit completed-prefix certificates. It does
// not derive source coverage from Sync. Admission is checked at the effect.
type RecoveryPrefixHook interface {
CertifyRecoveryPrefix(lineage RecoveryLineage) error
CertifiedPrefix() uint64
@@ -298,6 +298,7 @@ stateDiagram-v2
Healthy --> Degraded: barrier or ship failure
Degraded --> CatchingUp: gap within the primary's WAL
CatchingUp --> CatchingUp: identical recovery facts retain the prepared session
CatchingUp --> CatchingUp: active session refuses promotion readiness
Healthy --> Healthy: delayed probe retains completed durable R
Healthy --> Healthy: completed recovery certifies P, prune version suffix
CatchingUp --> Healthy: caught up to the target
+5 -4
View File
@@ -132,7 +132,7 @@ RF2 qualification limitation until ordered-live certification is wired (#297). S
| Primary, Supporting | Excluded | the fact names another primary and does not list this replica; ingress is closed, the other line is recorded and the frontend is unhealthy | `core/host/volume/host.go` `applyFact`, `recordOtherLine`; `core/host/volume/projection_bridge.go` `projectionWithSupersede` | `INV-ROLE-SUPERSEDED-001`, `INV-FENCE-STALE-PRIMARY-001` |
| 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 | 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` |
| Supporting | promotion candidate | no active recovery session; 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; 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.
@@ -333,7 +333,7 @@ snapshot lifetime; local persistence does not bypass it.
## Part B. Invariant ledger
83 rows: 72 ACTIVE, 11 STUB; 15 kept from the internal ledger, 68 new.
117 rows: 98 ACTIVE, 19 STUB; 15 kept from the internal ledger, 102 new.
The "Machine / transition" column refers to Part A. Notes under a table record what a row does not cover and, for kept rows, what was narrowed from the internal ledger.
@@ -423,7 +423,8 @@ Notes:
| ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status |
|---|---|---|---|---|---|---|
| `INV-REPL-RECOVERY-SESSION-UNIQUE-001` | Each runtime observation selects at most one recovery session; delayed same-identity facts cannot restart a completed prefix, while a higher primary head or replacement identity still permits new work. | M3 recovery observation / preparation | `core/adapter/adapter.go`, `normalize.go`; `core/engine/apply.go` | `TestAdapter_OneRecoveryFromPostCloseStalledAck`, `TestAdapter_OneRecoveryPreparedWithinProbeBatch`, `TestAdapter_ConcurrentOldProbesNeverRestartHealthyRecovery`, `TestAdapter_ProbeUsesFreshBoundsBeforePreparingRecovery`, `TestRecoveryProbeKeepsCompletedRButAllowsNewWorkAndIdentity`, `TestC5_OrderStableAcrossRuns` | `ReplicaApplyOrder` NoDuplicateRecovery | ACTIVE |
| `INV-REPL-SESSION-COVERAGE-RETIRE-001` | Superseded logical-session coverage is released only after every already-admitted frame for that session settles; newer sessions do not delay that release. Shared version history and P survive. | M3 replica admission / session retirement | `transport/replica.go` `admitMutation`, `endSessionFrame`; `ReplicaApplyGate.CloseSession` | `TestApplyGate_WireSessionTurnoverRetiresSettledCoverage`, `TestApplyGate_AlreadyAdmittedWireSessionNeverRegressesBytes` | `ReplicaReviewGuards` NoEarlyRetirement/NoSettledHistory | ACTIVE |
| `INV-REPL-RECOVERY-SESSION-UNIQUE-001` | Each runtime observation selects at most one recovery session; delayed same-identity facts cannot restart a completed prefix, while a higher primary head or replacement identity still permits new work. | M3 recovery observation / preparation | `core/adapter/adapter.go`, `normalize.go`; `core/engine/apply.go` | `TestAdapter_OneRecoveryFromPostCloseStalledAck`, `TestAdapter_OneRecoveryPreparedWithinProbeBatch`, `TestAdapter_ConcurrentOldProbesNeverRestartHealthyRecovery`, `TestAdapter_ProbeUsesFreshBoundsBeforePreparingRecovery`, `TestRecoveryProbeKeepsCompletedRButAllowsNewWorkAndIdentity`, `TestMissingProbeAckRestoresNewerDurableProgress`, `TestC5_OrderStableAcrossRuns` | `ReplicaApplyOrder` NoDuplicateRecovery; `ReplicaReviewGuards` AckRestoresProgress | ACTIVE |
| `INV-REPL-NO-PER-LBA-DATA-REGRESSION` | Successful applies share a replica-wide per-LBA version across all sessions and lanes. Stale recovery advances only its own coverage; stale live entries fail. Closing a session or merging a lower seed cannot erase the applied version; failed physical writes do not publish it. Only an explicit completed-recovery prefix certificate advances P and prunes entries at/below P; the floor still rejects/skips old records. Synced R is not a certificate. Restart safety still requires substrate seeds. | M3 replica apply / session release | `core/replication/apply_gate.go`; blockvolume `replicationIngress` | `TestReplicationIngressSharesApplyVersionsAcrossSessions`, `TestApplyGate_OverlappingSessionsNeverRegressBytes`, `TestApplyGate_AlreadyAdmittedWireSessionNeverRegressesBytes`, `TestApplyGate_CloseAndLowerSeedNeverEraseReplicaVersion`, `TestApplyGate_FailedWriteDoesNotPublishReplicaVersion`, `TestApplyGate_CertifiedRecoveryClosesBoundVersionHistory`, `TestApplyGate_PrunedDurableVersionsRemainStale`, `TestApplyGate_CertifiedPrefixFreezesAcrossSessions`, `TestApplyGate_SyncedLiveMaximumDoesNotCoverRecoveryHole`, `TestApplyGate_HealthyRecoveryPublishesWirePrefix`, `TestApplyGate_WirePrefixCannotIntroduceOrReviveSession` | `ReplicaApplyOrder` NoRegression; `ReplicaPrefixFloor` NoRegression/CertifiedCoverage/OnlySuffix | ACTIVE |
| `INV-REPL-REBUILD-PORT-FENCE-001` | The dual-lane rebuild port applies the replica listener's admission rules: no frame on a primary, below the epoch floor, or before the role is known. | M3 listener admission | `core/transport/replica.go` `EnterDualLane` | `TestDualLaneRebuildPort_RefusesStaleSenderAfterFence`, `TestDualLaneRebuildPort_RefusesBeforeRoleKnown` (`core/transport/g6_dual_lane_fence_test.go`) | — | ACTIVE |
| `INV-REPL-APPLY-FAIL-001` | A failed `ApplyEntry` on a replica closes the connection, so no barrier acknowledges past the gap. | M3 Healthy → Degraded | `core/transport/replica.go` `handleConn` | `TestReplicaApplyFailureStopsBarrierAtTheGap` (`core/transport/replica_apply_error_test.go`); `TestReplicaApplyFailure_PrimaryDegradesRecoversAndReplaysFailedLSN` (`core/replication/component/replica_apply_failure_recovery_test.go`) | — | ACTIVE |
@@ -431,7 +432,7 @@ Notes:
| `INV-REPL-CATCHUP-REBUILD-001` | The engine chooses catch-up when the gap is still in the primary's WAL and rebuild when it is not. | M3 Degraded → CatchingUp \| NeedsRebuild | `core/engine/apply.go` `decide` | `TestV3_Decision_CatchUp_GapWithinWAL`, `TestV3_Decision_Rebuild_GapBeyondWAL` (`core/engine/apply_test.go`) | — | ACTIVE |
| `INV-REPL-PEER-TRANSITIONS-001` | `ReplicaPeer.SetState` and `ReplicaPeer.Invalidate` apply only the transitions in the peer table; `NeedsRebuild` has no successor through either. | M3 peer state | `core/replication/peer.go` `ReplicaPeer.SetState`, `ReplicaPeer.Invalidate`, `replicaStateTransitionAllowed` | `TestReplicaStateTransition_AllowedSet`, `TestReplicaStateTransition_RejectedSet`, `TestReplicaStateTransition_NeedsRebuildIsTerminalInT4c` (`core/replication/peer_state_machine_test.go`); `TestReplicaPeer_InvalidatePreservesNeedsRebuildTerminalState` (`core/replication/invalidate_terminal_regression_test.go`); `TestReplicaPeer_InvalidateNonTerminalStatesBecomeDegraded`, `TestReplicaPeer_InvalidateOnNeedsRebuildStillLogsReason` (`core/replication/invalidate_transition_test.go`) | — | ACTIVE |
| `INV-REPL-DURABILITY-MODE-001` | Under `sync_all` a replicated `Sync` fails if any replica barrier fails; under `sync_quorum` it fails unless a majority of nodes, the primary included, are durable. | M3 barrier evaluation | `core/replication/durability.go` `EvaluateBarrierAcks` | `TestDurabilityCoordinator_Quorum_RF3_OneReplicaFailed`, `TestDurabilityCoordinator_Quorum_RF3_BothReplicasFailed`, `TestDurabilityCoordinator_SyncAll_AnyFailure_Fails` (`core/replication/durability_test.go`) | — | ACTIVE |
| `INV-REPL-PROMOTION-READY-001` | A replica reports `promotion_ready` only if it is a member, reachable, caught up, fenced at the current epoch, and has delivered its post-rebuild durable acknowledgement. | M3 Supporting → promotion candidate | `core/engine/promotion_ready.go` `BuildPromotionReadyFact` | `TestBuildPromotionReadyFact_RefusesPendingFence`, `TestBuildPromotionReadyFact_RefusesPostCloseAckGap`, `TestBuildPromotionReadyFact_RefusesNotCaughtUp` (`core/engine/promotion_ready_test.go`) | `WALReplica` `I3`; `ReplicationFailover` `AckedSurvive` | ACTIVE |
| `INV-REPL-PROMOTION-READY-001` | A replica reports `promotion_ready` only if it is a member, reachable, caught up, fenced at the current epoch, and has delivered its post-rebuild durable acknowledgement. An active recovery session always refuses readiness, even if delayed bounds select DecisionNone. | M3 Supporting → promotion candidate | `core/engine/promotion_ready.go` `BuildPromotionReadyFact` | `TestBuildPromotionReadyFact_RefusesPendingFence`, `TestBuildPromotionReadyFact_RefusesPostCloseAckGap`, `TestBuildPromotionReadyFact_RefusesNotCaughtUp` (`core/engine/promotion_ready_test.go`), `TestPromotionReadyRefusesDelayedProbeDuringNewRecovery` | `WALReplica` `I3`; `ReplicationFailover` `AckedSurvive`; `ReplicaReviewGuards` ReadyRequiresIdle | ACTIVE |
| `INV-ROLE-STALE-REPLAY-001` | A role call below the host's current desired epoch is refused and cannot clear a newer role-admission failure. | M3 role admission | `core/host/volume/host.go` `fenceSelfWithPeers`, `latchRoleAdmission` | `TestG1_StaleReplayDoesNotClearANewerAdmissionFailure`, `TestG1_StaleSupportingReplayDoesNotClearTheLatch` (`core/host/volume/g1_admission_latch_test.go`) | — | ACTIVE |
| `INV-ROLE-READINESS-BLOCK-001` | While local recovery blocks readiness, `applyFact` admits neither a primary nor a supporting role, and replays the stored fact once readiness clears. | M3 Unassigned → Primary \| Supporting (guard) | `core/host/volume/host.go` `applyFact`, `replayLocalReadinessFactIfReady` | `TestHost_ApplyFact_Self_LocalReadinessBlocked_SkipsReplicationAndAdapter`, `TestHost_ApplyFact_SupportingReplica_LocalReadinessBlocked_SkipsAdapter`, `TestHost_ApplyFact_Self_ReplaysAfterLocalReadinessClearsWithReplicationFirst` (`core/host/volume/apply_fact_test.go`) | — | ACTIVE |
| `INV-ROLE-SUPERSEDED-001` | A fact naming another replica as primary, with this replica not among its peers, never reaches this host's adapter or replication, and is recorded as the other line. | M3 Primary \| Supporting → Excluded | `core/host/volume/host.go` `applyFact`, `recordOtherLine` | `TestHost_ApplyFact_Supersede_NeverCallsAdapterOrReplication` (`core/host/volume/apply_fact_test.go`); `TestHost_BuildReport_SupersededReplicaNotReadyForPrimary` (`core/host/volume/frontend_targets_test.go`) | — | ACTIVE |
+7
View File
@@ -327,3 +327,10 @@ covered-prefix certification, suffix pruning and stale checks against the floor.
its two negative controls infer a prefix from the synced maximum or omit the
floor after pruning. It does not establish the wire certificate's provenance,
restart persistence, live-prefix extension, or a fixed memory cap without closes.
`ReplicaReviewGuards.tla` checks two logical sessions with one admitted frame
per session, settled-coverage retirement, active-recovery readiness refusal and
one missing-probe/newer-ACK schedule. `R293_review_safe` checks four invariants;
four negative controls separately remove retirement, the frame join, the
readiness guard or ACK progress restoration. This abstracts successful admitted
frames and does not prove physical-I/O, authority rollback or timing behavior.
@@ -0,0 +1,32 @@
---------------------- MODULE ReplicaReviewGuards ----------------------
EXTENDS Integers, TLC
CONSTANTS RetireSettled, WaitForFrames, GuardActive, RestoreAck
VARIABLES current, refs, coverage, active, ready, missing, observedR
vars == <<current, refs, coverage, active, ready, missing, observedR>>
Init == /\ current = 1 /\ refs = [s \in 1..2 |-> 0] /\ coverage = {1}
/\ active = FALSE /\ ready = FALSE /\ missing = TRUE /\ observedR = 100
Admit(s) == /\ s >= current /\ refs[s] = 0
/\ current' = s /\ refs' = [refs EXCEPT ![s] = 1]
/\ coverage' = (coverage \cup {s}) \ (
IF RetireSettled /\ s # current /\ (refs[current] = 0 \/ ~WaitForFrames)
THEN {current} ELSE {})
/\ UNCHANGED <<active,ready,missing,observedR>>
Release(s) == /\ refs[s] = 1 /\ refs' = [refs EXCEPT ![s] = 0]
/\ coverage' = IF RetireSettled /\ s # current THEN coverage \ {s} ELSE coverage
/\ UNCHANGED <<current,active,ready,missing,observedR>>
Prepare == /\ ~active /\ active' = TRUE /\ ready' = FALSE
/\ UNCHANGED <<current,refs,coverage,missing,observedR>>
DelayedProbe == /\ active /\ ready' = ~GuardActive
/\ UNCHANGED <<current,refs,coverage,active,missing,observedR>>
Finish == /\ active /\ active' = FALSE /\ ready' = TRUE
/\ UNCHANGED <<current,refs,coverage,missing,observedR>>
Ack == /\ missing /\ missing' = FALSE
/\ observedR' = IF RestoreAck THEN 150 ELSE 100
/\ UNCHANGED <<current,refs,coverage,active,ready>>
Next == (\E s \in 1..2 : Admit(s) \/ Release(s)) \/ Prepare \/ DelayedProbe \/ Finish \/ Ack
Spec == Init /\ [][Next]_vars
NoEarlyRetirement == \A s \in 1..2 : refs[s] = 1 => s \in coverage
NoSettledHistory == \A s \in coverage : s = current \/ refs[s] = 1
ReadyRequiresIdle == ready => ~active
AckRestoresProgress == ~missing => observedR = 150
=============================================================================
@@ -0,0 +1,6 @@
SPECIFICATION Spec
CONSTANTS RetireSettled = TRUE
WaitForFrames = TRUE
GuardActive = TRUE
RestoreAck = FALSE
INVARIANTS NoEarlyRetirement NoSettledHistory ReadyRequiresIdle AckRestoresProgress
@@ -0,0 +1,6 @@
SPECIFICATION Spec
CONSTANTS RetireSettled = TRUE
WaitForFrames = FALSE
GuardActive = TRUE
RestoreAck = TRUE
INVARIANTS NoEarlyRetirement NoSettledHistory ReadyRequiresIdle AckRestoresProgress
@@ -0,0 +1,6 @@
SPECIFICATION Spec
CONSTANTS RetireSettled = TRUE
WaitForFrames = TRUE
GuardActive = FALSE
RestoreAck = TRUE
INVARIANTS NoEarlyRetirement NoSettledHistory ReadyRequiresIdle AckRestoresProgress
@@ -0,0 +1,6 @@
SPECIFICATION Spec
CONSTANTS RetireSettled = FALSE
WaitForFrames = TRUE
GuardActive = TRUE
RestoreAck = TRUE
INVARIANTS NoEarlyRetirement NoSettledHistory ReadyRequiresIdle AckRestoresProgress
@@ -0,0 +1,6 @@
SPECIFICATION Spec
CONSTANTS RetireSettled = TRUE
WaitForFrames = TRUE
GuardActive = TRUE
RestoreAck = TRUE
INVARIANTS NoEarlyRetirement NoSettledHistory ReadyRequiresIdle AckRestoresProgress
+1
View File
@@ -25,6 +25,7 @@ case $cfg in
S4_*) spec=CutCapture ;;
S5_*) spec=ControlPlane ;;
S6_*) spec=ReplicationFailover ;;
R293_review_*) spec=ReplicaReviewGuards ;;
R293_prefix_*) spec=ReplicaPrefixFloor ;;
R292_*) spec=ReplicaApplyOrder ;;
S9b_*) spec=RetentionGCMulti ;;