Storage Engines, Durability and Recovery
Replication cannot repair an undefined local durability contract. This stage makes acknowledge, persist, recover and detect corruption separate, testable events.
Section 3 of 9 · 12 units · about 51 hours
By the end you can Preserve the declared acknowledgement contract across crashes at every write and compaction boundary, detect or safely recover corrupted state, and explain latency from measured amplification, caching and access patterns.
Units
- Point, range and analytical workloads, OLTP versus OLAP, and records, pages and segments4h
- Append-only log layout, write-ahead ordering and checksummed records4h
- Buffered, flushed and durable write states and the fsync contract4h
- Torn, truncated and reordered writes and crash-consistent metadata publication4h
- Recovery scanning, tail repair and recovery-time measurement4h
- In-memory and sparse indexes, and B-tree page and split invariants4h
- LSM levels, memtable flush, SSTables and Bloom filter false positives4h
- Compaction policy, tombstones, atomic manifests and segment compaction with atomic swap5h
- Compression, buffer-pool caching and sequential versus random I/O4h
- Read, write and space amplification and their measurement4h
- Row versus column layout, columnar files, zone maps and object-storage table metadata4h
- A crash-safe key-value store with crash and corruption injection and model-based tests6h
Build it
Mini project · about 14 to 20 hours
Crash-safe segmented storage with defensible acknowledgement boundaries
Extend loglab with a checksummed segmented log and a crash-safe key-value projection in storage/. Use independent operation and persistence models to establish recovery before timing anything on your machine, then explain durability, compaction and access costs from retained histories and byte accounting.
- 1Define the storage fault model and separate buffered, flushed and durable acknowledgement paths. Build versioned segmented write-ahead records with offsets, bounded lengths and identity-bound checksums; compare scans and key-value operations against independent byte-decoding and dictionary models, retaining record fixtures and state-transition histories.
- 2Inject crashes before and after every append, checksum write, flush, sync, index update, manifest publication and acknowledgement, including short, reordered and delayed writes, storage-full and sync errors. Compare recovery with an independent stable-byte model; retain acknowledged-prefix verdicts separating process loss from simulated OS loss.
- 3Implement checkpoint-plus-suffix recovery and index rebuild, including crashes during replay. Check against full replay of the trusted record history; retain idempotence, lost-write and misdirected-record tests. Repair only contract-permitted incomplete tails; surface possible acknowledged loss or interior corruption terminally without inventing records.
- 4Rebuild hash and sparse indexes, add memtable flushes into sorted runs and Bloom filters. Compare point and range results against full scans, Bloom decisions against exact membership and sizing math; retain split-invariant fixtures and separate CMU B+ Tree single-threaded test results with page-capacity reasoning.
- 5Implement projection compaction with retained tombstones, complete synced output files and atomic manifest replacement, including directory sync. Compare recovered live state against uncompacted replay at every publication boundary; retain a planted resurrection failure, its repair and snapshot-retention tests without silently compacting away replayable log records.
- 6Choose a layout for point, range and analytical workloads from byte models; contrast columnar skipping with full-scan results and distinguish file, table and catalog metadata. Check compression round trips and buffer ownership on fixed traces; retain separate CMU Buffer Pool Manager results and cache-state protocols.
- 7Pass randomized model-based operations and planted-delete regressions, retaining shrunk failures. Then repeat sync-policy, compaction and cache-controlled sequential/random-read comparisons; keep sync/recovery times, latency distributions, throughput, resource use, read/write/space amplification and observer overhead, reconciled with byte ledgers, versions, workloads and cache-state evidence.
What you hand in
- The segmented WAL, key-value projection, checkpoint recovery, rebuildable indexes and crash-safe compaction, with acknowledgement and replay-retention contracts.
- Independent dictionary and stable-byte models, exhaustive boundary fault fixtures, shrunk regressions, raw WAL histories and separate public-suite results.
- A repeated measurement dossier with byte ledgers, cache-state evidence, durability limitations and retained policy trade-offs.
How to check it
- Self-grade with the rubric below
- CMU 15-445 Fall 2025 Project 2: B+ Tree
Retain single-threaded insert, delete, iterator and tombstone-buffer results from the unit; your log indexes still need independent full-scan checks.
- CMU 15-445 Fall 2025 Project 1: Buffer Pool Manager
Keep ARC, disk scheduler and page-guard results separately from your store's crash, cache-state and ownership tests.
How it's graded
Acknowledgement and recovery
Pass: Own crash tests agree with the independent stable-byte model at every persistence boundary. The acknowledged-prefix contract survives permitted faults; unrepairable corruption halts with evidence rather than fabricated success.
Great: Delayed sync, failed sync and repeated recovery expose naive durability claims; a documented simulation-versus-filesystem boundary limits what process-kill evidence can establish.
Projection and indexing
Pass: Own dictionary and full-scan checks match randomized operations, rebuilt indexes and sorted runs. Exact membership catches Bloom false negatives; sizing calculations and page invariants have independent fixtures.
Great: A planted delete or index defect produces a shrunk failing sequence, fails before repair and remains a deterministic regression across restart and flush.
Publication and deletion
Pass: Own boundary tests recover old or new complete manifests and match uncompacted replay. A planted tombstone-resurrection defect fails; snapshot and log-retention contracts name which older versions must remain readable.
Great: Crashes combined with orphan cleanup or retained snapshots expose an unsafe reclamation; repaired tests preserve both live-state correctness and declared replay availability.
Cost and scope
Pass: Correctness gates precede repeated measurements. Independent byte ledgers reconcile amplification and skipping; reports name versions, workloads, cache preparation and observer overhead, separating logical I/O from device-traffic claims.
Great: Group-commit or compaction comparisons retain a losing regime; recovery time is explained by replayed bytes and sequential-versus-random read costs without claiming a universal winner.
Resources
- CMU 15-445 - Storage, Index and Recovery SequenceCarnegie Mellon Database Group
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. - DDIA 2e - Chapter 4 Storage and RetrievalMartin Kleppmann and Chris Riccomini
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.
- HLD Handbook - Storage Engines and Data StructuresHLD Handbook
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.
- Operating Systems: Three Easy Pieces - Crash Consistency and Data IntegrityRemzi and Andrea Arpaci-Dusseau
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.
- Hypothesis - Stateful TestingHypothesis
Use
RuleBasedStateMachinewith 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. - The Internals of PostgreSQL - Buffer Manager, WAL and RecoveryHironobu Suzuki
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.
- PostgreSQL 18 Documentation - WAL Configuration and InternalsPostgreSQL Global Development Group
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.
- ARIES: A Transaction Recovery Method (Mohan et al., 1992)ACM TODS (Stanford course copy)
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.
- Replicated Log and Stream Processor - Storage SliceRoadmap-Final
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
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
Read the DESCRIPTION for what
fsyncandfdatasyncguarantee and the directory-sync requirement for new file names, and the ERRORS section for what anEIOfrom write-back can refer to. - Building Distributed Systems - The Logger and IndexesBuild Distributed Systems
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.
- Build Your Own RedisBuild Your Own
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.