SSTable Format & Persistence (v1.0.0)
When an ImmutableMemTable is flushed to persistent storage, it is serialized into an SSTable (Sorted String Table) .sgdb file containing a header, contiguous record data, a Sparse Index, and an embedded Bloom Filter.
SSTable File Binary Layout
┌──────────────────────────────────────────────────────────────┐
│ 1. Header Block (256 Bytes) │
│ Magic (0x47534442) | Version (1) | Record Count | Data Offset│
│ Bloom Filter Offset | Sparse Index Offset | Tombstone Count │
├──────────────────────────────────────────────────────────────┤
│ 2. Data Block (Sorted Records @ 256) │
│ Record 1 [Seq (8) | Flag (1) | KeyLen | ValLen | Key | Val] │
│ Record 2 [Seq (8) | Flag (1) | KeyLen | ValLen | Key | Val] │
│ ... │
├──────────────────────────────────────────────────────────────┤
│ 3. Sparse Index Block ($K = 16$) │
│ Entry Count (4) │
│ Index Entry 0 [KeyLen | KeyBytes | RecordOffset (8)] │
│ Index Entry 1 ... │
├──────────────────────────────────────────────────────────────┤
│ 4. Bloom Filter Block ($1\%$ FPR) │
│ BitCount (8) | HashCount (4) | BitArrayBytes │
└──────────────────────────────────────────────────────────────┘
Header Fields
- Magic Number (
0x47534442): 4-byte integer magic identifier (GSDB). - Version (
1): 4-byte integer layout version. - Table ID & Timestamps: 8-byte sequence ID and creation timestamp.
- Record Count & File Size: 4-byte record count and total file byte size.
- Data Offset (
256): Byte offset where record payload data begins. - Bloom Filter Offset: Byte offset pointing to embedded
Bfilterbit array. - Sparse Index Offset: Byte offset pointing to
SstSparseIndexarray.
Indexed Read Path in v1.0.0
- Bloom Filter Probe (O(1)): Probes embedded
Bfilterbit array. Non-existent keys are rejected in nanoseconds without reading disk record blocks. - Sparse Index Binary Search (O(log(N/16))): Binary searches
SstSparseIndexsampled entries (K=16) to locate the exact 16-record chunk interval[startOffset, endOffset]. - Positional Reading:
SstReaderreads target block records positionally, guaranteeing zero OS memory leaks and deterministic Windows file handle release.