diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index b247046a5e..bd895ebb89 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -459,6 +459,7 @@ Notes: | `PROGRESS-DESTRUCTIVE` | Supported guest zero-data writes use ordinary COW and do not abort every update. Unsupported DSM/discard/write-zeroes opcodes reach no storage mutation. Administrative Recover/reset/BASE still invalidate and drain; progress assumes these lifecycle transitions eventually stop. | M1 Write / M5 Save | `chunk_cut_cow.go` `beforeCOWMutation`; frontend dispatch | `TestCutCOWV3_ZeroWritesDoNotAbortUpdates` (`core/storage/chunk_cut_alignment_test.go`); `TestDispatch_UnsupportedOperations` (`core/frontend/ublk/dispatch_test.go`); `TestT2Batch11a_IdentifyController_ONCSAllZero` (`core/frontend/nvme/identify_test.go`) | Guest/lifecycle distinction not modelled; native controls | ACTIVE | | `INV-CUT-PAYLOAD-BOUNDED-001` | Upload workers, active savers and cached saves share a configurable per-volume payload byte bound independent of candidate count; an explicit budget below six chunks is refused. An optional Budget admits before staging/barrier and accounts each COW save without a window lock; revocation aborts only the cut and its ticket is released after worker joins. Host-wide policy is a separate limiter module. WAL batch validation uses block-sized scratch even when a record spans many chunks. Pre-copy streams one chunk per worker; native at-H reads protect unsent candidates with COW. Only guest overwrites consume side-file bytes. A full side-file cap aborts the update, retains its dirty set and allows guest writes to proceed. Uploads join before cleanup. | M5 Stage / Copy / Upload | `chunk_cut_payload.go`; `chunk_cut_cow.go`; `chunk_upload.go` | `TestCutBudgetRefusesBeforeBarrier`, `TestCutBudgetCOWRefusalAbortsOnlyCut`, `TestCutBudgetRevocationJoinsBeforeRelease` (`core/storage/chunk_cut_budget_test.go`); `TestV3ReadLargeBatchScratchIsBlockBounded`, `TestCutAbortReasonsAreCountedAndCopied`, `TestCutPayloadBudgetBoundsSlots`, `TestChunkLayerPayloadBudgetRejectsUndersized` (`core/storage/chunk_cut_payload_budget_test.go`); `TestWALStoreChunk_InitialWriteAnonymousMemory` (isolated Linux RSS arms, `core/frontend/durable/provider_initial_memory_linux_test.go`); `TestCutCOWV3_ChangedImageExceedsSpillCap`, `TestChunkStageV3_ChangedImageExceedsSpillCap`, `TestCutCOWV3_OverwriteStormAbortsAndRetries`, `TestCutCOWV3_RemoteUploadDoesNotParkCopiedChunk` (`core/storage/chunk_cut_cow_spillcap_test.go`); `TestChunkUploads_FailureJoinsBeforeIntentCleanup` (`core/storage/chunk_upload_parallel_test.go`) | `CutPipeline` `AbortPoint` covers refused-point stutter; byte counts and filesystem/transport resource costs are not modelled | ACTIVE | | `INV-HOST-CUT-BUDGET-001` | Cooperating cut processes hold an OS slot before staging/barrier; payload and side caps are reserved per slot, including urgent slots. Cancellation never frees a slot before actual worker settlement. Missing-pool fallback is explicitly degraded and cannot claim the shared bound. | M7 admission/drain/release | `core/hostlimit`; durable `ChunkBudget`; blockvolume host-limit flags | `TestSlotsUrgentAndJoinedRelease`, `TestCOWAbortHoldsSlotUntilWorkerSettlement`, `TestHoldExpiryAndCloseDoNotSteal`, `TestKilledProcessReleasesButLiveHolderDoesNot`, `TestHostCutLimitDoesNotGateGuestIO`, `TestHostCOWCapAbortsCutAndRetainsPermitUntilJoin`, `TestCutPolicy_StaggerPreservesExplicitTimerReset`, `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` HeldUntilJoined/PayloadBound/SpillBound (bounded OS-lock abstraction; fallback excluded) | ACTIVE | +| `INV-HOST-POOL-CONFIG-001` | A pool configuration is invisible until its complete synced temporary file is atomically renamed under the OS configuration lock. A killed initializer cannot leave a partial visible configuration that strands successors. | M7 configuration preparation/publication | `core/hostlimit` `publishConfig` | `TestKilledInitializerDoesNotPublishPartialConfiguration` | `HostBudget` NoPartialConfig/ConfigBeforeAdmission (filesystem atomicity checked natively) | ACTIVE | | `INV-CUT-INTENT-FIRST-001` | Before the first upload of a cut or staging round, one intent names every preallocated candidate key (unused keys are harmless), independent of upload wave count. Known-aborted reusable roots are removed at clean Close; unresolved CAS roots remain protected. Intent removal follows a known CAS outcome. | M5 Intent → Upload → CAS | `core/storage/chunk_layer.go` `captureLocked`, `stage`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestCutPayloadReadsOverlapEarlierUploadsWithinBudget`, `TestCutPayloadIntentCountIndependentOfCandidates`, `TestChunkCloseDropsReusableButKeepsUnknownCASRoots`, `TestChunkIntent_WrittenBeforeFirstUploadAndDeletedAfterCAS` (`core/storage/chunk_layer_intent_test.go`); `TestChunkPrecopy_StagedUploadsAreCoveredByIntents` (`core/storage/chunk_layer_precopy_test.go`) | `ChunkLifecycleFixed` `GCSafe`; `WorkspaceTakeover` `NoLiveIntentExpired` | ACTIVE | | `INV-CUT-SEGMENT-REUSE-001` | A cut rewrites only manifest segments whose chunk references changed, and an uploaded but unpublished segment leaves the published root unchanged. | M5 Manifest | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` (`core/frontend/chunkstore/manifest_test.go`) | `CutPipeline` `SegConsistent` | ACTIVE | | `INV-CUT-HYDRATION-WAIT-001` | A read command shares its arrival deadline across chunks. A timed-out waiter returns typed pending without cancelling a shared fill. Per-layer worker and distinct-flight limits bound remote work; Close wakes waiters and joins issued fills before storage release. Physical/hash errors remain terminal. | M4 Holder (hydration wait) | `core/storage/chunk_hydration.go`; `core/storage/walstore.go` `ReadContext`; `core/frontend/durable/storage_adapter.go` `readStorageBlock`; `core/frontend/nvme/session.go` `handleRead` | `TestDurableHydration_MultipleChunksShareOneDeadline`, `TestDurableHydration_NVMePreservesPhysicalAndHashErrors`, `TestSessionReadBudgetIncludesQueueResidence`, `TestChunkHydration_QueueAndWorkerLimitsAreBounded`, `TestChunkHydration_CloseWakesCallerAndJoinsUninterruptibleGet`, `TestChunkHydration_ContextlessReadAllowsSlowFill`, `TestChunkHydration_NewGenerationDoesNotJoinStaleGet`, `TestChunkHydration_StaleCompletionKeepsReplacement`, `TestDurableHydration_RMWFenceWinsCallerExpiry` | — | ACTIVE | diff --git a/seaweed-block/docs/spec/HostBudget.tla b/seaweed-block/docs/spec/HostBudget.tla index 3d536cc503..b2cea0fe8e 100644 --- a/seaweed-block/docs/spec/HostBudget.tla +++ b/seaweed-block/docs/spec/HostBudget.tla @@ -1,43 +1,61 @@ ----------------------------- MODULE HostBudget ----------------------------- EXTENDS Integers, FiniteSets, TLC -CONSTANTS N, SlotCount, Payload, Spill, EarlyRelease +CONSTANTS N, SlotCount, Payload, Spill, EarlyRelease, AtomicConfig Owners == 1..N Slots == 1..SlotCount -VARIABLES phase, owner, slot, saved -vars == <> -Init == /\ phase = [o \in Owners |-> "free"] +VARIABLES phase, owner, slot, saved, cfg, initializer +vars == <> +Init == /\ cfg = "absent" + /\ initializer = 0 + /\ phase = [o \in Owners |-> "free"] /\ owner = [s \in Slots |-> 0] /\ slot = [o \in Owners |-> 0] /\ saved = [o \in Owners |-> 0] -Admit(o,s) == /\ phase[o] = "free" /\ owner[s] = 0 +Admit(o,s) == /\ cfg = "ready" + /\ phase[o] = "free" /\ owner[s] = 0 /\ (o = N \/ s < SlotCount) /\ phase' = [phase EXCEPT ![o] = "active"] /\ owner' = [owner EXCEPT ![s] = o] /\ slot' = [slot EXCEPT ![o] = s] - /\ UNCHANGED saved + /\ UNCHANGED <> Save(o) == /\ phase[o] = "active" /\ saved[o] < Spill /\ saved' = [saved EXCEPT ![o] = @ + 1] - /\ UNCHANGED <> + /\ UNCHANGED <> Abort(o) == /\ phase[o] = "active" /\ phase' = [phase EXCEPT ![o] = "draining"] /\ owner' = IF EarlyRelease THEN [owner EXCEPT ![slot[o]] = 0] ELSE owner - /\ UNCHANGED <> + /\ UNCHANGED <> Join(o) == /\ phase[o] \in {"active","draining"} /\ phase' = [phase EXCEPT ![o] = "joined"] - /\ UNCHANGED <> + /\ UNCHANGED <> Release(o) == /\ phase[o] = "joined" /\ owner' = [owner EXCEPT ![slot[o]] = 0] /\ phase' = [phase EXCEPT ![o] = "free"] /\ slot' = [slot EXCEPT ![o] = 0] /\ saved' = [saved EXCEPT ![o] = 0] + /\ UNCHANGED <> Crash(o) == /\ phase[o] # "free" /\ owner' = [owner EXCEPT ![slot[o]] = 0] /\ phase' = [phase EXCEPT ![o] = "free"] /\ slot' = [slot EXCEPT ![o] = 0] /\ saved' = [saved EXCEPT ![o] = 0] -Next == (\E o \in Owners,s \in Slots: Admit(o,s)) \/ + /\ UNCHANGED <> +BeginConfig(o) == /\ cfg = "absent" + /\ cfg' = IF AtomicConfig THEN "writing" ELSE "partial" + /\ initializer' = o + /\ UNCHANGED <> +PublishConfig == /\ cfg \in {"writing","partial"} + /\ cfg' = "ready" /\ initializer' = 0 + /\ UNCHANGED <> +CrashInitializer == /\ cfg \in {"writing","partial"} + /\ cfg' = "absent" /\ initializer' = 0 + /\ UNCHANGED <> +Next == (\E o \in Owners: BeginConfig(o)) \/ PublishConfig \/ CrashInitializer \/ + (\E o \in Owners,s \in Slots: Admit(o,s)) \/ (\E o \in Owners: Save(o) \/ Abort(o) \/ Join(o) \/ Release(o) \/ Crash(o)) Spec == Init /\ [][Next]_vars +NoPartialConfig == cfg # "partial" +ConfigBeforeAdmission == (\E o \in Owners: phase[o] # "free") => cfg = "ready" HeldUntilJoined == \A o \in Owners: phase[o] # "free" => owner[slot[o]] = o RECURSIVE Total(_) Total(n) == IF n=0 THEN 0 ELSE saved[n]+Total(n-1) diff --git a/seaweed-block/docs/spec/README.md b/seaweed-block/docs/spec/README.md index a7f9ff62e7..98c2c668f4 100644 --- a/seaweed-block/docs/spec/README.md +++ b/seaweed-block/docs/spec/README.md @@ -315,3 +315,5 @@ end-to-end wall-clock latency guarantee. Keep long model runs off tp04. ## HostBudget `HostBudget.tla` abstracts cooperating process slots, COW reservation and joined release. Config `HostBudget.cfg` checks three owners/two slots; `HostBudget_early_release.cfg` must violate HeldUntilJoined. It excludes degraded static fallback and does not prove filesystem locks, rates or physical-I/O deadlines. Native subprocess tests cover lock lifetime. + +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. diff --git a/seaweed-block/docs/spec/cfg/HostBudget.cfg b/seaweed-block/docs/spec/cfg/HostBudget.cfg index 691fdc1a6e..37f2082ee0 100644 --- a/seaweed-block/docs/spec/cfg/HostBudget.cfg +++ b/seaweed-block/docs/spec/cfg/HostBudget.cfg @@ -4,5 +4,6 @@ SlotCount=2 Payload=1 Spill=2 EarlyRelease=FALSE +AtomicConfig=TRUE SPECIFICATION Spec -INVARIANTS HeldUntilJoined PayloadBound SpillBound +INVARIANTS NoPartialConfig ConfigBeforeAdmission HeldUntilJoined PayloadBound SpillBound diff --git a/seaweed-block/docs/spec/cfg/HostBudget_early_release.cfg b/seaweed-block/docs/spec/cfg/HostBudget_early_release.cfg index d69a380860..6cf3a12ea2 100644 --- a/seaweed-block/docs/spec/cfg/HostBudget_early_release.cfg +++ b/seaweed-block/docs/spec/cfg/HostBudget_early_release.cfg @@ -4,5 +4,6 @@ SlotCount=2 Payload=1 Spill=2 EarlyRelease=TRUE +AtomicConfig=TRUE SPECIFICATION Spec -INVARIANTS HeldUntilJoined PayloadBound SpillBound +INVARIANTS NoPartialConfig ConfigBeforeAdmission HeldUntilJoined PayloadBound SpillBound diff --git a/seaweed-block/docs/spec/cfg/HostBudget_partial_config.cfg b/seaweed-block/docs/spec/cfg/HostBudget_partial_config.cfg new file mode 100644 index 0000000000..f0e304be5b --- /dev/null +++ b/seaweed-block/docs/spec/cfg/HostBudget_partial_config.cfg @@ -0,0 +1,9 @@ +CONSTANTS +N=3 +SlotCount=2 +Payload=1 +Spill=2 +EarlyRelease=FALSE +AtomicConfig=FALSE +SPECIFICATION Spec +INVARIANTS NoPartialConfig ConfigBeforeAdmission HeldUntilJoined PayloadBound SpillBound