Try
↑ ↓ move↵ openesc close
In this lesson · topic 5 of 7
  1. 1. A disk reads pages, not keys
  2. 2. Walking down, splitting up
  3. 3. Insert thousands of keys and count the pages
  4. 4. One small record, one whole page
  5. 5. The log lets the pages wait
  6. 6. How often to write the pages out
  7. 7. Pages, splits and the log

Topic 5

The log lets the pages wait

4 min read

Two jobs for one file

A crash in the middle of a split can leave the tree half changed. A parent may point at a page that was never written. The engine needs a way to commit a change that does not depend on getting every page to disk in the right order.

A write-ahead log is that way. Before it touches a page, the engine appends a record of the change to the log and flushes the log. Once the record is safe, the insert is committed. The pages stay dirty in memory.

An append is a sequential write, and the log record is small. In the lab it is 10xmeasured write amplification in total with the log on, against 35xmeasured without it. The log pays for itself by letting page writes be deferred and shared.

Recovery

After a crash, the engine reads the log from the last checkpoint. It redoes changes that were committed but whose pages did not reach disk. It undoes changes of transactions that never committed. The tree comes back in a consistent state.

The rule is simple to say. A page must not be written to disk before the log records that describe its changes are on disk. That is why it is called write-ahead.

The price

Every change is written twice, once to the log and once, later, to the page. The log write is small. The page write is large, but a page that changed many times between checkpoints is written once.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms