ARIES recovery simulator

After a crash, a database rebuilds its state from the write-ahead log in three passes: analysis finds what was going on, redo repeats history, and undo rolls back the transactions that never committed. Paste the log from your exercise and get every table and decision the way ARIES makes them.

Redo starts at
10
Losers
T1 T3 T4
CLRs written
4
Pass

Records: 10 T1 update P1, 20 T1 commit (or abort, end), 30 checkpoint, 40 T1 clr P1 next 10 with its undoNextLSN, and 50 flush P1 for a page written to disk (not a log record).

The log
LSNRecordprevLSNRecovery
10T1 update P1–
20T2 update P2–
30T1 update P310
40checkpoint analysis starts
50T2 commit20
60T3 update P5–
70flush P2 (not logged)
80T1 abort30
90T1 CLR P3, undoNext 1080
100T3 update P460
110T4 update P2–
crash
Transaction table after analysis
TransactionlastLSNStatus
T190running: a loser
T250committed (needs an end record)
T3100running: a loser
T4110running: a loser
Dirty page table after analysis
PagerecLSN
P110
P220
P330
P560
P4100
  1. 40Start at the checkpoint: transaction table {T1: 30, T2: 20}, dirty page table {P1: 10, P2: 20, P3: 30}.
  2. 50T2 commits: mark it committed.
  3. 60Update by T3 on P5: add T3 to the transaction table; P5 enters the dirty page table with recLSN 60.
  4. 70Flush of P2: not in the log, so analysis does not see it; the page stays in the dirty page table.
  5. 80T1 aborts: it stays in the table and will be rolled back.
  6. 90CLR by T1 on P3: T1's lastLSN becomes 90; P3 is already in the dirty page table.
  7. 100Update by T3 on P4: T3's lastLSN becomes 100; P4 enters the dirty page table with recLSN 100.
  8. 110Update by T4 on P2: add T4 to the transaction table; P2 is already in the dirty page table.

How to use the simulator

Type the log from your exercise, one record per line, starting each with its LSN. The system crashes after the last line. Press "Crash and recover" and switch between the three passes: analysis shows the transaction and dirty page tables it rebuilds, redo lists every record from the redo point with the reason it is redone or skipped, and undo shows the order of undo and the compensation records it writes, numbered after the last LSN in steps of 10.

  • A checkpoint line stands for a fuzzy checkpoint; its tables are taken from the log as it was at that point, including any flushes before it.
  • A flush line says the buffer manager wrote that page to disk. It is not in the log, so analysis cannot see it; redo notices it through the page's pageLSN.
  • "Copy answer" gives all the tables as text; "Copy link" saves the log in the address.

What is write-ahead logging?

A database changes pages in memory and writes them to disk later. With write-ahead logging (WAL), every change is first described in a log record, and the log is written to disk before the changed page is; a transaction counts as committed once its commit record is on disk. After a crash the log is the truth: it says what was committed and what each page should contain.

ARIES is the recovery method that made this precise for systems that may write uncommitted pages to disk (steal) and need not write committed pages at commit (no-force). Both choices are good for performance and both leave the disk wrong after a crash, so recovery has to redo committed work that never reached disk and undo uncommitted work that did.

LSNs and the two tables

  • Every log record has a log sequence number (LSN), increasing through the log, and a prevLSN linking it to the same transaction's previous record.
  • Every page stores its pageLSN, the LSN of the latest change applied to it, so recovery can tell whether a change is already on disk.
  • The transaction table lists running transactions with their lastLSN, where their undo would start.
  • The dirty page table lists pages changed in memory but not yet written, with their recLSN, the first change since the page was last written.

A fuzzy checkpoint writes both tables to the log without stopping the system or flushing pages, which limits how far back recovery has to read.

Analysis

Analysis starts from the last checkpoint's tables and reads forward to the end of the log. An update or CLR puts its transaction in the transaction table with that lastLSN and, if its page is not yet in the dirty page table, adds the page with this record as its recLSN. A commit marks the transaction committed; an end record removes it. At the end, committed transactions without an end record are given one, and every transaction still marked running is a loser that must be rolled back. Because flushes are not logged, the dirty page table may include pages that were in fact written; that is safe, and redo sorts it out.

Redo: repeating history

Redo starts at the smallest recLSN in the dirty page table, the oldest change that might not be on disk, and reapplies every update and CLR from there, for winners and losers alike, so that the database returns to exactly its state at the crash. A record is skipped when:

  1. its page is not in the dirty page table, so the change reached disk before the checkpoint or was never needed;
  2. its page's recLSN is later than the record, so the page was written after this change and dirtied again later;
  3. the page on disk has a pageLSN at least as large as the record's LSN, so the change is already there. Only this check needs the page itself to be read.

Undo and compensation records

Undo collects the lastLSN of every loser and repeatedly processes the largest LSN, so all losers are rolled back together in reverse log order. For an update, it restores the old value and writes a compensation log record (CLR) whose undoNextLSN is the update's prevLSN, then continues from there. For a CLR found in the log, from a rollback that was in progress at the crash, it does nothing but jump to the CLR's undoNextLSN, so work already undone is never undone again. When a transaction has nothing left to undo, an end record is written.

Crashing during recovery

Recovery itself can crash. Redo is safe to repeat because the pageLSN check skips changes already applied, and undo's progress is recorded in the CLRs, which the next redo replays and the next undo skips over. The model on this page was checked this way: on 2,000 random histories under strict two-phase locking, with random flushes, checkpoints and rollbacks, recovery left every page holding the value of its last committed update in 2,000 of them. In the 1,832 histories where undo wrote more than one record, a second crash part-way through undo followed by a second recovery gave the correct pages every time. In 1,505 histories redo skipped at least one record.

ARIES in real databases

C. Mohan and colleagues at IBM published ARIES in ACM Transactions on Database Systems in 1992, and it shaped the recovery of IBM's DB2 and many later systems. Microsoft's documentation describes SQL Server's recovery without its newer Accelerated Database Recovery as following the ARIES model, with the same analysis, redo and undo phases. PostgreSQL also writes a WAL and replays it forward after a crash, but because its storage keeps multiple versions of rows, the changes of transactions that never committed are simply left invisible, and it has no undo pass.

ARIES recovery questions and answers

What are the three phases of ARIES recovery?

Analysis scans forward from the last checkpoint to rebuild the transaction table and the dirty page table and find which transactions were still running. Redo scans forward from the smallest recLSN in the dirty page table and repeats history, reapplying every logged change that might not be on disk, including those of transactions that will be rolled back. Undo then rolls back the transactions that were running at the crash, newest change first, logging a compensation record for each change it undoes.

When does ARIES skip redoing a log record?

An update or CLR at or after the redo point is skipped in three cases: its page is not in the dirty page table, the page’s recLSN is later than the record, or the page on disk already has a pageLSN at least as large as the record’s LSN. The first two are decided from the tables alone; the third needs the page to be read.

What is a compensation log record (CLR)?

The log record written when an update is undone, during a normal rollback or during recovery. It describes the undo as a redo-only change and carries an undoNextLSN: the next record of that transaction still to be undone. If the system crashes during undo, the next recovery redoes the CLRs and continues from their undoNextLSN, so nothing is undone twice and undo always finishes.

Why does ARIES redo the changes of transactions that will be undone?

Repeating history brings every page to exactly the state it had at the crash, so that undo can work with ordinary logical undo and page-level information such as pageLSN is consistent. It is simpler than deciding which changes to skip, and it allows fine-grained locking, where pages hold changes of several transactions at once.

What is the difference between recLSN, pageLSN and lastLSN?

pageLSN is stored on each page: the LSN of the latest change applied to it. recLSN is kept in the dirty page table: the LSN of the first change that dirtied the page since it was last written to disk, so redo can start there. lastLSN is kept in the transaction table: the transaction’s most recent log record, where its undo starts.

Does ARIES work if the system crashes during recovery?

Yes. Redo is idempotent because of pageLSN checks, and undo progress survives in the CLRs it writes. The model on this page was run on 2,000 random histories with flushes, checkpoints and rollbacks; recovery left every page correct in 2,000 of them, and in all 1,832 cases where a second crash was simulated part-way through undo, recovering again gave the same correct result.

Further reading

Published Updated