#1198·litestream

Checkpoint triggers unwanted full snapshot under high write load

Author: corylanouCreated Mar 15, 2026Updated Sep 27, 2026
Labelsbugstale

Summary

Under high write load (500+ writes/sec), checkpoints trigger unwanted full snapshots instead of small incremental L0 syncs. This was detected by the new TestLTXBehavior soak test which found 742 snapshot-on-checkpoint violations in a 30-minute run.

Evidence

[no-snap-on-checkpoint] FAIL: 742 snapshot-on-checkpoint violations detected
[l0-page-count] FAIL: 125/279 (44.8%) L0 files exceed 200 pages. Max seen: 1917.3 MB

The "max seen: 1917 MB" for an L0 file is a full database snapshot written at L0 instead of L9.

Root Cause

The syncedToWALEnd flag (added in #927) tracks whether the last sync reached the WAL end, so verify() can distinguish expected checkpoint truncation from external WAL modification. However, under high write load:

  1. Sync() calls verifyAndSync() → sync reaches WAL end → syncedToWALEnd = true
  2. checkpoint() calls verifyAndSync() BEFORE checkpoint — new writes arrived, sync does NOT reach WAL end → syncedToWALEnd = false
  3. execCheckpoint() truncates WAL
  4. checkpoint() calls verifyAndSync() AFTER checkpoint — verify() sees truncated WAL, but syncedToWALEnd = false → triggers full snapshot with reason "wal truncated by another process"

The pre-checkpoint sync clears the flag when concurrent writes prevent it from reaching WAL end. The post-checkpoint sync then misidentifies the expected truncation as external.

Impact

  • Full database written as L0 LTX file (up to 1.9GB observed) instead of small incremental
  • Downstream compaction failures ("nonsequential page numbers in snapshot")
  • Compaction chain stalls at L2/L3

Fix

Set syncedToWALEnd = true in checkpoint() after execCheckpoint() succeeds, before the post-checkpoint verifyAndSync() call. The checkpoint function knows it just truncated the WAL, so the subsequent truncation detection should always be treated as expected.

Related: #927, #1183