Expand description
Write-ahead log (WAL) for crash recovery
Provides durability guarantees for mutations before they reach the memtable. Every mutation is fsync’d to the WAL before being acknowledged.
§WAL Entry Format
Each entry in the WAL follows this binary format:
[u32 LE: entry_length] (4 bytes)
[u32 LE: crc32] (4 bytes)
[bytes: serialized Mutation] (entry_length bytes)The CRC32 checksum is computed over the serialized mutation bytes only. This format allows for:
- Detection of corrupted entries during replay
- Safe truncation at partial writes (crash during append)
- Sequential append with minimal overhead
§Memory Budget
- 4 KB buffer for sequential append (configurable)
- Flushes to disk on explicit sync() or buffer full
§Crash Recovery
On startup, replay() reads all valid entries:
- Corrupted entries: logged as warnings, skipped
- Truncated entries: stop replay (incomplete write)
- Valid entries: returned in order for memtable replay
Structs§
- Write
Ahead Log - Write-ahead log for crash recovery