SSTable format

An SSTable is an immutable file of sorted internal keys and their values. Flush writes level-0 SSTables, compaction and bulk ingest write the others, and nothing rewrites a file in place: every new file gets a fresh file number (source: src/storage/sst.rs, SSTableWriter; src/storage/mod.rs, flush_memtable_to_sst).

Files are named sst-<file number as 16 lowercase hex digits>.sst in data_dir (source: src/storage/mod.rs, flush_memtable_to_sst; src/storage/compaction.rs, execute_compaction_throttled).

File layout

+-------------------+
| data block 0      |  payload || type byte || CRC32 LE
| data block 1      |
| ...               |
| data block N-1    |
+-------------------+
| filter block      |  sealed-meta frame: [flag][bloom filter]
+-------------------+
| index block       |  sealed-meta frame: [flag][index entries]
+-------------------+
| footer (48 bytes) |
+-------------------+

The writer emits blocks in that order, then calls sync_all on the file and sync_dir on its directory before returning the file's SSTableMeta (source: src/storage/sst.rs, SSTableWriter::finish; src/storage/wal.rs, sync_dir).

Footer

Bytes Field
0..8 Index block offset, u64 LE
8..16 Index block size, u64 LE
16..24 Filter block offset, u64 LE
24..32 Filter block size, u64 LE
32..40 Magic, u64 LE
40 Flags
41..48 Maximum sequence in the file, 7 bytes LE, valid when flag 2 is set
Magic Value Meaning
SST_MAGIC 0x53535441424C4531 ("SSTABLE1") Legacy: filter and index blocks stored raw
SST_MAGIC_V2 0x53535441424C4532 ("SSTABLE2") Filter and index blocks in sealed-meta frames; the current writer always emits this
Flag Value Meaning
FOOTER_FLAG_USER_KEY_FILTER 1 Bloom filter is over user keys, so point reads may use it
FOOTER_FLAG_MAX_SEQ 2 Bytes 41..48 hold the maximum sequence (limit 2^56 - 1)

(source: src/storage/sst.rs, SST_MAGIC, SST_MAGIC_V2, FOOTER_FLAG_USER_KEY_FILTER, FOOTER_FLAG_MAX_SEQ, SSTableWriter::finish, SSTableReader::open)

SST_VERSION (1) is defined but not written into the footer (source: src/storage/sst.rs, SST_VERSION).

The maximum-sequence field was added so engine open does not have to decode every block to find the sequence high water. For an older file without flag 2, max_sequence() scans its blocks, bypassing the block cache (source: src/storage/sst.rs, max_sequence; docs/status/2026-11-27-startup-memory-bound.md). Tested by footer_carries_max_sequence and legacy_footer_without_max_sequence_is_scanned (src/storage/sst.rs, tests).

Data blocks

On-disk frame

+-----------------------------+-----------+-------------+
| payload (compressed and/or  | type byte | CRC32 u32LE |
| sealed block encoding)      |           |             |
+-----------------------------+-----------+-------------+
CRC (crc32fast) covers type byte || payload        BLOCK_FOOTER_SIZE = 5
Type byte Meaning
bits 0..5 = 0 No compression
bits 0..5 = 1 LZ4, lz4_flex::compress_prepend_size
bits 0..5 = 2 zstd, level 3
bit 7 set, bit 6 clear (0x80) Legacy encryption with the master key: nonce(12) \|\| ciphertext \|\| tag(16)
bits 7 and 6 set (0xC0) Keyring sealing, Purpose::SstData: key id(4) \|\| nonce(12) \|\| ciphertext \|\| tag(16)

The writer encodes the block, compresses it, encrypts it when a cipher is installed, then computes the CRC over what will be on disk. The reader checks the CRC, decrypts according to the flag, decompresses and decodes (source: src/storage/sst.rs, BlockBuilder::flush_block, seal_block, read_block_with_verification, CompressionType). Tested by test_block_footer_*, test_block_crc_with_compression_types, test_sstable_compression and test_sstable_block_verification (src/storage/sst.rs, tests).

Data blocks are sealed with seal_blob, which binds the purpose but not the file or the block's position (see Encryption at rest internals) (source: src/storage/sst.rs, BlockBuilder::flush_block, seal_block; src/storage/keyring.rs, seal_blob).

Block encoding

DataBlock::encode writes prefix-compressed entries with a restart point every 16 entries:

entry:  [shared u32 LE][unshared u32 LE][value_len u32 LE][key suffix][value]
        (shared = 0 at every 16th entry: a full key)
block:  entry ... entry  [restart offset u32 LE] ... [num_restarts u32 LE]

The key is the encoded internal key and the value the bincode StorageValue. The decoder rebuilds every key while reading and does not use the restart offsets. In memory a decoded DataBlock keeps one flat data buffer, an index of (offset, key length, value length) per entry, group numbers, 8-byte fence keys for binary search and the block's common key prefix (source: src/storage/sst.rs, DataBlock::encode, DataBlock::decode). Tested by test_data_block_encode_decode, seek_matches_btree_range and fenced_lower_bound_matches_linear_search (src/storage/sst.rs, tests).

The writer cuts a block when the accumulated key + value + 12 bytes reach block_size (4096 by default). The block's index entry is its last key (source: src/storage/sst.rs, SSTableWriter::add).

Filter block

The bloom filter has 10 bits per key (BLOOM_BITS_PER_KEY), rounded up to whole bytes with a minimum of 8 bytes, and ceil(10 x 0.69) = 7 hash functions (clamped to 1..30). The base hash is CRC32 of the key; probes use double hashing with delta = h.rotate_left(15). The encoding is the bit array followed by one byte holding the number of hash functions (source: src/storage/sst.rs, BloomFilter).

Writer mode Filter keys Size
with_user_key_filter() (flush, compaction, bulk ingest) Distinct user keys (encoded key minus its 9-byte suffix) Sized to the number of distinct user keys
Default Whole encoded keys Fixed for 1000 keys

(source: src/storage/sst.rs, SSTableWriter::with_user_key_filter, BloomFilter::new)

Only files with FOOTER_FLAG_USER_KEY_FILTER are skipped by a point read on a filter miss; a whole-key filter cannot answer a user-key question (source: src/storage/mod.rs, consider_sstable). Tested by test_bloom_filter, user_key_filter_rules_out_absent_keys and files_without_user_key_filter_never_skip (src/storage/sst.rs, tests).

Index block

Repeated [key_len u32 LE][last key of block][offset u64 LE][size u64 LE], one per data block. The decoder sorts the entries if they are out of order (source: src/storage/sst.rs, encode_index, decode_index).

Sealed-meta frame

The filter and index blocks of a V2 file are stored as [flag][payload]:

Flag Payload
0 Plain
1 Legacy encrypted (nonce \|\| ct \|\| tag)
2 Keyring sealed with Purpose::SstMeta

(source: src/storage/crypto.rs, seal_meta, open_meta)

Metadata returned to the manifest

finish() returns SSTableMeta { filename, level, file_size, min_key, max_key, entry_count }, where min_key and max_key are the first and last encoded keys written (source: src/storage/sst.rs, SSTableWriter::finish; src/storage/manifest.rs, SSTableMeta).

Reader

SSTableReader::open reads the footer, the filter (unsealing it in V2 files) and the index, and builds BlockSeek, which groups index entries in runs of 32 with fence keys for binary search. Its min_key is the first block's last key; true_min_key is the first key actually stored, read from the first block. Each reader gets a process-unique id from NEXT_READER_ID; the block cache and column cache are keyed by it, so a reopened file never sees another file's cached blocks (source: src/storage/sst.rs, SSTableReader::open, BlockSeek, NEXT_READER_ID). Tested by test_sstable_write_read, test_sstable_true_min_key, test_sstable_scan_matches_brute_force_across_blocks, newest_version_matches_scan and a_reopened_file_gets_a_fresh_id... (src/storage/sst.rs, tests).

Reader method Use
read_block Through the global block cache (Caching and memory)
read_block_uncached Bypasses the cache
with_newest_version Point read at the current time
newest_versions_many Batched point reads for get_many
verify_all_blocks, is_valid Integrity checks
at_rest_census Counts blocks per encryption state for the audit
block_handles, block_handles_in Block list, used by column projections

(source: src/storage/sst.rs, SSTableReader)

Parallel writing

BlockBuilder and PreparedBlocks let bulk ingest encode and compress blocks on several threads, then append_prepared writes them in order. Bulk ingest uses up to 8 threads (BULK_INGEST_MAX_THREADS) once a batch has at least 65,536 entries (BULK_INGEST_PARALLEL_MIN_ENTRIES) (source: src/storage/sst.rs, BlockBuilder, append_prepared; src/storage/mod.rs, BULK_INGEST_MAX_THREADS, BULK_INGEST_PARALLEL_MIN_ENTRIES). Tested by the bulk_ingest_tests module in src/storage/mod.rs.