Skip to content

feat(data_plane): read view label columns back from the series identity - #869

Merged
zzylol merged 3 commits into
feat/tiered-view-storagefrom
feat/views-derive-identity-labels
Nov 24, 2026
Merged

zzylol merged 3 commits into
feat/tiered-view-storagefrom
feat/views-derive-identity-labels

Conversation

@zzylol

@zzylol zzylol commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: per-series views store each label (job, region, service, …) as a text column: a 4-byte key per row per label. Those keys repeat what the row's series identity already encodes.

  • Change: a text column whose every row equals the row's series-identity label of that name ("" when absent) 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. The view file format becomes version 3; older segments are set aside at startup.

  • Effect: 12-minute replay of the live demo's plan and load, minutes 6–12, against this branch with fix(data_plane): charge a read-back view window its own bytes, not the segment dictionary #865 merged:

    • view bytes written: 19.14 → 17.17 GB/h (−10%);
    • view files at minute 12: 3.82 → 3.24 GB (−15%);
    • cold reads: 3.80 → 3.35 MB/s.

    Query latency was slightly higher in this one run (p50 0.78 → 0.83 s; requests over SLO 101 → 215 of about 9,500), with equal ingest throughput and decode CPU. See the caveat under Verification.

    Query answers are unchanged: the cold-read parity suites pass. The executor's output schema is unchanged, so no ASAPPlanner change is needed.

Review guide

  • Base: feat/tiered-view-storage, the demo branch, with fix(data_plane): charge a read-back view window its own bytes, not the segment dictionary #865 merged.
  • Read first in data_plane/src/segment.rs:
    • IdentityLabels::of / holds_label: the writer's check;
    • the IDENTITY_LABEL arm of decode_fragment;
    • Segment::label_values.
  • Needs care:
    • label_values extends the cached array incrementally as the active segment's texts grow;
    • the arrays are counted in Segment::dictionary_bytes through dictionaries_built.
  • Mechanical: descriptor() / Descriptor factor out the existing descriptor parsing; the design doc is updated.

Behavior: before → after

View 122 of the demo plan: sum by (region, service, job) (sum_over_time(data[3m])), exact Sum per series at 1 s over 10,000 series. Its schema is window_end, state, job, region, service, $promql_series_identity.

before after
fragment columns written ts, states, text ×4 (identity + 3 labels) ts, states, text ×1 (identity), identity_label ×3 (0 bytes)
label key bytes per 1 s window 3 × 40 KB 0
text bytes, all views, first 30 s of the demo load 21.5 MB 7.1 MB
query answers — identical (the parity suites read every window cold)

Replay, minutes 6–12. Both runs used the same 40-core host, back to back:

#865 merged (before) this PR
view bytes written 19.14 GB/h 17.17 GB/h
view files at min 12 3.82 GB 3.24 GB
cold reads 5.4/s, 3.80 MB/s 5.4/s, 3.35 MB/s
cache hit ratio, charge per entry 0.988, 0.79 MB 0.988, 0.79 MB
ingest (append runs, min 6–12) 72,000 72,000
view decode CPU (min 6–12) 4.43 s 4.75 s
query requests over SLO / p50 / p99 101 / 0.781 s / 1.008 s 215 / 0.831 s / 1.049 s
data plane RSS at min 12 3.98 GB 3.94 GB

The analysis estimated about 15% of view bytes (2.9 GB/h) for label keys. The measured saving is 2.0 GB/h, because some views carry no label columns or no identity column.

Interfaces

data_plane/src/segment.rs, data_plane/src/series_ids.rs

-pub const FORMAT_VERSION: u32 = 2;
+/// The view file format version these segments are (3: label columns read back from the identity).
+pub const FORMAT_VERSION: u32 = 3;
+/// A text column whose every row holds its series identity's label of the column's
+/// name ("" without it): no data, rebuilt on read from the identity column (index in flags).
+const IDENTITY_LABEL: u32 = 8;
 pub struct Segment {
     dictionary: Mutex<Option<ArrayRef>>,
     dictionaries_built: Mutex<Vec<Weak<dyn Array>>>,
+    /// Per label name, one value per segment text, built for IDENTITY_LABEL reads.
+    identity_label_values: Mutex<IdentityLabelValues>,
 }
+/// The labels of the series whose identity text is identity: the interned series' own,
+/// else parsed once (result_labels); None when it is no label set's JSON.
+pub fn labels_of_identity(identity: &str) -> Option<Arc<BTreeMap<String, String>>>;

File format: fragment column kind 8 (IDENTITY_LABEL). The header version is 3. A version 2 segment is renamed .stale at startup with the warning a segment of another plan, group or format version (this data plane reads version 3); no migration is done.

Usage: the data plane runs as before (data_plane --plan plan.json --view-dir views).

  1. When a refresh persists view 122's window, encode_fragment finds $promql_series_identity in the schema and looks up each row's labels in the interner (labels_of_identity). It writes job/region/service as IDENTITY_LABEL.
  2. A cold read decodes them as dictionary columns: the keys are the identity column's keys, and the values come from Segment::label_values("job", ..).
  3. The query gets the same rows as before.

Algorithm changes

Label columns on disk.

  • Before: every text column is written as u32 keys into the segment's texts.
  • After:
    1. Writer: a text column is written as IDENTITY_LABEL when every row's value equals labels(identity)[name] ("" when absent). The identity column is itself text with no nulls, and the window is not empty. Otherwise it is stored as before.
    2. Reader: keys come from the identity column. Values come from a per-segment array that maps each text key to that text's label taken as an identity. The array is built once, extended as texts are added, counted once per segment, and parsed uncached when the identity is not interned.
  • Correctness:
    • The writer checks every row before marking a column, so the rebuilt column is equal row by row.
    • Unit tests: label_columns_are_read_back_from_the_series_identity (active, sealed in both read modes, after restart through the index, after the active segment's texts grow, interned and never-interned identities, a non-derivable column stored as text), and an_older_format_version_segment_is_set_aside.
    • Parity: with_every_view_read_cold_* in planner_executor_parity.
  • Complexity:
    • Write: one lookup per row in the active segment's identity → labels cache, which consults the process-wide interner once per series per segment. An earlier revision looked each row up in the interner directly; in the replay that cost more over-SLO requests (319 vs 215).
    • Read: none per row. Each segment does a label lookup per text per label name, once, and copies the array when it grows.
    • Memory: about 100–150 KB per label name per segment at 10k series, counted in the view bytes.
  • Limits:
    • Views without the identity column (grouped views) keep their text columns.
    • A label column that differs from the identity in any row stays text for that window.

Decisions and open questions

  • Needs reviewer decision: None.
  • Decided:
    • Kept the identity's segment text key rather than the interner's series id: interner ids are per process, so they are not stable across restarts.
    • No ASAPPlanner change: the executor schema is unchanged.
    • Old segments are set aside rather than migrated.

Verification

scope result newly failing vs base notes
cargo test -p data_plane --lib (persist, segment, store, window_cache, series_ids) 28 passed 0 2 new tests
view_cache_charge, view_tiering, view_persistence, view_cold_allocations 1 / 9 / 7 / 1 passed 0
planner_executor_parity cold suites (instant, range) passed 0 every window read cold from files
planner_executor_parity push suites T2 passed when run alone — They keep views in memory, so they do not touch this change. In a full parallel run on a loaded host, T2 differed on the oldest window (also seen without this change under load) and the other hit the host's 1,024 open-file limit.
cargo fmt --check, cargo clippy -p data_plane --all-targets -D warnings clean
replay, #865 merged vs this PR tables above One 12-minute run each. Query latency was a little higher (p50 +6%); low-priority test builds overlapped the start of this PR's run, so the difference is not established as a regression. Re-measure on the live demo before relying on it.

Follow-ups

A view's text column whose every row holds its series identity's label of
the column's name is no longer stored: the fragment marks it
IDENTITY_LABEL and a read rebuilds it from the identity column's keys and
a per-segment label array. View file format version 3; older segments are
set aside at startup.
…ollow-ups

Label values per segment are extended by the texts added since (parsed
uncached), counted with the segment's dictionaries; descriptor bounds are
checked once; empty windows store no identity labels; tests cover
identities that are not interned, the startup index and the extension.
@zzylol zzylol added area: data plane Runtime ingestion, storage, and query-serving data paths enhancement New feature or request labels Nov 24, 2026
… when writing

The writer looked up every row's identity in the process-wide interner for
every fragment (about 600k lock acquisitions per second in the demo);
the active segment now caches each identity's labels.
@zzylol
zzylol marked this pull request as ready for review November 24, 2026 15:04
@zzylol
zzylol merged commit 214e399 into feat/tiered-view-storage Nov 24, 2026
1 check passed
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