Skip to main content

run_checkpoint_task

Function run_checkpoint_task 

Source
pub async fn run_checkpoint_task(
    pool: Arc<ConnectionPool>,
    config: CheckpointConfig,
)
Expand description

Run the WAL checkpoint background task.

This is a long-running async task that should be spawned with tokio::spawn. It loops until the pool is dropped (the Arc count falls to one, meaning this task holds the last reference).

The task issues PRAGMA wal_checkpoint(PASSIVE) on every tick. PASSIVE is the only checkpoint mode used; see the module-level doc for why TRUNCATE is excluded. A WARNING is emitted once on threshold crossing (wal_pages transitions from below a threshold to at/above) rather than on every tick, preventing log spam when a long-lived reader pins a WAL snapshot.

Skipped ticks (writer mutex busy) leave both crossing-state flags unchanged so that a skip cannot spuriously re-arm the rate limit while WAL pressure is still elevated.

Uses try_writer_nowait (zero-wait try-lock) so a busy writer causes the current tick to be skipped rather than stalling write traffic.