Skip to main content

Module checkpointer_task

Module checkpointer_task 

Source
Expand description

Checkpointer task — Post-MVP credibility item.

Pairs with cache/bgwriter.rs to give reddb the Postgres-style three-tier I/O setup:

  1. bgwriter — flushes dirty pages on a cadence so eviction is fast.
  2. 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).
  3. walwriter — flushes the WAL itself (already in wal/group_commit.rs).

Mirrors PG’s checkpointer.c. Each checkpoint:

  1. Records start LSN.
  2. Walks every dirty page, calling pager flush.
  3. Records end LSN.
  4. Writes a Checkpoint WAL record with both LSNs.
  5. 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§

CheckpointConfig
Checkpoint cadence configuration.
CheckpointResult
Result of a single checkpoint pass.
CheckpointStats
Checkpoint diagnostic counters.
CheckpointStatsSnapshot
CheckpointerHandle
Shutdown handle returned by spawn.

Traits§

CheckpointDriver
Trait the database must implement so the checkpointer can drive the actual checkpoint without depending on the full Database struct.

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.