Architectural Overview
A disk-page storage engine implementing an 8KB slotted page with downward line-pointer array growth and upward tuple growth, PageLSN tracking, and 3-phase ARIES crash recovery (Analysis, Redo, Undo).
In production relational and analytical database systems—spanning PostgreSQL, SQLite, MySQL/InnoDB, and DuckDB—understanding how query clauses, schema constraints, index structures, and storage engines execute under the hood separates surface-level query authors from staff-level database engineers. This capstone build lab guides you through implementing 8KB Slotted Page + Write-Ahead Log Crash Recovery Simulator from first principles with deterministic self-test invariants.
Guided Implementation Walkthrough (4 Progressive Steps)
Step 1: 8KB Slotted Page Tuple Allocation (pd_lower & pd_upper)
- Core Database Concept: Growing Line Pointer Slots Downward From Header and Tuple Payloads Upward From Page End
- Target Module:
index.js(SlottedPageWalEngine.insertTuple) - Engineering Specification: Implement
insertTuple(payloadStr, lsn)to allocate space in an 8192-byte slotted page where headerpd_lowergrows downward by 4 bytes per slot andpd_uppergrows upward by tuple byte length. - Implementation Hint:
Check freeSpace >= 4 + byteLength; allocate tuple at pd_upper - len, append slot { offset, length, dead: false }, and advance pd_lower += 4. - Verification Invariant: deterministic assertion verified in
test.jsstep 1
Step 2: Tuple Deletion & In-Place Page Compaction
- Core Database Concept: Defragmenting Dead Tuple Holes While Preserving External Slot Numbers (TIDs)
- Target Module:
index.js(SlottedPageWalEngine.compactPage) - Engineering Specification: Implement
deleteTuple(slotId, lsn)andcompactPage()so that dead tuple bytes are reclaimed andpd_upperis restored while every live tuple keeps its originalslotId. - Implementation Hint:
Repack all live tuples contiguously from pageSize downward, updating each live slot’s offset without changing its slot index. - Verification Invariant: deterministic assertion verified in
test.jsstep 2
Step 3: ARIES WAL Analysis Phase (Active Tx Table & Dirty Page Table)
- Core Database Concept: Reconstructing Loser Transactions and Redo Start LSN from the Write-Ahead Log
- Target Module:
index.js(SlottedPageWalEngine.analyzeWal) - Engineering Specification: Implement
analyzeWal(walRecords)to identify uncommittedloserTxsand the minimumredoStartLsnacross dirty pages. - Implementation Hint:
Scan WAL forward: track active/loser transactions on BEGIN/UPDATE/COMMIT, and record first recLSN per page in dirtyPages. - Verification Invariant: deterministic assertion verified in
test.jsstep 3
Step 4: ARIES Redo (Repeating History) & Undo (Loser Rollback)
- Core Database Concept: Applying Logged Changes Where pageLSN < record.lsn and Rolling Back Losers in Reverse LSN Order
- Target Module:
index.js(SlottedPageWalEngine.recoverWal) - Engineering Specification: Implement
recoverWal(walRecords, initialPages)to execute ARIES Redo followed by reverse-LSN Undo of uncommitted loser transactions. - Implementation Hint:
Redo all UPDATE records forward to reconstruct state at crash, then walk loserTx UPDATE records in reverse LSN order restoring beforeImage. - Verification Invariant: deterministic assertion verified in
test.jsstep 4
Relational & Storage Engine Guarantees
- Curriculum Domain: Storage Engines, Buffer Pool & WAL
- Difficulty & Time Budget: Advanced (~45 minutes)
- Key Architectural Highlights:
• 8KB Slotted Page memory layout growing line pointers downward and variable-length tuples upward
• In-place line-pointer compaction reclaiming fragmented tuple space without changing external TIDs
• Three-phase ARIES WAL recovery (Analysis, Redo from minRecLSN, and reverse Undo with CLR logging) - Core Primitives & Tags:
Slotted Page,Write-Ahead Logging,ARIES Recovery,PageLSN,Buffer Pool
Related Curriculum Units
- slotted page layout 8kb anatomy
- heap files hot updates fillfactor
- buffer pool clock sweep lru k
- write ahead logging wal lsn
- checkpoints dirty page flushing
Production Database Context & Verification
This from-scratch relational engine component is engineered with zero external dependencies and deterministic verification harnesses. Every internal database invariant—from three-valued logic (TRUE / FALSE / UNKNOWN), referential integrity, and fan-out-free join pre-aggregation to B+Tree page splits, MVCC snapshot visibility (xmin / xmax), slotted-page compaction, and ARIES write-ahead log crash recovery—is asserted directly in test.js. Use the interactive browser workbench above to complete the 4 guided steps in Guided Lab mode or inspect and benchmark the complete reference architecture in Full Solution mode.