Transactions make concurrency correct, but machines crash. What recovers the system? An append-only log, plus a marker for where to start replaying.

The final post in the plan series.

1. What’s in the WAL

walog is a file storing redo log entries sequentially:

TypeWritten when
insert / delete / updatea transaction writes
flusha transaction commits
checkpointeverything before it is already applied to tables
create table / schema / use tableDDL and table switching

Key convention: entries between two flushes belong to one transaction, so replay needs no extra transaction-boundary metadata.

2. Replay in two phases

Startup order: load metadata → load checkpoint → read redo log → replay.

Replay itself:

  1. Scan the WAL for a checkpoint entry, take its checkpoint block id;
    • if it matches the block id in metadata, the log is already applied — replay ends;
  2. Otherwise apply entries one by one: insert/delete/update modify data, flush commits and starts the next transaction, create table creates, use table switches.

Two details:

  • replay does not generate redo and does not trigger checkpoints;
  • after a successful replay, the WAL is cleared.

3. When a checkpoint happens

TxnMgr decides at commit time, based on:

  • only one checkpoint at a time;
  • committed transactions are all GC’d;
  • redo size + WAL size exceed a threshold;
  • this transaction committed successfully.

A checkpoint doesn’t involve transactions, and no active transaction can affect the data while it runs — that’s the precondition for safety.

4. What a checkpoint writes

Persist layer by layer:

schema → table → row group → column data → column segment → vector
       → row/column versions → stats

In code, nested loops. Afterwards, log entries before the checkpoint entry are no longer needed.

5. Two engineering corollaries

  1. Commit latency jitters periodically: checkpoints trigger after large commits, and the heavy work sits on the commit path;
  2. Recovery time depends on checkpoint interval: longer intervals mean more log to replay.

So “how often to checkpoint” is a trade-off between recovery time and write amplification, with no single right answer.

6. Checklist

CheckExpectation
One transaction between two flushesyes
Replay finds the checkpoint firstyes
Replay stops generating redoyes
Old logs can be dropped after checkpointyes

7. Series summary

Six posts trace one chain: bind → plan → execute → store → transact → recover. Every layer shares one habit: define correctness first, then talk performance.

Series: Database kernel · Project page

Get the next post

New posts on database kernels and engineering.