From c7f7f016e9c9b054bc03b6a6bd82c04f7dfea7c0 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 2 Dec 2026 02:35:28 -0800 Subject: [PATCH] master: the grant reads the holder process's own report The publication boundary checks the (server, volume) entry of the process that will serve the volume, never the server's lowest level over its other processes: a sibling's report says nothing about this process's binary. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/host/master/format_gate.go | 29 ++++++++++++++++++ .../master/format_level_new_cluster_test.go | 30 +++++++++++++++++++ .../core/host/master/workspace_binding.go | 2 +- seaweed-block/docs/design/invariants.md | 2 +- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/host/master/format_gate.go b/seaweed-block/core/host/master/format_gate.go index 6d43fdfccb..26d097f843 100644 --- a/seaweed-block/core/host/master/format_gate.go +++ b/seaweed-block/core/host/master/format_gate.go @@ -73,6 +73,15 @@ func (r *readsLevels) liveLocked(server string, served map[string]bool) map[stri return r.procs[server] } +// entry is the level the process holding volume on server reported, and +// whether it reported one (a live entry): the holder's own report. +func (r *readsLevels) entry(server, volume string, served map[string]bool) (uint32, bool) { + r.mu.Lock() + defer r.mu.Unlock() + e, ok := r.liveLocked(server, served)[volume] + return e.level, ok +} + // of is the lowest level of server's live entries, and whether it has any. func (r *readsLevels) of(server string, served map[string]bool) (uint32, bool) { r.mu.Lock() @@ -190,6 +199,26 @@ func (h *Host) formatRefusal(prefix, server string) error { return lifecycleclient.WithReason(status.New(codes.FailedPrecondition, prefix+why), lifecycleclient.ReasonBinaryTooOld).Err() } +// grantTooOld names why the process that will serve volume on server may not +// be granted its line, or "" when it may: the grant reads that process's own +// report (the (server, volume) entry), never a sibling process's, since +// with one process per volume a sibling's report says nothing about this +// one's binary. No report means no grant; a lower one is binary_too_old. +func (h *Host) grantTooOld(server, volume string) string { + level := h.formatLevel() + if level == 0 { + return "" + } + reads, ok := h.reads.entry(server, volume, h.servedBy(server)) + if !ok { + return fmt.Sprintf("node %q has not reported the format read level of its process for volume %q; the cluster's format level is %d (no grant before that process's report)", server, volume, level) + } + if reads < level { + return fmt.Sprintf("node %q's process for volume %q reads format level %d; the cluster's format level is %d (binary_too_old)", server, volume, reads, level) + } + return "" +} + // formatTooOld names why server is not format-eligible, or "" when it is. func (h *Host) formatTooOld(server string) string { if h.formatEligible(server) { diff --git a/seaweed-block/core/host/master/format_level_new_cluster_test.go b/seaweed-block/core/host/master/format_level_new_cluster_test.go index bc7c01d726..74b46e391a 100644 --- a/seaweed-block/core/host/master/format_level_new_cluster_test.go +++ b/seaweed-block/core/host/master/format_level_new_cluster_test.go @@ -142,3 +142,33 @@ func TestAnEmptyAuthorityStoreOverAnExistingInventoryStartsAtLevel0(t *testing.T t.Fatalf("the master wrote an attestation file over an existing inventory: %v", err) } } + +// The grant reads the holder's own report: on a server whose process for +// volume u reported level 1, a new process for volume v that has not +// reported yet is not granted v's line; once v's own process reports level +// 1 it is (a sibling's report says nothing about this process's binary). +func TestTheGrantReadsTheHoldersOwnReportNotASiblings(t *testing.T) { + r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r.createVolume(t, "u") + r.createVolume(t, "v") + r.place(t, "u", "node-b") + r.place(t, "v", "node-b") + if err := r.fgProcessHeartbeat("node-b", "proc-u", "u", 1); err != nil { + t.Fatal(err) + } + grant := func() (bool, error) { + published := false + err := r.m.admitWorkspacePublication(authority.AssignmentAsk{VolumeID: "v", ReplicaID: "r1", DataAddr: "127.0.0.1:19331", CtrlAddr: "127.0.0.1:19332", Intent: authority.IntentBind}, + func() error { published = true; return nil }) + return published, err + } + if published, err := grant(); err == nil || published { + t.Fatalf("v's grant on u's report only: err %v, published %v; want no grant", err, published) + } + if err := r.fgProcessHeartbeat("node-b", "proc-v", "v", 1); err != nil { + t.Fatal(err) + } + if published, err := grant(); err != nil || !published { + t.Fatalf("v's grant after v's own report: err %v, published %v; want granted", err, published) + } +} diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 7838b3e4fa..f9cf828ffe 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -290,7 +290,7 @@ func (h *Host) admitWorkspacePublicationNow(ask authority.AssignmentAsk, publish // means no grant (the ask waits for it), and an ask decided on // observations taken before its server reported a lower level is not // published. - if why := h.formatTooOld(server); why != "" { + if why := h.grantTooOld(server, ask.VolumeID); why != "" { return fmt.Errorf("workspace publication: %s", why) } b := lifecycle.WorkspaceBinding{VolumeID: ask.VolumeID, ServerID: server, DataAddr: ask.DataAddr, CtrlAddr: ask.CtrlAddr} diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 1fe6d4b00d..43bf79f4ca 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -654,7 +654,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-CHUNK-RECORD-SHADOW-001` | While serving, the chunk record follows the engine's events via the kernel; an event bound to a captured version is skipped, never refused, after a write; at each barrier every chunk the engine captures is a record candidate. It decides nothing; on v1.0 it writes no page. | M3 Serving (chunk record shadow) | `core/storage/chunk_record_shadow.go` `newChunkRecordShadow`, `chunkRecordShadow.check`; `core/storage/chunk_layer.go` `noteMutation`, `fillOnce`, `EvictChunk`, `recoveredLocked`, `BeforeCheckpointAdvance`, `shadowCommit`, `shadowCommitCaptured` (also from `resolvePending`, `SettleDetach`); `core/storage/chunk_cut_payload.go` `markEqualNow`; `core/storage/chunk_record_runtime.go` `ApplyIf` | `TestShadowWriteCoverageFollowsTheStoreBitmap`, `TestShadowFillRacedByAWriteEndsUnknown`, `TestShadowCutOfAPartialChunkKeepsItPartial`, `TestShadowCommitAfterAChunkLandedSinceItsScratchCaptureIsSkipped`, `TestShadowExtentWritesLandAnAbsentChunkOnlyOnV10`, `TestShadowAttachKeepsACheckpointedWriteACandidate`, `TestShadowWriteRacingHashAndCommitIsSkippedNotRefused`, `TestShadowEvictEdges`, `TestShadowRecordWritesNoPage`, `TestShadowCheckerIsExactAndCatchesAMissingWrite`, `TestShadowRecoverChangesOnlyTheRecoveredChunks`, `TestShadowBaseInstallCompletingChangesEveryChunk`, `TestShadowDelayedSettlementCommitsTheCapturedChunks`, `TestShadowProductionCheckDoesNotScanTheRecord`, `TestShadowScratchExemptionIsBoundToItsCapturedVersion` (`core/storage/chunk_record_shadow_test.go`); every test of the package runs with the shadow strict, misses and extra record candidates both (`TestMain`, `core/storage/chunk_record_shadow_main_test.go`) | chunk-kernel/2 (the per-chunk state models are not in this repository) | ACTIVE | | `INV-CHUNK-RECORD-V11-001` | On the draft v1.1 format a layer upgrades its store once at attach and opens from its record; a fill's page claims no local block before one durable mark (partial fills and later writes too); an evict clears the store's bits only after its absent page is durable, retries too. | M1 Opened, M3 Serving (draft v1.1 format) | `core/storage/chunk_record_open.go` `openChunkRecordV11`, `loadChunkRecordV11`, `markFills`; `core/storage/chunk_record_upgrade.go` `upgradeChunkRecordWith`; `core/storage/chunk_record_runtime.go` `holdFills`, `PersistSegmentOf`; `core/storage/chunk_record_shadow.go` `evict`; `core/storage/chunk_layer.go` `EvictChunk`, `Close` | `TestV11AttachUpgradesTheStoreOnce`, `TestV11ReopenJudgesAWriteAfterThePageAsChanged`, `TestV11CleanStopWritesOnlyTheDirtyPages`, `TestV11UpgradeRecoversFromACrashAtEachStep`, `TestV11DamagedPageIsRebuiltFromTheStoreBits`, `TestV11FillsAreMarkedInOneBatchBeforeTheirPagesClaimThem`, `TestV11EvictSurvivesARestart` (`core/storage/chunk_record_v11_test.go`); `TestV11CloseDuringTheUpgradeRefusesTheAttach`, `TestV11EvictWithoutItsAbsentPageClearsNothing`, `TestV11ParkedFillBatchCannotOverwriteAnEvict`, `TestV11MalformedLeftoverPresenceDoesNotRefuseTheAttach`, `TestV11FinalPageFailureIsTheCloseResult` (`core/storage/chunk_record_v11_review_test.go`); `TestV11PartialFillWaitsForTheDurableMark`, `TestV11WriteAfterAHeldFillKeepsTheHold`, `TestV11EvictRetryStillWritesItsAbsentPage` (`core/storage/chunk_record_v11_hold_test.go`); `TestV11AbsentChunkSurvivesALostHeader`, `TestV11LogOnlyWriteSurvivesTheUpgrade` (`core/storage/chunk_record_v11_upgrade_test.go`) | chunk-kernel/2; CoverageDurable row 199 (the WAL is durable through a published position) (not in this repository) | DORMANT | | `INV-CHUNK-FORMAT-LEVEL-001` | An attach raises a volume to v1.1 only at the assigned format level 1 (absent = 0); at level 0 it runs v1.1 only over a version-1 HEAD (reported), refuses a v1.1 store over a version-0 HEAD, and a v1.1 attach refuses a remote without the HEAD format. | M-format gate (holder) | `core/storage/chunk_v11_format.go` `attachLevelV11`, `levelZeroFormat`; `core/storage/chunk_layer.go` `attachChunkLayerImpl`; `core/frontend/chunkstore/layout/format_level.go` `checkFormatLevel` (in `runTransition`); `core/frontend/chunkstore/layout_remote.go` `SetHeadFormat`, `HeadV11`; `core/host/volume/host.go` `applyFact`; `core/frontend/durable/provider_chunk.go` `attachFormatLevel` | `TestAttachFormatFollowsTheAssignedLevel`, `TestAttachAtLevelZeroOfAnUpgradedStore`, `TestAttachAtLevelZeroOfAV11HeadOverAnUnmarkedStore`, `TestAV11AttachRefusesARemoteWithoutTheHeadFormat`, `TestALevelOneCrashBeforeTheFirstCutReattachesAsV11`, `TestAV11AttachRefusesARemoteThatDeclinesTheHeadFormat` (`core/storage/chunk_format_level_test.go`); `TestLayoutRemoteHeadFormatFollowsItsLayer`, `TestALevelZeroCommitCannotRaiseHeadToVersionOne` (`core/frontend/chunkstore/layout_manifest_size_test.go`); `TestNoHeadWriteRaisesTheVersionBelowFormatLevelOne` (`core/frontend/chunkstore/layout/format_level_test.go`); `TestTheWrappedRemoteForwardsTheHeadFormatBothWays`, `TestAttachFormatLevelFromTheAssignment` (`core/frontend/durable/format_level_test.go`); `TestTheAssignedLevelDecidesTheStoredHeadAcrossARestart` (`core/frontend/durable/format_level_layout_test.go`); `TestTheSelfAssignmentsFormatLevelReachesTheProjection` (`core/host/volume/format_level_test.go`) | none | ACTIVE | -| `INV-MASTER-FORMAT-LEVEL-001` | A master whose stores (authority, attestations, lifecycle) are all empty starts at format level 1, written before it serves; existing state keeps its level; above level 0 placement refuses only a known-old host and a grant needs the holder's own report. | M-format gate (master) | `core/host/master/host.go` `New`; `core/host/master/store_attestation.go` `newClusterAtStart`; `core/host/master/format_gate.go` `FormatLevel`, `awaitingFirstReport`, `formatRefusal`; `core/host/master/observation_snapshot.go` `ObservationSnapshot` | `TestOnlyANewClusterStartsAtLevelOne`, `TestANewClusterStartsAtTheCurrentFormatLevel`, `TestANewClusterPlacesAnUnreportedNodeAndGrantsAfterItsReport`, `TestAnEmptyAuthorityStoreOverAnExistingInventoryStartsAtLevel0` (`core/host/master/format_level_new_cluster_test.go`); `TestFormatLevelIsAViewersRead`, `TestANewClustersFailedLevelWriteReleasesTheStore` (`core/host/master/format_level_auth_test.go`); `TestClusterFormatLevel` (`cmd/sw-block/cluster_format_test.go`) | none | ACTIVE | +| `INV-MASTER-FORMAT-LEVEL-001` | A master whose stores (authority, attestations, lifecycle) are all empty starts at format level 1, written before it serves; existing state keeps its level; above level 0 placement refuses only a known-old host and a grant needs the holder process's own report. | M-format gate (master) | `core/host/master/host.go` `New`; `core/host/master/store_attestation.go` `newClusterAtStart`; `core/host/master/format_gate.go` `FormatLevel`, `awaitingFirstReport`, `formatRefusal`; `core/host/master/observation_snapshot.go` `ObservationSnapshot` | `TestOnlyANewClusterStartsAtLevelOne`, `TestANewClusterStartsAtTheCurrentFormatLevel`, `TestANewClusterPlacesAnUnreportedNodeAndGrantsAfterItsReport`, `TestAnEmptyAuthorityStoreOverAnExistingInventoryStartsAtLevel0`, `TestTheGrantReadsTheHoldersOwnReportNotASiblings` (`core/host/master/format_level_new_cluster_test.go`); `TestFormatLevelIsAViewersRead`, `TestANewClustersFailedLevelWriteReleasesTheStore` (`core/host/master/format_level_auth_test.go`); `TestClusterFormatLevel` (`cmd/sw-block/cluster_format_test.go`) | none | ACTIVE | | `INV-CHUNK-FOREIGN-ROOT-FENCE-001` | A HEAD that moved past the holder's base without superseding it and is not its own proposal must keep the chunk root; one that changed it fences the layer (`errChunkForeignRoot`), so no chunk is held clean against a root that no longer names it. | M5 Commit (head conflict, settlement) | `core/storage/chunk_layer.go` `adoptHeadLocked` (from `captureLocked`, `SettleDetach`, `resolvePending`) | `TestShadowForeignRootWithoutSupersedeFences` (`core/storage/chunk_record_shadow_test.go`) | HeadWriters (only metadata writers move HEAD without superseding; not in this repository) | ACTIVE | | `INV-CHUNK-RECORD-PAYLOAD-001` | Persisting and loading a chunk record preserves every entry's state and hash, including entries on either side of a segment boundary. | M1 chunk record codec (caller not wired) | `core/storage/chunk_record.go` `encodeChunkRecordPage`, `decodeChunkRecordPage` | `TestRecordEntryPayloadRoundTripsAcrossSegments` (`core/storage/chunk_record_test.go`; state-zero and one-entry hash-drop controls) | Encoding fidelity; no state transition change | STUB | | `INV-CHUNK-COVERAGE-INIT-POSITION-001` | Coverage initialization rechecks the captured append position under the final store lock before publishing a fence or replacing live entries; a changed position refuses the candidate. | M1 coverage initialization | `core/storage/chunk_coverage.go` `InitializeChunkCoverage` | `TestChunkCoverageInitializationRefusesAnAppendDuringPagePreparation`, `TestChunkCoverageInitializationCaptureBarrierExcludesPublicWrites` (`core/storage/chunk_coverage_initialization_append_test.go`) | SlotFence.Publish; capture barrier remains the public-write exclusion | ACTIVE |