Interactive Storage Lab · 4KB Pages, B-Tree & WAL

How mydb.db & mydb.wal work. Click to animate each structure.

Three focused labs: add rows to a 4,096-byte page, watch a B-Tree pointer lookup beam, and simulate a crash before pages flush to disk.

Lab 1 · Fixed 4KB Pages

Page 0 Catalog & Linked TablePages

Interactive Page State

Click a button above to watch rows land in 4KB pages.

PAGE 0 · CATALOG 0x0000..0x0FFF

b"RDBCAT" + v2

heap_first: 1, heap_last: 1, next_row_id: 1

PAGE 1 · TABLE PAGE 0x1000..0x1FFF
Show Rust format details (src/catalog.rs · src/table_page.rs)
DiskManager reads/writes 4,096-byte chunks at page_id * 4096. Page 0 stores CatalogData serialized with bincode (must fit in 4KB). Each TablePage stores BTreeMap<u16, Row> + next_page_id; when insert_row() hits "Page Full", TableHeap allocates and links a new page.
Lab 2 · B-Tree Pointer Lookup

Primary DiskBTree vs Secondary Indexes

Click either button to trace how row_id finds a row's physical RecordId.

1. DiskBTree Root (Page 2 · on disk) — MAX_KEYS = 100 · keys: [1, 2]
2. Matched Pointer — row_id 1 → RecordId { page_id: 1, slot_id: 0 } (or secondary BTree<Vec<i64>> in RAM)
3. Direct Heap Fetch (Page 1 · slot 0) — returns [Integer(1), Text("alice")]
Show Rust B-Tree details & SipHash caveat (src/disk_btree.rs · src/btree.rs)
DiskBTree only indexes internal row_ids. When you run CREATE INDEX, IndexMeta is saved on Page 0 and rebuilt into an in-memory BTree<Vec<i64>> (t = 32) on open(). TEXT indexes use SipHash, so >/< on text falls back to FULL_SCAN.
Lab 3 · Write-Ahead Log

Simulate a crash & watch replay_wal() recover

Buffer Pool (RAM)
—
Disk (mydb.db)
—
What just happened
—
Show WAL binary format & test confidence (src/wal.rs · src/lib.rs)
mydb.wal begins with b"RUSTDBWL" + u16(1) followed by [u32 LE len][bincode WalEntry] synced via sync_all(). Unit and CLI integration tests verify replay after the last Checkpoint, though records do not carry CRC checksums yet.

Try queries in the Simulated Playground next.

Open Simulated Playground Read Limitations Ledger