Expand description
Periodic WAL checkpoint task. Periodic WAL checkpoint task for the connection pool (ADR-091).
Issues PRAGMA wal_checkpoint(PASSIVE) on every tick — non-blocking, never
waits for readers. A rare, separately-gated escalation may additionally run
PRAGMA wal_checkpoint(TRUNCATE) once WAL pressure crosses
truncate_high_water_pages and truncate_min_interval has elapsed since
the last attempt (Plank 2); both run under the single writer checkout
checkpoint_once holds for that tick. checkpoint_once uses
try_writer_nowait (zero-wait try_lock) so a tick is skipped immediately
when the writer mutex is held, rather than blocking — a skipped tick is
always preferable to stalling write traffic.
warn_pages / high_water_pages WARNs fire at most once per below→above
crossing; a skipped tick leaves crossing state unchanged. An age-based
background sweep (Plank 1) additionally checks the oldest span in
khive_storage::tx_registry against tx_warn_secs/tx_max_age_secs on
every tick (Skipped or Observed) and escalates to warn!/error! on each
below→above crossing — visibility only, nothing here force-closes a stale
span.
See crates/khive-db/docs/api/checkpoint.md#module-overview-adr-091-planks-012 for full ADR-091 Plank 0/1/2 design rationale (why TRUNCATE is excluded from ordinary ticks, the single-writer-checkout invariant, and why Plank 1 is a sweep rather than the ADR’s originally-described per-statement guard).
Structs§
- Checkpoint
Config - Configuration for the WAL checkpoint background task.
- Checkpoint
Severity Emission - One severity-ladder emission produced by a single
CheckpointSeverityState::observe_wal_pagescall. - Checkpoint
Severity State - ADR-091 severity ladder state, carried across ticks by the caller
alongside
TruncateState. Pure state machine: no I/O, no logging — callers turn the returned emissions intotracingcalls. - Truncate
State - Mutable escalation state carried across ticks by the caller (ADR-091 Plank 2).
- TxAge
Emission - One emission produced by a single
TxAgeSweepState::observecall. - TxAge
Sweep State - ADR-091 Plank 1 background-sweep state, carried across ticks by the
caller alongside
CheckpointSeverityStateandTruncateState. Pure state machine: no I/O, no logging — callers turn the returned emissions intotracingcalls, mirroringCheckpointSeverityState’s shape.
Enums§
- Checkpoint
Severity Rung - ADR-091 graduated severity rung for sustained WAL pressure.
- Checkpoint
Tick - Outcome of a single checkpoint attempt.
- TxAge
Rung - ADR-091 Plank 1 rung for the open-transaction registry’s background age sweep: independent of the WAL-pressure ladder above, keyed purely off how long the registry’s oldest entry has been open.
Constants§
- DEFAULT_
WARN_ SUSTAINED_ CYCLES - Default number of consecutive above-
warn_pagesobserved ticks required to escalate from the INFO to the WARN rung of the ADR-091 severity ladder.
Functions§
- checkpoint_
consecutive_ skips - Current consecutive-skip run length; 0 once the next tick is observed.
- checkpoint_
last_ skip_ wal_ pages - WAL page count last known at the time of the most recent skip, if any skip has occurred yet in this process.
- checkpoint_
once - Issue one checkpoint cycle against the writer connection.
- checkpoint_
skipped_ ticks - Total checkpoint ticks skipped (writer busy) in this process’s lifetime.
- last_
observed_ wal_ pages - Last-observed WAL page count, if any checkpoint tick has run yet in this process. Read surface for the daemon-frame metrics snapshot.
- run_
checkpoint_ task - Run the WAL checkpoint background task.
- truncate_
attempts - Total WAL TRUNCATE attempts made in this process’s lifetime.
- truncate_
consecutive_ failures - Current consecutive TRUNCATE-attempt failure count.