Skip to content

data-plane: view storage fixes from the live demo (cache charge, label columns, RFC 3339 times, format 4) - #871

Merged
zzylol merged 6 commits into
mainfrom
feat/view-storage-fixes-to-main
Nov 24, 2026
Merged

zzylol merged 6 commits into
mainfrom
feat/view-storage-fixes-to-main

Conversation

@zzylol

@zzylol zzylol commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Review first

Why

The live demo showed four problems in the view store and the query API:

  1. A read-back view window was charged the whole segment's text dictionary (about 5.9 MB a window against 0.4–1.6 MB real), so the 2 GiB window cache held about 360 windows and thrashed (fix(data_plane): charge a read-back view window its own bytes, not the segment dictionary #865).
  2. Every per-series view row stored its job/region/… label texts, though they follow from the series identity (feat(data_plane): read view label columns back from the series identity #869).
  3. vmalert sends time as RFC 3339; the data plane planned only Unix seconds and forwarded everything else to its fallback store (fix(data_plane): read query times as RFC 3339 too, as the Prometheus API does #868).
  4. View files wrote almost as many bytes as the raw samples (a 10-sample DDSketch row took 160 B) (data-plane: compact, compressed view fragments (format 4) #866).

What

commit change measured
#865 a read-back window is charged window_batch_bytes + its state bytes; each segment dictionary counted once in the view bytes demo replay: hit ratio 0.808 → 0.988, cold reads 55.2 → 3.8 MB/s
#869 a text column equal to the series' label is not written (IDENTITY_LABEL), rebuilt on read from the identity keys; format 3 demo replay: 19.1 → 17.2 GB/h written
#868 time/start/end accepted as Unix seconds or RFC 3339; empty time = now; an unparsable time is a 400, as in Prometheus vmalert rules answered from the plan without a rewriting proxy
#866 compact lossless DDSketch / exact state columns, varint text keys, zstd level 1 per fragment; format 4 demo segments 7.23 → 0.94 GB; live run, 30 min in: views 0.68 → 0.14 MB/s written, 1.10 → 0.22 GB on disk

Interfaces

 // data_plane/src/segment.rs
-pub const FORMAT_VERSION: u32 = 2;
+pub const FORMAT_VERSION: u32 = 4;
+const IDENTITY_LABEL: u32 = 8;   // label column rebuilt from the series identity
+const COMPACT_STATES: u32 = 9;   // compact state column (state_codec)
 impl WindowLocation {
-    pub fn read(&self, schema: &SchemaRef, how: ViewRead) -> Result<Batch, Error>;
+    /// 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>;
-    #[cfg(test)] pub(crate) fn maps(&self, address: usize) -> bool;
 }
 // data_plane/src/prometheus.rs
-pub(crate) struct BadTime(String);
-pub(crate) struct BadRange(String);
+pub(crate) struct BadParameter(pub(crate) String);
+pub(crate) fn parse_time_ms(name: &str, text: &str) -> Result<Option<i64>, BadParameter>;
+// data_plane/src/state_codec.rs (new, crate-private)
+pub enum CompactKind { DDSketch, Sum, Count, MinMax, Counter, LastTwoSamples }

Port notes

  • ViewFiles::append on main creates the active segment lazily. The labels-by-identity cache from feat(data_plane): read view label columns back from the series identity #869 is therefore built in a local map when no segment is active, and that map becomes the new segment's.
  • prometheus.rs keeps main's crate-private visibility and its upper bound on the range step.
  • Tests that use APIs main has since changed were adapted: series_ids::intern is now intern_pairs, CacheStats::loads is replaced by the tier's cold_reads, and decode_fragment takes the columnar bytes. main's test of the old directory layout is not part of this port.

Tests

Run on this branch (changed parts only): cargo fmt --check; cargo clippy -p data_plane --all-targets -D warnings; cargo test -p data_plane --lib for store, persist, segment, window_cache, series_ids, state_codec and prometheus; and --test view_cache_charge, view_tiering, view_persistence, view_cold_allocations, view_memory, ingest_shards, time_params, server and no_forward.

ingest_shards::a_shard_running_ahead_does_not_close_windows_early failed once in the first run (a 422 at t=30) and passed in 3 reruns on this branch and on main: a timing flake, not caused by this change.

zzylol and others added 6 commits November 24, 2026 18:18
…e segment dictionary (#865)

A view window read back from its file was charged Batch::memory_bytes, which counts the segment's shared text dictionary once per text column (about 5.9 MB per window against 0.4-1.6 MB real), so the 2 GiB window cache held about 360 windows and thrashed. Both paths now charge window_batch_bytes (plus a read-back window's mapped state columns), and ViewStore::bytes counts each live segment dictionary once. Demo replay, minutes 6-12: hit ratio 0.808 -> 0.988, cold reads 55.2 -> 3.8 MB/s.
…ty (#869)

A view text column whose every row holds its series identity's label of the column's name is no longer written: the fragment marks it IDENTITY_LABEL and a read rebuilds it from the identity column's keys through a per-segment label-value array (counted once per segment). View file format version 3; older segments are set aside at startup. The writer looks each identity up once per segment. Demo replay, minutes 6-12: view bytes written 19.14 -> 17.17 GB/h, view files 3.82 -> 3.24 GB; cold-read parity suites unchanged.
…API does (#868)

time, start and end are parsed as Prometheus' parseTime does: Unix seconds with an optional fraction, else RFC 3339 (as Go's time.Parse(RFC3339Nano) accepts it), Prometheus' min/max time strings forwarded, an empty time meaning now, and anything else refused with Prometheus' 400 text. RFC 3339 instant and range queries (as vmalert sends them) are answered from the plan, with the same answers as their Unix-seconds forms.
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.
series_ids::intern is intern_pairs, CacheStats has no loads (the tier's cold_reads counts decodes), and decode_fragment takes the columnar bytes; cargo fmt.
@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 merged commit d34f296 into main Nov 24, 2026
1 check passed
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