Expand description
CRC32C helpers used by both the page-0 header and the page trailer.
The choice of CRC32C (Castagnoli) is fixed at format-major 0; see
docs/format.md § Checksum algorithm for the rationale. This
module is the only place that calls into the crc32c crate so the
algorithm can be revisited in one edit.
§Trailer formats
Two trailer interpretations live side by side:
- v0 (
write_page_trailer/page_trailer_valid) — the full 32-bit CRC32C of bytes[0..PAGE_SIZE - PAGE_TRAILER_SIZE]. Used by every non-header page in aformat_minor = 0file, and by the in-memory representation of every page in every file (the pager re-stamps the on-disk trailer onwrite_back_page). - v1 (
write_page_trailer_v1/page_trailer_valid_v1/page_trailer_flag_v1) — bit 31 of the trailer is the per-page compression flag; bits 0..30 are the 31-bit CRC32C of the on-disk bytes. Phase 3 (issue #8) — seedocs/format.md§ Page trailer for the rationale of the 32→31-bit precision tradeoff.
Constants§
- TRAILER_
OFFSET - Byte offset of the page trailer inside any non-header page.
- V1_
CRC_ MASK - Mask isolating the lower 31 bits of the v1 trailer (CRC region).
- V1_
FLAG_ MASK - Mask isolating bit 31 of the v1 trailer (compression flag).
Functions§
- crc32c
- Compute the CRC32C of
bytesusing the Castagnoli polynomial. - crc32c_
append - Continue a CRC32C computation: fold
bytesinto a running CRC produced by a priorcrc32c()/crc32c_appendcall. The result is byte-identical tocrc32c(prefix ++ bytes)whereprefixwas the input that producedcrc. This is the only place that calls into thecrc32ccrate’s incremental API, so the WAL frame CRC can be computed over discontiguous segments (header sans-CRC, zeroed CRC field, page body) without allocating a contiguous scratch buffer. - page_
trailer_ flag_ v1 - Phase 3 (issue #8): read the v1 compression flag (bit 31) from
the trailer. The caller is responsible for verifying the
trailer with
page_trailer_valid_v1BEFORE consulting the flag — an unverified buffer’s flag is meaningless. - page_
trailer_ valid trueiff the page trailer matches the recomputed CRC32C of the body (v0 interpretation). Caller decides what error to surface on mismatch.- page_
trailer_ valid_ v1 - Phase 3 (issue #8): v1 trailer verifier. Compares the lower 31
bits of the trailer against the recomputed 31-bit CRC32C of
bytes
[0..TRAILER_OFFSET]. The flag bit (bit 31) is NOT part of the checksum. - write_
page_ trailer - Compute the page trailer for
pageand write it into the lastPAGE_TRAILER_SIZEbytes (v0 interpretation: full 32-bit CRC). - write_
page_ trailer_ v1 - Phase 3 (issue #8): v1 trailer writer. Stamps the per-page
compressedflag into bit 31 and the 31-bit CRC32C of bytes[0..TRAILER_OFFSET]into bits 0..30.