fix: require layout capabilities before attaching and refuse missing forwards

This commit is contained in:
pingqiu committed 2026-11-29 10:08:47 -08:00
1 parent 09699673c7
commit 1dca8789e4
7 files changed
+81 -19

No files matched your search

@@ -117,8 +117,11 @@ func (l *LayoutRemote) ProbeSnapshots(ctx context.Context) (map[string]struct{},
}
var (
_ storage.ChunkRemote = (*LayoutRemote)(nil)
_ storage.ChunkKeyer = (*LayoutRemote)(nil)
_ storage.ChunkRemote = (*LayoutRemote)(nil)
_ storage.ChunkKeyer = (*LayoutRemote)(nil)
_ storage.ChunkCommitChecker = (*LayoutRemote)(nil)
_ storage.ChunkHeadStepBounder = (*LayoutRemote)(nil)
_ storage.ChunkHeadRootReader = (*LayoutRemote)(nil)
)
// NewLayoutRemote returns the remote of volume v for the holder me (the
@@ -40,6 +40,20 @@ func (r *casObservedRemote) GetHead(ctx context.Context) (storage.ChunkHead, err
return r.ChunkRemote.GetHead(ctx)
}
func (r *casObservedRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) {
r.reads++
if r.onGetHead != nil {
r.onGetHead(r.reads)
}
return r.ChunkRemote.(storage.ChunkHeadRootReader).GetHeadRoot(ctx)
}
func (r *casObservedRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error {
return r.ChunkRemote.(storage.ChunkCommitChecker).CheckCommit(ctx, expected, next)
}
func (r *casObservedRemote) BoundsHeadStep() bool {
return r.ChunkRemote.(storage.ChunkHeadStepBounder).BoundsHeadStep()
}
func (r *casObservedRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) {
r.cass++
gen, err := r.ChunkRemote.CASHead(ctx, expected, next)
@@ -56,9 +56,10 @@ var (
var ErrChunkStaleLocalRoot = errors.New("durable: local volume predates a HEAD published by another holder")
var (
errProviderClosed = errors.New("durable: provider closed")
errChunkForeignClaim = errors.New("durable: HEAD claim refused by another holder")
errChunkNoAuthority = errors.New("durable: projection carries no master authority for the chunk layer")
errProviderClosed = errors.New("durable: provider closed")
errChunkForeignClaim = errors.New("durable: HEAD claim refused by another holder")
errChunkNoAuthority = errors.New("durable: projection carries no master authority for the chunk layer")
errChunkRemoteCapabilities = errors.New("durable: layout remote requires CheckCommit, BoundsHeadStep and GetHeadRoot")
)
const (
@@ -506,6 +507,10 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h
inner, err = p.cfg.ChunkLayoutRemoteFor(volumeID, me)
}
if err == nil {
capabilities, ok := inner.(layoutRemoteCapabilities)
if !ok || !capabilities.BoundsHeadStep() {
return nil, errChunkRemoteCapabilities
}
p.mu.Lock()
h.layoutHolder, h.layoutHead, h.layoutRemote = me, st, inner
p.mu.Unlock()
@@ -595,6 +600,14 @@ func (p *DurableProvider) attachProgress() func(uint64) {
return func(n uint64) { report(storage.RecoveryAttach, done.Add(n)) }
}
// Layout adapters must keep the object's check outside the HEAD step and
// provide an identity-only read. Wrapping must not manufacture these features.
type layoutRemoteCapabilities interface {
storage.ChunkCommitChecker
storage.ChunkHeadStepBounder
storage.ChunkHeadRootReader
}
// closeBoundRemote ends every remote call when the provider closes, so a
// shutdown never waits on the remote for an attach or a cut. While an
// attach runs, its calls also end with the attach caller's context.
@@ -710,7 +723,7 @@ func (r *closeBoundRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead,
if reader, ok := r.ChunkRemote.(storage.ChunkHeadRootReader); ok {
return reader.GetHeadRoot(c)
}
return r.ChunkRemote.GetHead(c)
return storage.ChunkHead{}, fmt.Errorf("%w: GetHeadRoot unavailable", errChunkRemoteCapabilities)
}
func (r *closeBoundRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) {
@@ -720,15 +733,15 @@ func (r *closeBoundRemote) CASHead(ctx context.Context, expected storage.ChunkHe
}
// CheckCommit forwards the commit's object check (storage.ChunkCommitChecker)
// with the same binding as CASHead. A remote without it passes: its CAS then
// runs the check itself.
// with the same binding as CASHead. A remote without it refuses; the
// wrapper must never manufacture a successful object check.
func (r *closeBoundRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error {
c, end := r.bind(ctx)
defer end()
if checker, ok := r.ChunkRemote.(storage.ChunkCommitChecker); ok {
return checker.CheckCommit(c, expected, next)
}
return nil
return fmt.Errorf("%w: CheckCommit unavailable", errChunkRemoteCapabilities)
}
// BoundsHeadStep forwards whether the wrapped remote bounds its own HEAD
@@ -64,6 +64,22 @@ func (g *gatedRemote) hold(ctx context.Context, what string, ch chan struct{}) e
}
func (g *gatedRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) {
return g.getHead(ctx, false)
}
func (g *gatedRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) {
return g.getHead(ctx, true)
}
func (g *gatedRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error {
return g.ChunkRemote.(storage.ChunkCommitChecker).CheckCommit(ctx, expected, next)
}
func (g *gatedRemote) BoundsHeadStep() bool {
return g.ChunkRemote.(storage.ChunkHeadStepBounder).BoundsHeadStep()
}
func (g *gatedRemote) getHead(ctx context.Context, rootOnly bool) (storage.ChunkHead, error) {
read := g.ChunkRemote.GetHead
if rootOnly {
read = g.ChunkRemote.(storage.ChunkHeadRootReader).GetHeadRoot
}
g.mu.Lock()
fail := g.failGetHead > 0
if fail {
@@ -75,14 +91,14 @@ func (g *gatedRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) {
return storage.ChunkHead{}, errors.New("injected GetHead failure")
}
if g.holdAfter {
h, err := g.ChunkRemote.GetHead(ctx)
h, err := read(ctx)
_ = g.hold(ctx, "gethead", ch)
return h, err
}
if err := g.hold(ctx, "gethead", ch); err != nil {
return storage.ChunkHead{}, err
}
return g.ChunkRemote.GetHead(ctx)
return read(ctx)
}
// B Start reads HEAD through StartStore before constructing its content
@@ -28,6 +28,14 @@ type sealProgressRemote struct {
calls int
}
func (r *sealProgressRemote) CheckCommit(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) error {
return r.layoutRemote.CheckCommit(ctx, expected, next)
}
func (r *sealProgressRemote) GetHeadRoot(ctx context.Context) (storage.ChunkHead, error) {
return r.layoutRemote.GetHeadRoot(ctx)
}
func (r *sealProgressRemote) BoundsHeadStep() bool { return r.layoutRemote.BoundsHeadStep() }
func (r *sealProgressRemote) AbortOpenSession(ctx context.Context) (string, error) {
return r.layoutRemote.AbortOpenSession(ctx)
}
@@ -58,7 +58,7 @@ type missingRootRemote struct {
}
func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing.T) {
for _, missing := range []string{"CheckCommit", "BoundsHeadStep", "GetHeadRoot"} {
for _, missing := range []string{"CheckCommit", "BoundsHeadStep", "GetHeadRoot", "complete"} {
t.Run(missing, func(t *testing.T) {
fixture := newKZLayout(t)
cfg := ProviderConfig{Impl: ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 256, BlockSize: 4096, ChunkBlocks: 16,
@@ -73,8 +73,10 @@ func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing.
return &missingCheckRemote{lr, lr, lr, lr}, nil
case "BoundsHeadStep":
return &missingBoundRemote{lr, lr, lr, lr}, nil
default:
case "GetHeadRoot":
return &missingRootRemote{lr, lr, lr, lr}, nil
default:
return lr, nil
}
},
}
@@ -86,12 +88,17 @@ func TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart(t *testing.
if _, err := p.EnsureStorage("v1"); err != nil {
t.Fatal(err)
}
if _, err := p.RecoverVolume(context.Background(), "v1"); err == nil {
t.Fatalf("layout remote missing %s was accepted at startup", missing)
_, err = p.RecoverVolume(context.Background(), "v1")
if missing == "complete" {
if err != nil {
t.Fatalf("complete layout remote refused: %v", err)
}
} else if !errors.Is(err, errChunkRemoteCapabilities) {
t.Fatalf("missing %s: want capability refusal, got %v", missing, err)
}
for _, s := range p.DurableStatuses() {
if s.Operational {
t.Fatal("unsupported layout remote served")
if s.Operational != (missing == "complete") {
t.Fatalf("%s operational=%v", missing, s.Operational)
}
}
})
+3 -2
View File
@@ -66,7 +66,7 @@ stateDiagram-v2
| — | CreateRefused | a new volume needs the durable root's free space >= its size + WAL, checked before the store, its WAL or its fresh marker is created (the replica floor, written when the assignment arrives, precedes the check and stays); the refusal ends the process with status 1; an existing volume opens and warns when its remaining data growth + WAL exceed the free space | `core/frontend/durable/headroom.go`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-LOCAL-HEADROOM-001` |
| — | CreateRefused | a chunk volume in create mode (no local store yet): before the provider is built, the geometry flags are compared with the volume record; they disagree, or the record is there but does not decode: exit 78; the filer failed the read: exit 75; nothing is created; an absent record keeps the create path; an existing store is never rechecked against the flags | `cmd/blockvolume/main.go` (create-mode check); `cmd/blockvolume/chunk_remote.go` `geometryFlagsRefusal` | `INV-VOL-GEOMETRY-FLAGS-RECORD-001` |
| Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001`, `INV-RECOVERY-PROGRESS-WINDOW-001` |
| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason); a workspace primary claims HEAD, listens and reports ready only while its lease guard permits now (`WorkspaceLeaseGuard.Held`; without a grant: `NotReadyReason=lease_not_held`, exit 75 after the start-time wait); a primary of a replicated line serves only when its own `--replication-ack` is the profile its assignment names (otherwise not Healthy, `NotReadyReason` naming both profiles, ahead of the backend's own refusal) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection`; `core/host/volume/workspace_lease.go` `Held`; `core/host/volume/workspace_startup.go` `noteAckProfile` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001`, `INV-PRIMARY-ACK-PROFILE-001` |
| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end; the frontend targets start, and `FrontendPrimaryReady` is reported, only once the backend admits I/O (a chunk volume: after its storage claim; attach-pending or fenced reports not ready with the reason); a workspace primary claims HEAD, listens and reports ready only while its lease guard permits now (`WorkspaceLeaseGuard.Held`; without a grant: `NotReadyReason=lease_not_held`, exit 75 after the start-time wait); a primary of a replicated line serves only when its own `--replication-ack` is the profile its assignment names (otherwise not Healthy, `NotReadyReason` naming both profiles, ahead of the backend's own refusal) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover`; `cmd/blockvolume/frontend_gate.go` `awaitFrontendStart`; `core/frontend/durable/storage_adapter.go` `FirstServing`; `core/host/volume/status_server.go` `statusProjection`; `core/host/volume/workspace_lease.go` `Held`; `core/host/volume/workspace_startup.go` `noteAckProfile` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001`, `INV-WAL-V3-W-RECOVERY-001`, `INV-WAL-V3-FENCE-001`, `INV-WAL-V3-MAP-PUBLISH-001`, `INV-FE-PRIMARY-READY-OPERATIONAL-001`, `INV-WS-SERVE-LEASE-HELD-001`, `INV-PRIMARY-ACK-PROFILE-001`, `INV-LAYOUT-REMOTE-CAPABILITIES-001` |
| Recovering | RecoveryFailed | a WAL integrity failure or an I/O error; the backend stays not operational and the host blocks local readiness with `wal_corrupt` or `io_error` | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `INV-WAL-TYPED-FAILCLOSED-001`, `INV-WAL-OPGATE-001`, `INV-WAL-V3-W-RECOVERY-001` |
| Serving | Serving | each `Read`, `Write`, `Sync` passes the operational, chunk-fence and lineage checks; write admission samples the active writer's native pressure before waiting; a write is durable only when a covering `Sync` returns | `core/frontend/durable/storage_adapter.go` `gate`; `core/storage/walstore.go` `WALStore.Sync` | `INV-FE-LINEAGE-GATE-001`, `INV-WAL-SYNC-FRONTIER-001`, `INV-FE-FUA-SYNC-001`, `INV-FE-FLUSH-SYNC-001`, `INV-WAL-V3-ADMISSION-001`, `INV-WAL-V3-W-001` |
| Serving | Serving (checkpoint) | the flusher binds its snapshot/materialization to one recovery lifetime; extent and owned COW map are durable before the shared descriptor publisher advances checkpoint/tail; both slot tails pin reuse | `core/storage/flusher.go` `flushOnceInternal`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `INV-WAL-CHECKPOINT-SNAPSHOT-001`, `INV-WAL-REUSE-PERSISTED-TAIL-001`, `INV-WAL-CKPT-META-FAIL-001`, `INV-CUT-BITMAP-001`, `INV-WAL-FLUSH-SYNC-COVERS-WAL-001`, `INV-WAL-V3-RECLAIM-001`, `INV-WAL-V3-PUBLISH-NONCE-FLOOR-001`, `INV-WAL-V3-MAP-PRIOR-LIVE-001` |
@@ -900,6 +900,7 @@ Notes:
| `INV-CUT-QUIESCED-001` | HEAD is exactly the image at a quiesced cut H, and H is a synced LSN. | M5 Quiesce → Copy → CAS | `core/storage/chunk_layer.go` `captureLocked` | `TestChunkLayer_C1_HeadIsQuiescedCutImage`, `TestChunkLayer_C3_EveryHeadIsExactUnderConcurrentWrites` (`core/storage/chunk_layer_contract_test.go`) | `CutPipeline` `HeadImage`; `CutCapture` `HeadImage` | ACTIVE |
| `INV-CUT-BIRTH-001` | Retired: B does not store per-chunk BirthLSN; `INV-SNAPK-COMMIT-REACH-001` protects the published object graph, and the surviving barrier-image test protects the cut image. | legacy M5 | — | — | — | ARCHIVED |
| `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window. | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy` (`core/storage/chunk_cut_progress_test.go`); `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`); `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied` (`core/storage/chunk_layer_precopy_test.go`); `TestNativeReplacementRecoverInvalidatesStagedImage` (`core/storage/legacy_replacement_v3_test.go`); `TestChunkStageV3_MidUploadAbortReducesRetryBytes` (`core/storage/chunk_abort_upload_bytes_test.go`); `TestCutRevokedMidUploadKeepsItsUploads` (`core/storage/chunk_cut_revoke_reuse_test.go`) | `CutPipeline` `HeadImage` | ACTIVE |
| `INV-LAYOUT-REMOTE-CAPABILITIES-001` | A provider attaches only a layout remote with commit checking, a bounded HEAD step and identity-only HEAD reads. Its wrapper refuses missing check/read capabilities and never substitutes a full manifest read or a successful check. | M1 attach; M5 object check and HEAD confirmation | `LayoutRemote` compile-time assertions; `DurableProvider.newChunkLayer`; `closeBoundRemote` | `TestCloseBoundRemoteRefusesMissingCapabilities`, `TestProviderRefusesLayoutRemoteMissingRequiredCapabilityAtStart`, `TestCloseBoundRemoteForwardsCapabilitiesAndClose` (`core/frontend/durable/remote_capabilities_test.go`) | existing adapter contract (no state or transition change) | ACTIVE |
| `INV-CUT-RETRY-FAIRNESS-001` | New staging retries without backoff; zero progress backs off. Dirty-start cleaning waits for a completed store attempt or one maintenance interval. K=3 admitted stalled background attempts yield reusable staging, never a pending or active/newer cut. | M5 Stage, M6 Clean (CUT-BUDGET B1/B3) | `core/frontend/durable/provider_chunk.go`; `core/frontend/durable/chunk_snapshot_schedule.go`; `core/storage/chunk_periodic_cut.go` | `TestCutLoopProgressRetriesWithoutBackoff`, `TestScheduledSnapshotProgressRetriesWithoutBackoff`, `TestDirtyStartCleaningWaitsForFirstCutAttempt`, `TestDirtyStartCaptureRefusalsDoNotReleaseCleaning`, `TestStalledCutYieldsSessionToCleaning` (`core/frontend/durable/cut_progress_test.go`); `TestDiscardStagedRechecksCaptureState` (`core/storage/chunk_stalled_discard_test.go`); `TestLayoutStalledSessionYieldAllowsCleaning` (`core/frontend/chunkstore/layout_stalled_discard_test.go`) | `CommitReach` `CBegin` (existing session exclusion; scheduling only) | ACTIVE |
| `INV-CUT-STAGED-COUNT-001` | `Stats.StagedChunks` counts each chunk staging finished (remembered for reuse) in every cut attempt, an interrupted round included, and only grows; a re-staged chunk counts again; it is in-process. A cut's `PayloadNs` includes its staging rounds whether or not they uploaded. | M5 Stage (before the barrier) | `core/storage/chunk_cut_payload.go` `rememberPayload`, `streamCutPayloads`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkStage_StagedChunksCountsFailedAttempts`, `TestChunkStage_StagedChunksCountsAnInterruptedRound`, `TestChunkStage_PayloadTimeCountsStagingWithoutUploads` (`core/storage/chunk_stage_accounting_test.go`) | — | ACTIVE |
| `INV-CUT-BITMAP-001` | The owned map never under-reports: its checkpoint coverage is durable before WAL recycling; UNKNOWN is cleared only after definite HEAD publication (a cut, or a fresh store's claim: `INV-CUT-FRESH-KNOWN-ZERO-001`) and an unchanged capture token. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `core/storage/chunk_layer_map_v3.go` `persistCapturedMapV3` | `TestWALStoreV3_AutomaticMapCheckpoint` (`core/storage/walstore_map_checkpoint_v3_test.go`); `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN` (`core/storage/chunk_layer_map_v3_test.go`) | `CutCapture` `HeadImage` | ACTIVE |
@@ -1300,4 +1301,4 @@ replay, reclaim indexing, attach. Counts are cumulative within each phase across
same-process retries; a repeated or earlier frontier is not progress. Late
progress cannot clear an already elapsed inactivity window. The existing
same-epoch promotion-ready fact alone clears the timeout latch. C.L's start
rows remain STUB until recovery and attach controls are qualified together.
rows remain STUB until recovery and attach controls are qualified together.