diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 21f7210be9..bae4bf19c5 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -521,7 +521,7 @@ Notes: | `INV-WS-HEAD-BELT-001` | After a successful HEAD CAS, takeover or cut, the publisher acts on it only once a re-read of HEAD (the durable frontier) shows that CAS's generation, epoch and holder: a takeover opens I/O only then, a cut settles remoteLSN and the owned map and drops its intents only then. | M4 Claiming → Cooling → Holder; M5 CAS → Settled | `core/storage/chunk_head_belt.go` `casAndConfirmChunkHeadMeasured`, `confirmChunkHead`, `confirmChunkTakeover`; `core/storage/chunk_restore.go` `ClaimChunkHead`; `core/storage/chunk_layer.go` `captureLocked`, `resolvePending`, `SettleDetach` | `TestHeadBeltTakeoverRefusesLateOldCAS`, `TestHeadBeltOldCASUnconfirmedKeepsIntentsAndFrontier`, `TestHeadBeltConfirmationUsesOnlyRoot` (`core/storage/chunk_head_belt_test.go`) | `WorkspaceTakeover` belt extension pending | ACTIVE | | `INV-WS-HEAD-BELT-COOLING-001` | The HEAD cooling window W is 0 or at least 2.1 s (the 2 s HEAD operation deadline plus 100 ms settling); with W > 0 a takeover waits W after its CAS, on the local monotonic clock, before its confirming re-read. | M4 Claiming → Cooling → Holder | `core/storage/chunk_head_belt.go` `validateHeadCoolingWindow`, `confirmChunkTakeover`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestHeadBeltCoolingWindowCoversCASAndSettle`, `TestHeadBeltTakeoverWaitsBeforeConfirmation`, `TestHeadBeltSinglePointHasNoCoolingDelay`, `TestHeadBeltRetryOfUnconfirmedClaimStillCools` (`core/storage/chunk_head_belt_test.go`) | — | ACTIVE | | `INV-WS-HEAD-BELT-DEADLINE-001` | Each HEAD CAS and each HEAD confirmation re-read runs under its own deadline of at most 2 s on the local monotonic clock, nested inside the caller's context. | M4 Claiming → Cooling → Holder; M5 CAS | `core/storage/chunk_head_belt.go` `casChunkHead`, `confirmChunkHead`, `readChunkHead` | `TestHeadBeltOperationsHaveOwnDeadline` (`core/storage/chunk_head_belt_test.go`) | — | ACTIVE | -| `INV-WS-HEAD-BELT-FENCE-001` | A publisher whose CAS failed or was not confirmed, and whose re-read shows a different publication owner (another epoch, a lower one included, or another holder; any owner when its last known HEAD was empty), fences without retrying the CAS. | M4 Cooling → HolderFenced; M5 CAS → Fenced | `core/storage/chunk_head_belt.go` `publicationOwnerChanged`, `fencePublication`; `core/storage/chunk_layer.go` `captureLocked`, `resolvePending`, `SettleDetach` | `TestHeadBeltLowerEpochConflictFencesWithoutCleanup`, `TestHeadBeltEmptyBaseForeignPublicationFences` (`core/storage/chunk_head_belt_test.go`) | — | ACTIVE | +| `INV-WS-HEAD-BELT-FENCE-001` | A publisher whose CAS failed or was not confirmed, and whose re-read shows a publication owner different from its own (another epoch, a lower one included, or another holder), fences without retrying the CAS. With an empty last known HEAD its own owner is its configured epoch and holder. | M4 Cooling → HolderFenced; M5 CAS → Fenced | `core/storage/chunk_head_belt.go` `publicationOwnerChanged`, `fencePublication`; `core/storage/chunk_layer.go` `captureLocked`, `resolvePending`, `SettleDetach` | `TestHeadBeltLowerEpochConflictFencesWithoutCleanup`, `TestHeadBeltEmptyBaseForeignPublicationFences` (`core/storage/chunk_head_belt_test.go`) | — | ACTIVE | | `INV-WS-HEAD-CAS-001` | Every HEAD publish is conditional on `{gen, epoch}` at one serialization point. A conflicting observed owner fences the publisher. Multiple independent filer serialization points are not made atomic by readback. | M4 Holder → Fenced | `core/frontend/chunkstore/chunk_remote.go` `CASHead`; `core/storage/chunk_layer.go` `supersededBy`, `captureLocked` | `TestChunkRemote_TakeoverRefusesOldHolder` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C6_FencedOnTakeover` (`core/storage/chunk_layer_contract_test.go`); `TestIntegration_ConcurrentHEADCASRealFiler` (`core/frontend/chunkstore/concurrent_cas_integration_test.go`) | `WorkspaceTakeover` `NoOldCasAfterTakeover` | ACTIVE | | `INV-WS-HEAD-MONOTONE-001` | HEAD epoch and `RemoteLSN` never decrease. | M4, M5 CAS | `core/frontend/chunkstore/chunk_remote.go` `CASHead`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkRemote_EpochNeverLowers` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestMemChunkRemote_RefusesLowerRemoteLSN` (`core/storage/chunk_layer_lsn_order_test.go`); `TestHEADRefusesLSNRegressionAcrossMove` (`core/frontend/chunkstore/restore_lsn_test.go`); `TestNativeReplacementCutBehindHEADRefuses` (`core/storage/legacy_replacement_v3_test.go`) | `WorkspaceTakeover` `HeadMonotone` | ACTIVE | | `INV-WS-HEAD-KEY-PROVENANCE-001` | Every key a HEAD names is named by its predecessor HEAD or was uploaded by this owner under an intent that rooted it until the CAS settled; a key that left every root is never named again. | M5 Manifest → CAS | `core/storage/chunk_layer.go` `captureLocked`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | — | — | STUB | diff --git a/seaweed-block/internal/invcheck/invariants_test.go b/seaweed-block/internal/invcheck/invariants_test.go index ff82424b08..e07fb23ac4 100644 --- a/seaweed-block/internal/invcheck/invariants_test.go +++ b/seaweed-block/internal/invcheck/invariants_test.go @@ -8,6 +8,7 @@ import ( "fmt" "io/fs" "os" + "os/exec" "path/filepath" "regexp" "strings" @@ -236,4 +237,30 @@ func TestInvariantStatementsAreShort(t *testing.T) { t.Errorf("%s:%d: %s is not a row of invariants.md: delete its line", list, at, id) } } + // The list only shrinks. Its size is pinned here, so a new exception needs + // an edit of this constant, and where the base commit is at hand every + // listed row must already have been listed there. + if len(listed) != longStatementsLeft { + t.Errorf("%s names %d rows, longStatementsLeft is %d: lower the constant when a line is deleted; it is never raised", list, len(listed), longStatementsLeft) + } + base, err := exec.Command("git", "-C", root, "show", "HEAD^1:"+list).Output() + if err != nil { + t.Logf("no base version of %s (%v): the only-shrink comparison is skipped", list, err) + return + } + was := map[string]bool{} + for _, line := range strings.Split(strings.ReplaceAll(string(base), "\r\n", "\n"), "\n") { + if id := strings.TrimSpace(line); id != "" && !strings.HasPrefix(id, "#") { + was[id] = true + } + } + for id, at := range listed { + if !was[id] { + t.Errorf("%s:%d: %s was not listed in the base commit: the list only shrinks", list, at, id) + } + } } + +// longStatementsLeft is the number of rows testdata/long-statements.txt may +// name. It only goes down. +const longStatementsLeft = 28