Skip to main content

rebuild_is_chunk_size_invariant

Function rebuild_is_chunk_size_invariant 

pub async fn rebuild_is_chunk_size_invariant<F: ProjectionFixture>(
    open: impl AsyncFn() -> F,
) -> RuleOutcome
Expand description

A rebuild produces the same read model however it is chunked.

PS-13 and PS-14, both [FROZEN]. A rebuild is run at whatever chunk size fits the operator’s memory budget, and an adapter that lets the chunk size change the answer turns “how much RAM did we give it” into a correctness variable nobody logs.

Rejects: CommittedReadBatchStore, whose batch get answers from committed state, and FirstWriteWinsBatchStore, whose batch stages writes with entry().or_insert(…) and keeps the first value for a key — the natural spelling when the batch is thought of as a dedup buffer. Its reads through the batch are honest, so it passes the rule above and fails only this one.

§The sequence, and why each step is a read-modify-write

One fixed sequence — a, a, b, a, b, a — replayed at chunk sizes 1, 3 and whole-log against three isolated stores, one open() per run. Each step reads the key through the batch and writes one more than it saw, so the correct final state is a = 4, b = 2 at every chunking.

A plain set instead of an increment is the trap: last-writer-wins is chunk-insensitive by construction, so a rule written that way passes against a store that cannot read through its own batch and certifies PS-13 and PS-14 on nothing. The sizes are chosen for the same reason — 1 is the degenerate case where pending and committed state coincide and a broken store gets it right, 3 is the smallest size that puts a repeated key both inside one chunk and across a boundary, and whole-log is what a rebuild actually runs at.

§Two things it deliberately does not do

It compares read models, never checkpoints and never positions: the positions it commits at are its own, deliberately non-contiguous so that a later edit growing a position == index + 1 assumption is visible, and strictly increasing so it does not trip PS-22 for a reason that has nothing to do with what it is testing.

And the end-of-run comparison uses probe_read, which is the suite reading committed state after the fact. That is not the out-of-band read PS-13 forbids: the clause constrains what a projection’s apply may read while it is writing, and every read this rule makes on that path goes through the batch.