Skip to content

data-plane: compact, compressed view fragments (format 4) - #866

Merged
zzylol merged 1 commit into
feat/tiered-view-storagefrom
feat/compact-view-segments
Nov 24, 2026
Merged

zzylol merged 1 commit into
feat/tiered-view-storagefrom
feat/compact-view-segments

Conversation

@zzylol

@zzylol zzylol commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Review first

  • Format change. View files move to format 4. Segments of formats 2 and 3 are set aside at startup (renamed *.stale) and are not readable by this build. A data plane restarted on this build starts its views empty.
  • Answers do not change. The compact encodings are lossless. A read rebuilds the executor's mapped state layout byte for byte. A state not in the form the executor writes is stored in the mapped layout, never approximated.
  • Cold-read trade-off. A cold read now always decompresses and rebuilds the states into its own buffers. Before, it borrowed them from the mapping. Decode of a window already in the page cache costs more (table below); a window whose pages are not in memory costs less, since there are 25–60× fewer bytes to read.

Why

View files wrote almost as many bytes as the raw samples they summarize. In the live demo, a DDSketch of the ten samples a series has in a 1 s pane took 160 B a row on disk: an 88-byte head that repeats alpha, the admission rate and a count on every row, then sparse u32 bucket keys, u32 offsets and u32 text keys. An exact counter took 72 B a row and an exact sum 40 B.

What

Before this PR (format 3): a fragment is one view's rows of one window, by column, uncompressed. State columns are in the executor's mapped layout. Label columns are already rebuilt from the series identity (#869).

After this PR (format 4): the fragment is still columnar, one per (view, window), so a cold read still reads one fragment. Two changes:

  1. Compact state and text columns (data_plane/src/state_codec.rs):
    • DDSketch: alpha and the admission rate once per column; no count (it is the sum of the bucket and zero counts). Per store, either the non-empty buckets as varint gaps and counts, or every count from the first to the last non-empty bucket, whichever is shorter. The first bucket index is a delta from the previous row's.
    • Exact Sum, Count, Min, Max, Counter and IRate: a tag byte saying which fields are set, then the set floats. Timestamps are varint deltas from the previous row's. A counter's increase is left out when it is exactly last − start.
    • Float fields go in byte-plane streams, one per field.
    • Text keys are varint deltas.
    • KLL and Count-Min keep the mapped layout.
  2. zstd level 1 per fragment: a u32 length, then the compressed columnar bytes. One zstd context per thread.

Interfaces

 // data_plane/src/segment.rs
-pub const FORMAT_VERSION: u32 = 3;
+pub const FORMAT_VERSION: u32 = 4;
 const IDENTITY_LABEL: u32 = 8;
+/// A state column in compact form; its flags are the CompactKind code.
+const COMPACT_STATES: u32 = 9;
 // Text column data: u32 keys
-TEXT: u32 key per row
+TEXT: signed varint delta from the previous row's key
 // A stored fragment
-columnar bytes
+u32 columnar length, then the columnar bytes compressed (zstd level 1)
 impl WindowLocation {
-    pub fn maps(&self, address: usize) -> bool;
     /// The batch, and the bytes of its rebuilt state columns (charged by the window cache).
     pub fn read(&self, schema: &SchemaRef, how: ViewRead) -> Result<(Batch, usize), Error>;
 }
+// data_plane/src/state_codec.rs (crate-private module)
+pub enum CompactKind { DDSketch, Sum, Count, MinMax, Counter, LastTwoSamples }
+pub fn encode_states(kind: CompactKind, states: impl Iterator<Item = impl AsRef<[u8]>>) -> Option<Vec<u8>>;
+pub fn decode_states(kind: CompactKind, bytes: &[u8], rows: usize) -> Option<(Vec<u64>, Vec<u32>)>;
+pub fn encode_text_keys(keys: impl ExactSizeIterator<Item = u32>) -> Vec<u8>;
+pub fn decode_text_keys(bytes: &[u8], rows: usize) -> Option<Vec<u32>>;

The window cache's charge for a read-back window stays window_batch_bytes(batch) plus the state bytes read returns (#865). The rebuilt DDSketch buffer is shrunk to its length, so the charge equals what the window holds. Each label column read back from the series identity holds its own copy of the identity keys, as in #869, so the charge is exact.

Measurements

Bytes per row on the demo's segments. The data is 27 minutes of format-2 segments of the 1 s workload (7.2 GB), re-encoded offline. Bytes include the record frame.

state, pane format 2 compact only format 4 (compact + zstd 1)
DDSketch α=0.02, 1 s 160.5 49.6 17.2
DDSketch α=0.05, 5 s 232.9 98.8 31.3
DDSketch, 60 s 271.6 198.6 82.0
exact Counter, 1 s 72.1 23.1 7.4
exact Sum, 1 s 40.1 12.1 3.2
all views 7.23 GB 2.74 GB 0.94 GB (7.7× smaller)

For the 30 s workload, on a copy of its first 10 minutes of segments, by view write rate: format 2 wrote 2.59 GB/h, zstd 1 alone 0.78 GB/h, and format 4 0.57 GB/h. #869's label columns overlap with part of the "compact only" column: in format 3 the label text keys were already gone.

Encode and decode time. view_read_bench (extended here with a family argument and write timing) was run at 10,000 series × 40 windows of 10 samples each, on one pinned core, 3 runs each, base (format 3) against this PR. The table shows the median ms per window.

family write, ns/row (base → PR) cold, page cache dropped, mmap warm, page cache, mmap pread warm
DDSketch α=0.02 1,549 → 1,236 11.9 → 6.0 2.6 → 5.5 4.5 → 5.6
exact Counter 736 → 709 6.5 → 1.4 0.23 → 1.24 1.31 → 1.24
KLL (mapped layout) 1,329 → 1,039 15.2 → 3.4 0.72 → 2.7 3.1 → 2.7

The bench's synthetic states repeat across series, so its byte counts (1–5 B/row) are not representative. The bytes per row above come from the demo's segments.

What this means for query latency. A window-cache miss on a page-cache-resident 10k-row window costs 1–3 ms more CPU. A miss whose pages left memory costs 5–12 ms less. With #865, misses run at about 5 windows/s in the demo replay, about +15 ms of CPU per second at worst. Hits, which are ≈99% of reads, are unchanged.

Tests

  • state_codec unit tests:
    • pinned sizes (a 10-sample DDSketch takes 47 B compact against a 120 B view; a counter 20 B against 56 B);
    • byte-exact round trip for DDSketch (empty, zeros, negatives, counts wider than a byte, dense and sparse stores) and for every exact kind, including non-canonical records;
    • damaged input returns an error.
  • a_ten_sample_ddsketch_window_is_stored_compact pins a 1,000-series window at 30,196 B, against 124,352 B in the mapped layout. It also fails if the writer's DDSketch output ever falls back to the mapped layout.
  • cold_reads_report_state_bytes_and_share_one_dictionary replaces the borrow test.
  • label_columns_are_read_back_from_the_series_identity (feat(data_plane): read view label columns back from the series identity #869) now checks only the fragment length order, since fragments are compressed.
  • every_family_reads_back_from_its_fragment covers answer parity for every family through segments.
  • Passed on the rebased head: cargo fmt --check; cargo clippy -p data_plane --all-targets -D warnings; cargo test -p data_plane --lib (store, persist, segment, window_cache, series_ids, state_codec: 37 passed); --test view_cache_charge, view_tiering (9), view_persistence (7), view_cold_allocations, view_memory, ingest_shards (9).
  • view_tiering::view_files_stay_bounded_by_retention and ingest_shards::a_shard_running_ahead_does_not_close_windows_early, which failed in an earlier run, pass on both the base branch and this PR. No failure reproduced.

Reviews

Independent review passes, one for correctness and one for dead code, duplication and efficiency, were run on the rebased change. Fixed here:

  • the DDSketch rebuild buffer is shrunk to its length, so a cold window's charge is not below what it holds;
  • compress refuses a fragment past MAX_FRAME_BYTES, instead of writing one that a read would reject;
  • one zstd compressor and one decompressor per thread, not one per fragment;
  • the identity column's keys are decoded once per fragment. Each label column gets its own copy, which keeps view_cache_charge exact: sharing one buffer overcharged by about 40%;
  • encode_text_keys reserves its output, and the module docs no longer describe in-place reads.

Found correct: the round trip of every column kind, including IDENTITY_LABEL over varint keys; lossless DDSketch and exact encodings (NaN payloads, ±inf, −0.0, i64 timestamp extremes); damaged input is rejected without panics; formats 2 and 3 are never misread.

Left for follow-ups:

  • a sketchlib API that lists a DDSketch's buckets, so the data plane stops mirroring sketchlib's view layout (until then, the pinned-size test catches a silent fallback);
  • dropping the now-unneeded 8-byte padding inside fragments and the Mmap read mode, if a bench shows pread ties;
  • decompressing into an aligned buffer, so fixed-width columns are not copied again.

@zzylol
zzylol force-pushed the feat/compact-view-segments branch from b747a27 to da14bb5 Compare November 24, 2026 17:22
@zzylol zzylol changed the title data-plane: compact, compressed view fragments (format 3) data-plane: compact, compressed view fragments (format 4) Nov 24, 2026
@zzylol zzylol added enhancement New feature or request area: data plane Runtime ingestion, storage, and query-serving data paths labels Nov 24, 2026
@zzylol
zzylol marked this pull request as ready for review November 24, 2026 17:23
@zzylol
zzylol merged commit 57673b1 into feat/tiered-view-storage Nov 24, 2026
2 checks passed
zzylol added a commit that referenced this pull request Nov 24, 2026
View file format 4: each (view, window) fragment is zstd level 1 compressed, and DDSketch and exact state columns are stored in a lossless compact form (state_codec.rs) and rebuilt byte for byte into the mapped layout on read; text keys are varint deltas. Formats 2 and 3 are set aside at startup. Demo segments re-encoded: 7.23 GB -> 0.94 GB (DDSketch 1 s 160 -> 17 B/row, counter 72 -> 7.4, sum 40 -> 3.2). Cold reads of pages not in memory 2-5x faster; page-cache-resident window decode 1-3 ms slower per 10k rows. Review fixes: exact cache charge for rebuilt DDSketch and label columns, write-size cap, per-thread zstd contexts.
zzylol added a commit that referenced this pull request Nov 24, 2026
…, label columns, RFC 3339 times, format 4 (#871)

Ports #865, #869, #868 and #866 from the tiered-view-storage branch to main: a read-back view window is charged its own bytes; label text columns are rebuilt from the series identity; query times are read as Unix seconds or RFC 3339; view fragments are compact and zstd-compressed (view file format 4; formats 2 and 3 are set aside at startup). Tests adapted to main's APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant