docs: bind cut payload limits to the resource regressions

This commit is contained in:
pingqiu committed 2026-11-19 20:16:34 -08:00
1 parent 3b506620ff
commit ae8faa3fcb
2 files changed
+5 -4

No files matched your search

@@ -153,7 +153,7 @@ Per volume, under the chunk base directory in the filer (`core/frontend/chunksto
- `pending`: become the owner (`saving`), read the chunk (still its content at H), put it in the side store, mark `saved`, wake waiters, proceed;
- `copying` or `saving`: wait (step 2), then re-check.
- **Batches across chunks** (`WriteBatch`; public `ApplyEntry` accepts one block): visit the batch's chunks in ascending chunk index and finish each chunk's step (wait, or save) before the next; no chunk is held while waiting on another, so batches cannot deadlock with each other or with the copier, which owns one chunk at a time. The batch publishes only after all its chunks are `saved`, `done` or outside D.
4. **Copier**, outside the barrier and parallel: for each chunk of D, become the owner (`copying`) or find `saved`; read the live chunk (or the saved bytes) into the cut's immutable buffer, hash it, mark `done`, wake waiters. When every chunk of D is `done`, the window closes: no mutation runs the COW step any more. Upload, manifest and CAS are unchanged (steps 5–11) and work from the buffers, so an unknown CAS outcome keeps today's semantics (proposal pending, intents kept); it does not need the side store.
4. **Copier**, outside the barrier: copy local at-H bytes into a capped private local payload file and retain metadata. When all local copies finish the window closes; pinned-HEAD fills and uploads run afterward, with bounded buffers and no guest COW owner held. Intent, manifest, CAS and unknown-outcome rules are unchanged.
5. **Terminal states: closed, or aborted.** The window ends exactly once, either closed (step 4) or aborted. Abort is taken on a save error (side store full or an I/O error), cut cancellation, fencing, and before `Recover`, a reset or `Close` in the same open. Abort happens **before** the mutation that hit the error proceeds: the cut is marked failed (retryable, `finishCut` does not run, so the dirty set keeps every candidate and the next cut takes them again), all waiters are woken and proceed without saving, and the copier stops. A guest write is never refused because of a cut problem. `Recover`, a reset and `Close` wait for the abort to finish and join every outstanding owner and reader (step 6) before they take their own locks.
6. **Side store and drain.** Local and per cut: memory up to a bound, then a file in the volume's local root; at most |D| × 4 MiB, in practice the chunks written during the window. Every saving or copying owner holds a window reference from its state claim until all of its live-chunk reads and side-store I/O finish; every additional saved-buffer or side-store reader holds a reference too. Abort atomically invalidates the cut and wakes waiters without waiting for its caller's own reference. Owners release their references on every success and error path; an owner that initiates an abort releases its own reference before any join. `Recover`, a reset and `Close` join all outstanding owners and readers before their destructive transition. The side store is deleted exactly once, after the window is closed or aborted **and** no reference is outstanding; no later state claim or I/O may acquire a reference to that terminal window. Recovery never reads it: after a crash the cut is gone, HEAD is unchanged, and the dirty set is rebuilt from the owned map and the WAL. A locked RW open discards only regular files with this volume's reserved `.cut-cow-` prefix; it never reads their contents.
7. **Reads go through the store's read path as the format-v3 work defines it** (the stable, validated reader), both for the save and for the copier; COW adds no flusher hook and no raw extent read. The flusher moves WAL content to the extent without changing what a read returns, so saving at the flusher would miss writes still in the WAL.
@@ -163,7 +163,7 @@ Per volume, under the chunk base directory in the filer (`core/frontend/chunksto
**Alternatives.** Holding the flusher for candidate chunks (reading the at-H content back from the extent and WAL entries up to H) needs no side store, but the WAL cannot be released for those chunks during the window, and a long upload fills it. Raising `BarrierBound` staging does not bound the stall when writes keep re-dirtying staged chunks. Redirect-on-write at the extent changes the on-disk layout and is out of scope for the current format work.
**Implementation and lifetime.** `chunk_cut_cow.go` owns the window, single-owner chunk claims and reference drain; the write hook runs before lifecycle/admission/store locks. Copier workers use the configured upload concurrency (default 8). Side payload retains at most 64 MiB in RAM, then spills to an ephemeral file beside the volume, in checked compact candidate slots. This is not an RSS cap: immutable upload buffers and transient owner reads remain additional memory. Side I/O failures abort the cut, not the guest write. Cleanup failures fail the cut diagnostically; side files are never durable evidence.
**Implementation and lifetime.** `chunk_cut_cow.go` owns window claims and drain; `chunk_cut_payload.go` owns immutable local payloads through joined uploads. Copy, upload and active saver slots reserve payload bytes before admission; cached saves use only the remainder of the 64 MiB default budget. Larger chunks have an explicit geometry-dependent minimum. Pre-copy uses the same local-file path. Local payloads and saver spills share the configured disk cap; exhaustion aborts the cut before publication. No remote wait retains the local window. Locked RW open discards regular files under the reserved `.cut-cow-` prefix; recovery never imports their contents.
Store Close permanently closes attachment admission and captures hooks under captureMu, releases it, then aborts/joins the layer before closing storage. Every Close caller shares completion/result. Recover/reset acquire a window-admission lease and join owners before lower store locks; hook snapshot recheck includes racing first attachment. BASE begin/complete drain the whole cut through capMu. Resume is excluded by BaseInstalling state, not by capMu. A completed install handle's ApplyInstallEntry uses the same pre-publication hook as ordinary ApplyEntry.
+3 -2
View File
@@ -211,9 +211,10 @@ stateDiagram-v2
|---|---|---|---|
| Admit | not closed, fenced, detached or installing a base; `CaptureAllowed` (healthy primary, unchanged lineage, valid lease); no cut while reconciling | `core/storage/chunk_layer.go` `admit`, `captureLocked`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` (`CaptureAllowed`) | `INV-CUT-RECONCILING-001`, `INV-WS-LEASE-001` |
| Settle pending | an earlier unknown CAS is resolved by re-reading HEAD before any new proposal | `core/storage/chunk_layer.go` `resolvePending` | `INV-WS-CAS-UNKNOWN-001` |
| Stage | while more than the barrier bound would be copied, pre-copy outside the barrier; new keys are covered by an intent first | `core/storage/chunk_layer.go` `stage` | `INV-CUT-INTENT-FIRST-001`, `INV-CUT-STAGED-REUSE-001` |
| Stage | while more than the barrier bound would be copied, pre-copy outside the barrier; new keys are covered by an intent first | `core/storage/chunk_layer.go` `stage` | `INV-CUT-PAYLOAD-BOUNDED-001` | Cut payload slots and cached saves have a byte bound independent of candidate count. Pre-copy and native at-H copies retain metadata and capped local files; the local COW window drains before remote waits, and uploads join before file cleanup. | M5 Stage / Copy / Upload | `chunk_cut_payload.go`; `chunk_cut_cow.go`; `chunk_upload.go` | `TestWALStoreChunk_InitialWriteAnonymousMemory` (isolated Linux RSS arms, `core/frontend/durable/provider_initial_memory_linux_test.go`); `TestCutCOWV3_SharedPayloadCapRefusesBeforePublication`, `TestCutCOWV3_RemoteUploadStartsAfterWindowCloses` (`core/storage/chunk_cut_cow_spillcap_test.go`) | Not modelled: byte counts and filesystem/transport resource costs | ACTIVE |
| `INV-CUT-INTENT-FIRST-001`, `INV-CUT-STAGED-REUSE-001` |
| Quiesce | the capture barrier (`captureMu`) is held exclusively, then `Sync` fixes H; `Recover` and writes hold the barrier shared | `core/storage/chunk_layer.go` `captureLocked`; `core/storage/walstore.go` `WALStore.Recover`, `WALStore.Write` | `INV-CUT-QUIESCED-001`, `INV-CUT-RECOVER-BARRIER-001` |
| Copy | every candidate chunk (native owned LSN map relative to HEAD plus retained WAL/in-memory dirt; legacy bitmap/hash mode) is read into buffers; a staged copy is reused only if unchanged since staging; native copy occurs after barrier release with pre-publication COW ownership | `core/storage/chunk_layer.go` `captureLocked` | `INV-CUT-QUIESCED-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-BITMAP-001` |
| Copy | every candidate chunk (native owned LSN map relative to HEAD plus retained WAL/in-memory dirt; legacy bitmap/hash mode) is copied into capped private local payload storage; a staged copy is reused only if unchanged since staging; native copy occurs after barrier release with pre-publication COW ownership | `core/storage/chunk_layer.go` `captureLocked` | `INV-CUT-QUIESCED-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-BITMAP-001` |
| LSN guard | refuse when H is below HEAD's `RemoteLSN` (`lsn_behind`) | `core/storage/chunk_layer.go` `captureLocked` | `INV-WS-HEAD-MONOTONE-001` |
| Upload | upload only chunks whose SHA-256 differs from HEAD, under fresh write-once keys, after a durable intent names them | `core/storage/chunk_layer.go` `captureLocked`; `core/frontend/chunkstore/chunk_remote.go` `putObject` | `INV-CUT-INTENT-FIRST-001`, `INV-CHUNK-WRITE-ONCE-001` |
| Manifest | rewrite only segments whose references changed; new segments are covered by an intent | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `INV-CUT-SEGMENT-REUSE-001`, `INV-CUT-INTENT-FIRST-001` |