Tested by pulling the plug, in software.
Every commit is written ahead to a log, synced before it is acknowledged by default, and replayed whole or not at all after a crash. A power-loss harness checks that by building the disk images a power cut could leave and opening each one.
An INSERT, from statement to visible row
Every write is logged before it is applied, lands in a reclaimed extent when one fits, and teaches the filter index about itself before it commits.
- 1The statement arrives
Over any protocol. It is parsed once; a repeated shape is learned and skips the parse next time.
- 2Written ahead
A WAL record is appended and synced before the commit is acknowledged; synchronous_commit decides whether the commit waits for that sync.
- 3Row bytes placed
The free list offers the best-fitting reclaimed extent. Only when none fits does the rows file grow.
- 4Pointer record
37 bytes: id, length, position, deleted, xmin = this transaction, xmax = none.
- 5Filter index taught
Each column's fingerprint bits are set for the new row, and its zone's min/max bounds widen.
- 6Commit
The transaction is marked committed. Snapshots taken from now on see the row; older ones never will.
synchronous_commit, with the trade stated
On (the default), nothing is acknowledged until its records are durable: one fdatasync per writing statement. Off, a commit returns once its bytes are in the kernel's page cache. A process crash then loses nothing, and only an operating-system crash or power loss costs the last --wal-writer-delay-ms of transactions: whole transactions off the end of the log, never half of one.
rasterizeddb_core --location <PATH> --synchronous-commit off --wal-writer-delay-ms 200 # or live: SET CONFIG wal.synchronous_commit = off;
Why SIGKILL tests are not enough
A killed process leaves the page cache behind, so it can never lose an unsynced write, keep a later write while losing an earlier one, or undo a rename. A power cut can do all three. So the harness watches every sync and directory operation, and at each cut point freezes what a power loss there could leave:
- each file as of its last completed sync; a sync still in flight makes nothing durable
- unsynced 4 KiB pages kept or dropped, page by page, so logs get torn tails
- directory operations not yet covered by a directory sync kept or reverted, newest first
- several seeded images per cut, each opened as a fresh database and checked
Damage in the middle of the log stops the start
Since 1.1.0: a torn tail, the normal shape of a crash, is replayed up to the last whole record without a word. Damage followed by valid records is something else, and the server refuses to start rather than quietly drop every commit after it. An operator can choose to replay the prefix and drop the rest, for one start only.
A gap of zeros is told apart from damage: a power cut can keep a later page and drop an earlier one, and that is a crash, not corruption.
rasterizeddb_core --location /var/lib/rasterizeddb --wal-truncate-damaged
# embedded: Builder::open("./data").wal_truncate_damaged(true)And the rest
- Replay stops at the first record it cannot read whole
- Checkpoints bound replay time; the log is preallocated
- Backups verify log coverage on both sides before a snapshot is recorded
- Replication logs are written ahead through the same WAL
- An optional build adds checksums on the read path