Skip to main content

Module snapshot

Module snapshot 

Source
Expand description

Snapshot management for WAL replication.

§Snapshot approach

We take a snapshot by checkpointing the WAL (PRAGMA wal_checkpoint(TRUNCATE)) then reading the database file directly, rather than using VACUUM INTO. This avoids:

  • VACUUM INTO failing with “output file already exists” on repeated calls
  • File locking issues when opening a second connection while the main connection holds the WAL lock

Trade-off: the snapshot includes free space from fragmented database pages (slightly larger uploads). A future improvement could re-add VACUUM INTO with unique temp paths if size is critical.

§Concurrency note

The snapshot opens a second SQLite connection to perform the checkpoint. If the main connection is mid-transaction, wal_checkpoint(TRUNCATE) will block until the transaction completes. This is acceptable because snapshots are infrequent and the main connection’s transactions are typically short-lived. If blocking becomes an issue, consider using wal_checkpoint(PASSIVE) which is non-blocking but may not checkpoint all frames.

Structs§

SnapshotManager