Columnar segment format with per-column zstd + blake3 checksum - #3
Merged
Conversation
…§6.1)
Replaces the length-prefixed bincode-row segment format with a real
columnar layout:
magic "UDBRAW1\n" + version + row_count + num_columns
for each of 14 columns:
name + encoding + codec + compressed_len + compressed_bytes
footer: u64 checksum (blake3) + magic "UDBEND01"
Each column payload pre-compression is bincode-serialized Vec<T> of
the column's native type; zstd is applied per-column. Co-locating
homogeneous data (string IDs together, all timestamps together, etc.)
makes zstd's history window much more effective — 10k repetitive
events fit in under 500 KB on disk (segment_format::compression test).
Writer + reader rewritten; flusher and compaction worker thread the
returned checksum through into SegmentMeta, populating a field that
was previously hardcoded to 0.
Format extensibility:
- Encoding discriminants reserved for Dictionary / Delta / Zigzag / RLE;
reader rejects unknown values with a corrupt-segment error.
- Codec discriminants cover None / Zstd / Lz4; reader picks the
decoder per column.
- Adding a column is additive; old readers fail loud.
Validation on read: start magic + version + end magic + checksum must
all match, or open fails with InvalidData. Two new tests verify byte-
flip and truncation rejection.
tests/segment_format.rs (5 tests): round-trip preservation including
Correction events and i128 quantities; empty-segment validity;
checksum mismatch rejection; truncation rejection; compression
sanity. README adds a Segment format section.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes review item #6. Replaces the length-prefixed bincode-row segment format with a real columnar layout (spec §6.1) — per-column zstd compression, blake3 footer checksum, format-versioned headers, and readers that reject corrupt or truncated files.
File format
Each column payload before compression is a bincode-serialized
Vec<T>of the column's native type (Vec<String>,Vec<i64>,Vec<i128>,Vec<Option<String>>,Vec<SmallDimensions>, etc.). Zstd is applied per-column. Co-locating homogeneous data makes zstd's history window dramatically more effective — the new compression test packs 10k repetitive events into under 500 KB.Extensibility
Encodingenum reserves discriminants forDictionary/Delta/Zigzag/RLE— these can be added without bumping the file format version, and the reader rejects unknown values with a corrupt-segment error.Codecenum coversNone/Zstd/Lz4; the reader picks the decoder per column header.Validation
Every open verifies start magic + version + end magic + checksum. Any deviation surfaces as
InvalidData. Two integration tests verify this:checksum_mismatch_is_rejected— flips a byte inside the bodymissing_end_magic_is_rejected— truncates the tailPlumbing
RawSegmentWriter::finish()now returns(row_count, checksum).SegmentMeta.checksum, populating a field that was previously hardcoded to 0.read_next(),scan_by_account()), so the query executor needed no edits.Test plan
cargo build --all-targetsclean with-D warningscargo test --all-targets— 23 tests pass (6 unit + 8 durability + 4 bucketing + 5 segment_format)Still on the backlog
rejectedcountsparking_lotdep🤖 Generated with Claude Code