Unit 5 of 12 · about 4 hours · implement, measure

Recovery scanning, tail repair and recovery-time measurement

Recovery is the read half of the durability contract. Its scan rule decides which prefix of the log is truth after every crash.

You'll be able to

  • Implement a recovery scan that replays from the last checkpoint and stops at the first invalid record.
  • Explain ARIES analysis, redo and undo passes and the page LSN rule in one paragraph each.
  • Measure recovery time against log size and state the integrity the scan guarantees.

Covers

Recovery scanning and tail repairRecovery time and data-integrity measurement
1

Read

In this order, only the parts listed

0 of 3 done

  1. CMU 15-445 Fall 2025 logging and recoveryCMU 15-445 - Storage, Index and Recovery Sequence

    Lecture #21: Database Logging with Lecture #22: Database Recovery, including LSNs, checkpoints and the ARIES recovery phases

  2. PostgreSQL checkpoint and recovery processingThe Internals of PostgreSQL - Buffer Manager, WAL and Recovery

    Chapter 9, Sections 9.7 and 9.8: Checkpoint Processing and Database Recovery, with 9.8.2 on LSN comparison and idempotency, read with Section 28.5 on the redo record (page read 2026-10-15)

  3. ARIES restart processingARIES: A Transaction Recovery Method (Mohan et al., 1992)

    Sections 1 and 3 for the repeating-history overview, then Section 6 with 6.1 Analysis, 6.2 Redo and 6.3 Undo

    Read the pass structure and the page LSN rule. Skip physiological logging detail and the 1992 storage taxonomy; the rest is beyond this section.

2

Focus on

  • Start from the last checkpoint redo record, not from the beginning of time. Everything before the redo point is already on disk, so recovery time grows with replayed bytes and checkpoint frequency trades write cost against recovery time.
  • ARIES repeats history first: redo all logged actions to rebuild the crash state, then undo the losers. Redo before undo is the order that makes the result correct.
  • A page is redone only when the log record LSN exceeds the page LSN. The comparison is what makes replay idempotent across repeated crashes.
  • A corrupt record with nothing valid after it is treated as a torn append and truncated, which is safe only if that record was never acknowledged. A corrupt record with valid records after it may hide acknowledged writes, so stop with a corruption error and keep the evidence; recovering only the prefix is an explicit, lossy choice. Recovery never invents missing records.
Common mistakes · 3
  • Replaying from segment zero after every crash. The redo record exists so recovery skips already-checkpointed work.
  • Redoing only committed transactions. Repeating history redoes everything including losers, then undoes them; skipping the redo pass breaks the chain the undo pass assumes.
  • Skipping over a corrupt middle record to salvage later ones. Only a corrupt tail that was never acknowledged is safely truncatable; a corrupt middle record ends the trustworthy prefix.
3

Try it yourself

Closed-book, before checking anything

Given a log with records r1 and r2 checksummed and a torn r3, state the recovered prefix and the index contents after recovery. Then crash partway through recovery, run it again and show the result is identical: in a paged engine the page LSN check makes redo idempotent, and in your log the index is rebuilt from the same valid prefix.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What are the three ARIES restart passes in order, and what does each produce?Answer

    Analysis rebuilds the dirty-page and transaction tables. Redo repeats history to the crash state. Undo rolls back loser transactions with compensation records.

  2. 2.A log record has LSN 100 and the page has LSN 100. Does redo apply it?Answer

    No. Redo applies only when the record LSN exceeds the page LSN. Equal LSNs mean the page already contains the change.

  3. 3.Recovery finds a corrupt record in the middle of a segment with valid records after it. What is the safe outcome?Answer

    Do not skip it, and do not silently truncate there: the later records may be acknowledged writes. Stop with a corruption error and keep the evidence; serving only the prefix before it is an explicit, lossy operator choice.

  4. 4.Checkpoints run twice as often. What happens to recovery time and steady-state cost?Answer

    Recovery replays less log so it finishes faster, but each checkpoint flushes dirty pages and emits full-page images more often, raising steady-state write cost.

5

Practice

  • CMU 15-445 Fall 2025 Homework #6: Recovery

    Recovery homework: ARIES pass and LSN reasoning questions

    Work the pass-order and LSN questions on paper, then check your answers on the course's Gradescope site for non-CMU learners (entry code in the course FAQ). Keep your local log replay as the implementation evidence.

You're done when

Your log recovers the valid prefix on torn-tail and clean schedules, halts with evidence on a corrupt middle record, and recovery time tracks replayed bytes on your machine.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 10 more in the section
  • CMU 15-445 - Storage, Index and Recovery SequenceCarnegie Mellon Database Group · primary

    Follow Fall 2025 lectures 3 to 10 and 21 to 22. Do the BusTub projects from tag v20251119-2025fall (https://github.com/cmu-db/bustub/tree/v20251119-2025fall): P1 (ARC replacer, disk scheduler and buffer pool manager) and P2 (B+ tree with a leaf tombstone buffer), with P0 (Count-Min Sketch) as the C++ warm-up. Tests ship with a DISABLED_ prefix to remove, and GCC 15 needs -DCMAKE_CXX_FLAGS="-include cstdint" at configure time. Use the storage and recovery homework for WAL reasoning, and keep C++ scope bounded to storage and recovery.

  • The Internals of PostgreSQL - Buffer Manager, WAL and RecoveryHironobu Suzuki · support

    Read Chapter 1 Sections 1.2 to 1.4 (heap pages and tuples), Chapter 8 (buffer manager and dirty-page flushing) and Chapter 9 Sections 9.1 to 9.8 (WAL segments, XLOG records, checkpoints and recovery). Compare each mechanism with your simplified store. The site is revised often, so note the date you read it.

  • ARIES: A Transaction Recovery Method (Mohan et al., 1992)ACM TODS (Stanford course copy) · support

    Read the introduction, the overview and restart processing (analysis, redo by repeating history, undo) and the page LSN rule. The rest is 1992 storage detail beyond this section.

Also in this section

  • Hypothesis - Stateful TestingHypothesis · support

    Use RuleBasedStateMachine with rules, bundles and invariants to drive your store and a dictionary model with the same random operation sequences, and check the machine catches a planted bug before trusting a pass.

  • DDIA 2e - Chapter 4 Storage and RetrievalMartin Kleppmann and Chris Riccomini · required

    Read "Storage and Indexing for OLTP" (log-structured storage, B-trees, their comparison and secondary indexes) and "Data Storage for Analytics" (column-oriented storage). Its Bloom filter, tombstone and write-ahead log coverage is brief, so take those from OSTEP and The Internals of PostgreSQL. Build a workload decision table, then connect each claim to a measurement from your small store.

  • Building Distributed Systems - The Logger and IndexesBuild Distributed Systems · optional

    Only the first three tasks are free (a write-ahead log, its recovery and log segments). Tasks are graded in the browser after login, so treat a pass as a drill and keep your local harness as the evidence.

  • HLD Handbook - Storage Engines and Data StructuresHLD Handbook · required

    Read Part 0 data structures plus Part 4 storage engines and OLTP versus OLAP. Use its exercises for comparison, while the CMU project and local fault tests remain the implementation evidence.

  • PostgreSQL 18 Documentation - WAL Configuration and InternalsPostgreSQL Global Development Group · support

    Read "WAL Configuration" (checkpoints and the redo point crash recovery starts from), "WAL Internals" and "Reliability" for the official, versioned statement of the write-ahead and durability contract.

  • Operating Systems: Three Easy Pieces - Crash Consistency and Data IntegrityRemzi and Andrea Arpaci-Dusseau · required

    Read Chapter 42 (FSCK and journaling: the crash scenarios, data and metadata journaling and their write order) and Chapter 45 (data integrity: checksums, misdirected and lost writes, scrubbing; https://pages.cs.wisc.edu/~remzi/OSTEP/file-integrity.pdf). Turn each crash scenario into an injection point in your store.

  • Build Your Own RedisBuild Your Own · optional

    Use the persistence and data-structure portions only if a second implementation is needed to cement parsing, indexing or append-log behavior. Do not replace the crash-tested stage artifact with tutorial completion.

  • Replicated Log and Stream Processor - Storage SliceRoadmap-Final · support

    Implement checksummed segments, indexes, acknowledgement states, recovery, retention and atomic metadata changes. Preserve every crash schedule and corrupted artifact needed to reproduce a failure.

  • Apache Parquet File FormatApache Software Foundation · support

    Read the File Format layout (row groups, column chunks, footer metadata) and the Page Index page (ColumnIndex and OffsetIndex with per-page min and max values for page skipping). Use it only for file layout and skipping; it does not cover table metadata or catalogs.

  • Linux man-pages: fsyncLinux man-pages project · support

    Read the DESCRIPTION for what fsync and fdatasync guarantee and the directory-sync requirement for new file names, and the ERRORS section for what an EIO from write-back can refer to.