Files
seaweedfs/seaweed-block/docs/design/map-checkpoint-cost.md
T

4.9 KiB

Map checkpoint cost boundary

Let S be the number of chunks, D the number of changed entry/serialized pages, H the bounded reference-tree height, P the allocated sidecar pages, and R the number of retained candidates.

Format Checkpoint cost Bound and lifetime
Format 1 O(S): the flat reference root is serialized and hashed at each publication At most 256 GiB after create; transient until the first-attach coverage upgrade
Format 2 Capture O(1); validate/compare/copy changed entry paths; serialize changed leaf/index paths; incremental extent pins and O(log P) allocation per new page Metadata work O(D H + D log P + R), independent of unchanged entry count; native full-storage, focused-race and empty-tail stop controls below

Creation retains the existing all-Unknown format1 map: prepare generation 1 at position 0, write the descriptor, then sync. This is O(S) map work once. A store above 256 GiB starts unmarked and empty; every later owned map checkpoint refuses until first attach completes the coverage upgrade. The order remains record pages, both synced/read-back descriptor slots carrying the attach epoch, then the record header. Missing or corrupt map metadata never stands for an empty store. Release creation admission and the lab override are unchanged; there is no marked epoch-zero state or new initial-format path.

The live entry container owns both its flat O(1) read vector and its COW tree. Every mutation updates them together under the existing store lock. Capture freezes an immutable version. Newer writes copy their paths, so publishing a captured root retires only that root's versions; an abandoned candidate retires nothing. The selected durable root is the comparison baseline. Recovery rebuilds this memory representation from validated roots with cancellation/progress preserved.

Physical reference trees share unchanged subtrees. Their node pins propagate only at zero-to-one/one-to-zero transitions. Both valid slots, retained/uncertain candidates and a preparation's acquired prior pin protect extents; fresh reservations remain pinned until the candidate is registered. Opening interns equal slot subtrees and builds the free-page index once. Checkpoints do not rebuild or sort the full live set. Indexed heaps retain at most one entry per page in the open file's allocation high-water. Truncated free indexes are excluded by EOF, without sweeping the whole free table. Legacy growth/truncation synchronizes that high-water before the coverage transition, and append refuses to reuse any pinned page. The same sole descriptor publisher, proof checks, WAL-before-page rule, page hashes and on-disk encodings remain in use.

The eager runtime still loads the complete logical map at open. Its 1 GiB geometry admission charges both always-resident entry representations (flat vector plus COW leaves, about 6 MiB extra per TiB at 4 MiB chunks), plus conservative reference-tree/allocator metadata accounting and can refuse a large geometry earlier. This is a runtime bound, not a disk-format capacity change. Format1's bounded fallback still rebuilds its live-set snapshot.

ChunkMapStatsV3 returns LastCheckpoint and LastStop typed receipts, retained after Close. Checkpoint intervals are disjoint nanoseconds: capture (including lock wait), WAL sync, extent sync, prepare (including sidecar lock wait, validation, reservations and page/root persistence), and descriptor publication. Caller idle time between prepare and publish is excluded. TotalNs is their sum. ComparedEntryPages counts changed immutable entry leaves inspected; WrittenPages counts attempted physical 4 KiB writes. A failed preparation/publication carries its error. A very short phase can measure zero.

Stop records total elapsed time, chunk close, lifecycle wait, final flusher stop, committer stop, sidecar close and file close, including failure. Named stop phases fit within total; unassigned coordination is included only in total. Repeated Close retains the first receipt.

Windows Go1.25.6 metadata controls at 1 TiB: the initial candidate-copy regression fell from 7,164,632 bytes to about 42 KiB; with every reference leaf occupied, one changed page fell from 1,472,960 bytes to about 37 KiB. These are allocation/work controls, not published throughput figures. The native test measures full WALStore.Close on a sparse 1 TiB store with an empty dirty tail; it does not include a holder process or an attached chunk layer's presence serialization. Native Go1.25.14 qualification passed: full storage -short (820 pass, 9 skip), 76 focused tests repeated three times normally and under race (228 pass each), and seven executions of the sparse 1 TiB empty-tail stop bound. This qualifies the store-level control, not a holder process or presence-file serialization.

The owned checkpoint and stop cells are exported in map-checkpoint-resource-grid.tsv; other holder/detach work keeps its separate owner and evidence.