Expand description
Checkpointer task — Post-MVP credibility item.
Pairs with cache/bgwriter.rs to give reddb the
Postgres-style three-tier I/O setup:
- bgwriter — flushes dirty pages on a cadence so eviction is fast.
- checkpointer — periodically writes a checkpoint record to the WAL, fsyncs every dirty page, and advances the recovery floor (the LSN below which the WAL can be truncated).
- walwriter — flushes the WAL itself (already in
wal/group_commit.rs).
Mirrors PG’s checkpointer.c. Each checkpoint:
- Records start LSN.
- Walks every dirty page, calling pager flush.
- Records end LSN.
- Writes a
CheckpointWAL record with both LSNs. - Truncates the WAL up to the previous checkpoint’s redo pointer.
Crash recovery starts from the most recent checkpoint record’s redo pointer instead of replaying the entire WAL — bounded by checkpoint_timeout (default 5 min) so recovery wall time is bounded too.
§Why
Without checkpoints, the WAL grows unbounded and crash recovery has to replay everything since database creation. With checkpoints every N minutes / M MB of WAL written, recovery is bounded to “WAL since last checkpoint”.
§Wiring
Phase post-MVP wiring spawns this task during
Database::open alongside the bgwriter. Stops when the
database is dropped.
Structs§
- Checkpoint
Config - Checkpoint cadence configuration.
- Checkpoint
Result - Result of a single checkpoint pass.
- Checkpoint
Stats - Checkpoint diagnostic counters.
- Checkpoint
Stats Snapshot - Checkpointer
Handle - Shutdown handle returned by
spawn.
Traits§
- Checkpoint
Driver - Trait the database must implement so the checkpointer can
drive the actual checkpoint without depending on the full
Databasestruct.
Functions§
- spawn
- Spawn the checkpointer thread. Wakes on a 1-second cadence to check both the timeout and the WAL byte threshold; runs a checkpoint as soon as either trips.