CSE Roadmap

Common tier · about 2 hours · 5 parts

Part 3 of 5 · 1 min read

The log entry is written first

A record of the change is written to a sequential log before the dirty page is ever flushed.

Think of a shipping company confirming a change. It writes "package 501 now weighs 2kg" in a sequential logbook right away, well before anyone updates the warehouse's master inventory sheet.

In plain words: before, or at the same time as, changing the in-memory page, the database writes a small record describing exactly what changed to a sequential log file: which page, which value, old value, new value. This log write happens first, and is itself written to disk quickly, because the log is the one thing recovery can trust if the system crashes before the dirty page is ever flushed. Level 8's recovery modules depend entirely on this log existing and being durable before the data page is.

A worked example. The log entry for the price update records something like "page containing book_id 501, column price, old value 22.50, new value 24.99," appended to the end of the log file.

The key lines. No new SQL; the log write is internal to the storage engine, triggered automatically by the same UPDATE statement.

Write-ahead log entry

A write-ahead log entry is a sequential record describing exactly one change (what page, what value, old and new), written to a durable log before the corresponding data page change is guaranteed to reach disk.

Example: the shipping company's logbook entry for package 501's new weight is a write-ahead log entry; the master inventory sheet is the data page, updated later.