zstd and LZ4 framing
Every section of a SEAM data file except the footer is a frame. A frame carries a one-byte header whose low nibble is the frame codec id. This page covers that codec id, the length rules and the writer policy. The column codecs inside a block are a separate layer, see Column codecs.
Frame header
Section titled “Frame header”| Offset | Size | Type | Meaning |
|---|---|---|---|
| 0 | 1 | u8 | low nibble = codec id, high nibble = block format |
| 1 | 4 | u32 LE | raw_len: the decompressed length, at most 64 MiB |
| 5 | m | bytes | body = codec(raw) |
| 5+m | 32 | bytes | seal trailer |
The high nibble is the block format: 0 for a row block, 1 for a columnar block. Meta frames use 0. Any other value is Corrupt("block format").
Codec ids
Section titled “Codec ids”| Id | Name | Body |
|---|---|---|
| 0 | raw | the data itself. m == raw_len is required. |
| 1 | zstd | one standard zstd frame |
| 2 | LZ4 | LZ4 block format (lz4_flex::block), with no frame header |
Any other id is Corrupt.
Length rules
Section titled “Length rules”raw_lenis at most 64 MiB.- The decompressed length must equal
raw_len. - For codec 0, the body length
mmust equalraw_len.
Writer policy
Section titled “Writer policy”The policy lives in crates/strata-lsm/src/codec.rs.
- Compressed output is kept only if
packed + packed/8 < raw. Otherwise the frame is written raw. Herepackedis the compressed size andrawthe uncompressed size. - The default data codec is zstd level 1, called
Auto. - Files at LSM levels 0 and 1 that are neither cold nor the bottom level use LZ4.
- The cold layer uses zstd level 9 with 128 KiB blocks.
- A per-table override selects none, LZ4 or zstd by key prefix. It is stored in the catalog, see Ext C: compression.
- Bloom frames are always raw.
- Stats and index frames use zstd unless the compression setting is None.
How to decode
Section titled “How to decode”- Read the first byte. The low nibble is the codec id.
- Read
raw_lenand check that it is at most 64 MiB. - Authenticate the frame, see the seal trailer.
- Decode the body: copy it for id 0, decompress one zstd frame for id 1, decompress one LZ4 block for id 2. An unknown id is
Corrupt. - Check that the result has exactly
raw_lenbytes.
Illustration
Section titled “Illustration”This example is derived from the rules and is not taken from a real file. A frame header 00 34 00 00 00 has codec id 0 (raw), block format 0 (row) and raw_len = 0x34 = 52. Its body must be exactly 52 bytes. If the writer’s zstd output of those 52 bytes would be 50 bytes, then 50 + 50/8 = 56 is not less than 52, so the writer keeps the frame raw.