diff --git a/seaweed-block/core/engine/recovery_prefix_test.go b/seaweed-block/core/engine/recovery_prefix_test.go index 464b8ea878..d58b5367cc 100644 --- a/seaweed-block/core/engine/recovery_prefix_test.go +++ b/seaweed-block/core/engine/recovery_prefix_test.go @@ -12,7 +12,7 @@ func TestHealthyPrefixRequiresCompletedRecoveryAndPostCloseAck(t *testing.T) { t.Fatal("recovery close certified before post-close ack") } } - result = Apply(st, DurableAckObserved{ReplicaID: "r1", SessionID: 8, EndpointVersion: 1, TransportEpoch: 1, DurableLSN: 120, PrimaryTailLSN: 1, PrimaryHeadLSN: 120}) + result = Apply(st, DurableAckObserved{ReplicaID: "r1", EndpointVersion: 1, TransportEpoch: 1, DurableLSN: 120, PrimaryTailLSN: 1, PrimaryHeadLSN: 120}) for _, command := range result.Commands { if healthy, ok := command.(PublishHealthy); ok { if healthy.CertifiedPrefix != 100 || healthy.RecoverySessionID != 8 || healthy.Epoch != 1 || healthy.EndpointVersion != 1 { diff --git a/seaweed-block/docs/design/block-design.md b/seaweed-block/docs/design/block-design.md index 41a572dd55..9061f000c4 100644 --- a/seaweed-block/docs/design/block-design.md +++ b/seaweed-block/docs/design/block-design.md @@ -299,6 +299,7 @@ stateDiagram-v2 Degraded --> CatchingUp: gap within the primary's WAL CatchingUp --> CatchingUp: identical recovery facts retain the prepared session Healthy --> Healthy: delayed probe retains completed durable R + Healthy --> Healthy: completed recovery certifies P, prune version suffix CatchingUp --> Healthy: caught up to the target CatchingUp --> Degraded: catch-up fails Degraded --> Healthy: recovers diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index afe5586a3a..e30a534706 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -114,6 +114,13 @@ stateDiagram-v2 Excluded --> Supporting: later fact lists self as a peer ``` +The apply gate retains versions only above its certified contiguous prefix P. +Completed recovery plus post-close healthy publication sends an explicit full-lineage +certificate; current listener admission and the durable boundary guard it. Sync R, +ordinary live traffic and session changes do not advance P. This implementation +prunes at successful recovery certification only; healthy-run growth remains an +RF2 qualification limitation until ordered-live certification is wired. + **Host role and listener admission.** | From | To | Event and guard | Enforced in | Protects | @@ -135,7 +142,7 @@ stateDiagram-v2 |---|---|---|---|---| | `Healthy`, `Unknown` | `Degraded` or `CatchingUp` | ship, barrier or fence failure; or a probe that needs catch-up | `core/replication/peer.go` `ReplicaPeer.SetState`, `replicaStateTransitionAllowed` | `INV-REPL-PEER-TRANSITIONS-001` | | `Degraded` | `CatchingUp` or `NeedsRebuild` | the engine decides catch-up when the gap is in the primary's WAL, rebuild when it is not | `core/engine/apply.go` `decide` | `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-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. 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` | `ReplicaApplyOrder` NoRegression | 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-CATCHUP-REBUILD-001` | | `CatchingUp` | `Healthy`, `Degraded` or `NeedsRebuild` | done-acknowledgement; failure; WAL recycled or retries exhausted | `core/replication/peer.go` `ReplicaPeer.SetState` | `INV-REPL-PEER-TRANSITIONS-001` | | any but `NeedsRebuild` | `Healthy` | recovered | `core/replication/peer.go` `replicaStateTransitionAllowed` | `INV-REPL-PEER-TRANSITIONS-001` | diff --git a/seaweed-block/docs/spec/README.md b/seaweed-block/docs/spec/README.md index 8190995f3e..a3586b8834 100644 --- a/seaweed-block/docs/spec/README.md +++ b/seaweed-block/docs/spec/README.md @@ -320,3 +320,10 @@ HostBudget also models guarded configuration initialization: staged bytes are in ## 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`, `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. + +`ReplicaPrefixFloor.tla` checks two LBAs/three source versions with explicit +covered-prefix certification, suffix pruning and stale checks against the floor. +`R293_prefix_safe` checks `NoRegression`, `CertifiedCoverage`, and `OnlySuffix`; +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. diff --git a/seaweed-block/docs/spec/ReplicaPrefixFloor.tla b/seaweed-block/docs/spec/ReplicaPrefixFloor.tla new file mode 100644 index 0000000000..70e419d693 --- /dev/null +++ b/seaweed-block/docs/spec/ReplicaPrefixFloor.tla @@ -0,0 +1,31 @@ +----------------------- MODULE ReplicaPrefixFloor ----------------------- +EXTENDS Integers, TLC +CONSTANTS UseFloor, CertifiedOnly +VARIABLES data, seen, versions, durable, prefix +vars == <> +Addr(n) == IF n = 2 THEN 2 ELSE 1 +Max(a,b) == IF a > b THEN a ELSE b +Covered(p) == \A n \in 1..p : data[Addr(n)] >= n +Init == /\ data = [i \in 1..2 |-> 0] /\ seen = data /\ versions = data + /\ durable = 0 /\ prefix = 0 +Apply(n) == LET i == Addr(n) + threshold == Max(versions[i], IF UseFloor THEN prefix ELSE 0) + IN /\ data' = IF n > threshold THEN [data EXCEPT ![i] = n] ELSE data + /\ seen' = [seen EXCEPT ![i] = Max(@,n)] + /\ versions' = IF n > threshold THEN [versions EXCEPT ![i] = n] ELSE versions + /\ UNCHANGED <> +Sync == /\ durable' = Max(durable, Max(data[1],data[2])) + /\ UNCHANGED <> +Certify(p) == /\ p > prefix /\ p <= durable + /\ (~CertifiedOnly \/ Covered(p)) + /\ prefix' = p + /\ versions' = [i \in 1..2 |-> IF versions[i] <= p THEN 0 ELSE versions[i]] + /\ UNCHANGED <> +\* Session changes, ordinary live writes, disconnects and Sync do not certify. +RestartSession == UNCHANGED vars +Next == (\E n \in 1..3 : Apply(n)) \/ Sync \/ (\E p \in 1..3 : Certify(p)) \/ RestartSession +Spec == Init /\ [][Next]_vars +NoRegression == data = seen +CertifiedCoverage == Covered(prefix) +OnlySuffix == \A i \in 1..2 : versions[i] = 0 \/ versions[i] > prefix +============================================================================= \ No newline at end of file diff --git a/seaweed-block/docs/spec/cfg/R293_prefix_red_forgot_floor.cfg b/seaweed-block/docs/spec/cfg/R293_prefix_red_forgot_floor.cfg new file mode 100644 index 0000000000..651a875730 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/R293_prefix_red_forgot_floor.cfg @@ -0,0 +1,4 @@ +SPECIFICATION Spec +CONSTANTS UseFloor = FALSE + CertifiedOnly = TRUE +INVARIANTS NoRegression CertifiedCoverage OnlySuffix diff --git a/seaweed-block/docs/spec/cfg/R293_prefix_red_synced_max.cfg b/seaweed-block/docs/spec/cfg/R293_prefix_red_synced_max.cfg new file mode 100644 index 0000000000..2e7b34a866 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/R293_prefix_red_synced_max.cfg @@ -0,0 +1,4 @@ +SPECIFICATION Spec +CONSTANTS UseFloor = TRUE + CertifiedOnly = FALSE +INVARIANTS NoRegression CertifiedCoverage OnlySuffix diff --git a/seaweed-block/docs/spec/cfg/R293_prefix_safe.cfg b/seaweed-block/docs/spec/cfg/R293_prefix_safe.cfg new file mode 100644 index 0000000000..8fc29bed97 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/R293_prefix_safe.cfg @@ -0,0 +1,4 @@ +SPECIFICATION Spec +CONSTANTS UseFloor = TRUE + CertifiedOnly = TRUE +INVARIANTS NoRegression CertifiedCoverage OnlySuffix diff --git a/seaweed-block/docs/spec/run.sh b/seaweed-block/docs/spec/run.sh index 4bfc7d0b46..06ed9184b8 100755 --- a/seaweed-block/docs/spec/run.sh +++ b/seaweed-block/docs/spec/run.sh @@ -25,6 +25,7 @@ case $cfg in S4_*) spec=CutCapture ;; S5_*) spec=ControlPlane ;; S6_*) spec=ReplicationFailover ;; + R293_prefix_*) spec=ReplicaPrefixFloor ;; R292_*) spec=ReplicaApplyOrder ;; S9b_*) spec=RetentionGCMulti ;; S9_*) spec=RetentionGCTiming ;;