MiniDB is a lightweight, high-performance, single-file embeddable B+Tree storage engine written in modern C++20 with full ARIES (Algorithm for Recovery and Isolation Exploiting Semantics) Write-Ahead Logging (WAL) crash durability.
- Slotted Page Storage Engine: 4 KB fixed-size page architecture with 24-byte
PageHeader, 32-byteNodeHeader, sorted 8-byteSlotarray, and downward-growing payload heap with dynamic fragmentation compaction. - Buffer Pool Manager: Configurable frame capacity with LRU eviction replacer, pin count tracking, dirty page flushing, and WAL ordering invariants.
- Physical WAL & CLRs: Dual-image physical page diff logging for
kUpdaterecords, compensation log records (kClr) for single-pass rollback, sharp checkpointing, and torn tail detection via CRC32 checksums. - ARIES 3-Pass Recovery Engine:
- Analysis Pass: Scans WAL forward building active transaction table.
- Idempotent Redo Pass: Replays physical updates driven strictly by page LSN comparison.
- Undo Pass: Reverses active uncommitted transactions using
prev_lsnchains and generates CLRs.
- Crash Consistency Fuzzer: Automated multi-process fuzzer with POSIX
fsyncjournal oracle testing against arbitrary processSIGKILLand simulatedpwrite/fsyncsyscall failures. - Zero External Dependencies: Standard C++20 library + POSIX system calls only (
pread,pwrite,fsync,ftruncate).
┌─────────────────────────────────────────────────────────────┐
│ DB Facade │
├──────────────────────────────┬──────────────────────────────┤
│ BTree Engine │ RecoveryManager │
├──────────────────────────────┴──────────────────────────────┤
│ BufferPoolManager │
├──────────────────────────────┬──────────────────────────────┤
│ LogManager │ DiskManager │
└──────────────────────────────┴──────────────────────────────┘
- C++20 compatible compiler (
clang++,g++, or Apple Clang) - CMake 3.20+
- POSIX-compliant operating system (Linux, macOS)
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build
./build/minidb_testscmake -S . -B build_release -DCMAKE_BUILD_TYPE=Release
cmake --build build_release
./build_release/bench_main --mode seq_insert --num-ops 100000python3 scripts/crash_fuzz.py --iterations 100 --mode mixed --build-dir buildMeasured on GitHub Actions Ubuntu Server runner (AMD EPYC 7763, 100k ops, 100-byte payloads):
| Benchmark Mode | Operations | Throughput (ops/sec) | Latency p50 (us) | Latency p99 (us) |
|---|---|---|---|---|
| Sequential Insert | 100,000 | 52,442 ops/sec | 6.42 us | 90.29 us |
| Random Insert | 100,000 | 58,640 ops/sec | 6.11 us | 88.88 us |
| Point Get | 100,000 | 427,923 ops/sec | 2.25 us | 3.42 us |
| Range Scan (100 keys) | 10,000 | 405,404 ops/sec | 2.37 us | 3.65 us |
| Recovery | 1 open | 433 ops/sec | 2.20 ms | 2.20 ms |
See docs/BENCHMARKS.md for complete benchmark details and docs/COMPARISON.md for head-to-head comparisons against SQLite, LMDB, and RocksDB.
- Single-Threaded Execution Model: Transactions execute under global synchronization locks; concurrency control (2PL/MVCC) is omitted for storage layer simplicity.
- Fixed Page Size: Fixed 4096-byte pages require keys and values to fit within a single slotted page (max entry payload: 3900 bytes). Large binary objects (LOBs) are not supported.
- Sharp Checkpointing:
DB::Checkpoint()flushes all dirty pages to disk during checkpointing rather than maintaining a fuzzy checkpoint dirty page table.
MIT License. See LICENSE for details.