Module 07 · From Scratch · Database · with code: Go · about 26 min to read
Continue where you left off ×
Write-Ahead Log
Write-Ahead Log · Open board
Follows Database 04: The B-Tree , and
Before you start. This series builds a small copy of a database, a program that stores your data and can find any piece of it again fast, the way a real database does. So far, it stores rows inside fixed-size chunks called pages, and it finds any row quickly using a B-tree, a sorted tree built out of those pages.
The idea in 30 seconds
A database writes down what it’s about to do, and makes that note survive a crash, before it touches the real data at all.
That note is the write-ahead log. Making a note actually survive a crash is a separate step, called fsync.
A second note, the commit record, says “this is real.” The move only counts once that second note has survived a crash too.
If the second note is missing after a crash, the change never happened, and crash recovery throws it away.
If the second note made it, the change is finished after the fact, a redo, using the notes as instructions.
Without any of this, a crash between two related changes loses data permanently, with no way to even notice.
This is one rule, discovered once at IBM in 1992, in a system Mohan called ARIES, and it is still what runs under your bank’s app today.
Read the story
Lesson 50 of 117 in From Scratch
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson 1992: IBM needs a bank’s records to never half-happen The rule: write the plan down, then act The failure this is actually defending against What fsync actually promises A second, quieter failure: the torn page The record format The log writer The commit path Recovery Kill it and see Checkpoints, and why the log can’t just grow What a real engine adds The log is also the stream The one thing Terms it explains: write-ahead log, WAL, fsync, commit record, crash recovery, redo, power cut, delta, group commit, idempotent, SIGKILL, The log grows forever, checkpoint, bigger, write-behind, absolute new value.
Review From Scratch
Mark as read Saved in this browser, and to your account when you sign in.