Memtable
The memtable is an in-memory sorted data structure (skip list) that holds recent writes before they’re flushed to SSTables.
Operations
- Insert: O(log n) — new facts are inserted in key + commit_ts order
- Point lookup: O(log n) — binary search for a specific key
- Prefix scan: O(log n + k) — seek to prefix, iterate k matches
- Range scan: O(log n + k) — seek to start, iterate through range
Flush Trigger
When the memtable reaches memtable_max_bytes (default: 4MB), it’s frozen and flushed to an L0 SSTable:
- The current memtable is frozen (made immutable)
- A new empty memtable is created for incoming writes
- The frozen memtable is serialized as an SSTable
- The SSTable is registered in the manifest
- The WAL for flushed records can be truncated
Fast Write Path Interaction
The fast write path checks memtable size before each write:
- If the memtable is below capacity: write directly (fast path)
- If the memtable is full: fall back to the channel path, triggering a flush
Configuration
| Parameter | Default | Description |
|---|---|---|
memtable_max_bytes | 4MB | Maximum memtable size before flush |