transaction-correctness

Installation
Summary

WAL mechanics, checkpointing, concurrency, and recovery in Turso's SQLite implementation.

  • Turso uses WAL (Write-Ahead Logging) exclusively with in-memory WAL index instead of SQLite's shared memory file, supporting one writer and concurrent readers without blocking
  • Checkpointing transfers WAL pages back to the main database in four modes: PASSIVE (non-blocking), FULL (waits for readers), RESTART (resets WAL), and TRUNCATE (truncates WAL file)
  • Each connection maintains private page cache, dirty pages, and snapshot view; shared state includes frame cache, read lock slots, write lock, and checkpoint lock across all connections
  • Recovery replays valid commits from WAL on crash; durability, atomicity, isolation, and no-lost-updates invariants enforced through fsync on COMMIT and checkpoint coordination
SKILL.md

Transaction Correctness Guide

Turso uses WAL (Write-Ahead Logging) mode exclusively.

Files: .db, .db-wal (no .db-shm - Turso uses in-memory WAL index)

WAL Mechanics

Write Path

  1. Writer appends frames (page data) to WAL file (sequential I/O)
  2. COMMIT = frame with non-zero db_size in header (marks transaction end)
  3. Original DB unchanged until checkpoint

Read Path

  1. Reader acquires read mark (mxFrame = last valid commit frame)
  2. For each page: check WAL up to mxFrame, fall back to main DB
  3. Reader sees consistent snapshot at its read mark

Checkpointing

Transfers WAL content back to main DB.

Related skills
Installs
591
GitHub Stars
18.7K
First Seen
Jan 28, 2026