Skip to content

chore: pin ASAPPlanner 566b35c and its asap_sketchlib d050037 (view format 5) - #886

Draft
zzylol wants to merge 3 commits into
refactor/layout-eval-deployfrom
chore/bump-planner-latest
Draft

zzylol wants to merge 3 commits into
refactor/layout-eval-deployfrom
chore/bump-planner-latest

Conversation

@zzylol

@zzylol zzylol commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Review guide

  • Base: refactor/layout-eval-deploy (refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884, head 659d53b, the restacked layout stack). This is a stacked draft. Rebased from 7862cb6: the conflicts were storage::boundary (deleted by the restack, so its test JSON change is dropped with it), FORMAT_VERSION (now pub(crate) there, kept so, value 5) and the README pin line.
  • Read first:
    1. crates/storage/src/segment.rs:
      • view_bytes and view_column_of (the write path);
      • the COMPACT_STATES / VIEW_STATES arms of decode_fragment (the read path);
      • FORMAT_VERSION.
    2. crates/storage/src/state_codec.rs: the DDSketch head constants, read_dd and DdContents::view_bytes.
    3. crates/storage/src/persist.rs: window_rows, which now returns each row's source batch and row.
    4. crates/query/src/lib.rs: query_time_slot.
    5. crates/data-plane/tests/planner_executor_parity.rs: within_retention (the T2 test fix, its own commit).
  • Mechanical:
    • SketchAlgorithm renames in tests and benches;
    • the hand-built MaterializedView JSON in tests, which gains plan_id and view_state_key;
    • doc and README pins.

Re-pin to 566b35c

f2da999 → 566b35c (ASAPPlanner #1527, #1528, #1543, #1518) and 01f3333 → d050037 (asap_sketchlib #273). Only Cargo.toml, Cargo.lock (sources only) and the README pin line change; no backend code change was needed.

Change Backend effect
#1518: every family with a view layout (DDSketch, KLL, Count-Min) is sealed into it (StateColumn::sealed); KLL quantiles and Count-Min totals are read on the views; the cost model charges sealed states at their view layout. None in code. The write path already borrowed a batch's sealed views (view_bytes), so KLL and Count-Min windows are now borrowed too instead of written per state. The bytes are the library's to_view_bytes either way, so the stored layout is unchanged: FORMAT_VERSION stays 5 (fragments 2.7 MiB, 7.1 B/row in view_read_bench on both pins; persisted bytes per ingest_bench run 6.11 MB on both).
#1543 / asap_sketchlib #273: a DDSketch computes its indexable bounds once. None. The wire and view bytes are unchanged (only the in-memory struct and a doc line in ddsketch/wire.rs changed).
#1527 (no Count-Min over weights not proven non-negative), #1528 (search-space pruning rule 1: threshold θ). The Planner chose the same plans for the parity dump and ingest_bench workloads (same view sets), so no plan-driven difference.

Public API between f2da999 and 566b35c: only SearchSpacePruning gained a field, which the backend does not build.

Planner changes and how the backend follows them

Planner change (between 1d527bc and f2da999) Backend change
#1521 removed StateColumn::from_mapped, state_view_bytes and family_has_mapped_form. #1542 restored them as StateColumn::from_views, StateColumn::view_bytes(index) and family_has_view_layout. Cold reads build the state column with from_views, still zero-copy over the fragment buffer. Writes read each row's view from its own window batch's state column (view_bytes). That borrows the view when the batch already holds sealed views, and writes it otherwise. The column kind constant is renamed MAPPED_STATES → VIEW_STATES; its on-disk code stays 7.
asap_sketchlib #252: a DDSketch keeps no sum / min / max (ASAPv1 kind 0x05 0x01). The view head shrinks from 88 to 64 bytes. The compact DDSketch codec reads and rebuilds the new head. Its offsets are now named constants. A compact DDSketch column has no float streams.
MaterializedView gained the required fields plan_id and view_state_key (#1536). query_time_slot (shared query-time results) sets the plan's plan_id and a key naming only its node. Without this, any plan with a shared node failed to install with "missing field plan_id".
SketchAlgorithm variants were renamed (Kll → KLL, Cms → CountMinSketch, Hll → HLL, HydraCms → HydraCountMinSketch, ...). The plan wire version is 16. Renamed in tests and benches. The backend has no plan-version check of its own; the Planner's loader checks the version.
from_views reports a column's state_memory_bytes as the bytes its views span. from_mapped reported 0. Neither charges a run. No code change: the backend's caches use Batch::memory_bytes, which still charges 0 for these states. One test now asserts the new report.
MaterializedView::view_state_key() is public. Not adopted. The view store keys stored windows by (plan hash, refresh group, node id), not by coverage or definition_id. Behavior is kept as it was.

Interfaces

crates/storage/src/segment.rs (crate-private)

-/// The view file format version these segments are.
-pub const FORMAT_VERSION: u32 = 4;
+/// 5: DDSketch states without `sum`, `min` and `max` (ASAPv1 kind `0x05 0x01`; a 64-byte view head).
+pub const FORMAT_VERSION: u32 = 5;
-const MAPPED_STATES: u32 = 7;
+const VIEW_STATES: u32 = 7;
+pub(crate) type RowSource<'a> = (&'a Batch, usize);
 pub(crate) fn encode_fragment(
     schema: &Schema,
     rows: &[Vec<Value>],
+    sources: &[RowSource<'_>],
     texts: &mut SegmentTexts,
     grids: &mut Grids,
 ) -> Option<Vec<u8>>;
-fn mapped_states(rows: &[Vec<Value>], column: usize) -> Option<(Vec<u8>, Vec<u8>)>;
+pub(crate) fn view_bytes<'a>(family: &FieldDataType, sources: &[RowSource<'a>], column: usize) -> Option<Vec<Cow<'a, [u8]>>>;
+fn view_column_of(views: Vec<Cow<'_, [u8]>>) -> Option<(Vec<u8>, Vec<u8>)>;

crates/storage/src/persist.rs (private)

-fn window_rows(batches: &[Batch]) -> Option<Vec<Vec<Value>>>;
+fn window_rows(batches: &[Batch]) -> Option<(Vec<Vec<Value>>, Vec<RowSource<'_>>)>;

crates/query/src/lib.rs (private)

-fn query_time_slot(node: PhysicalASAPNodeId) -> anyhow::Result<MaterializedView>;
+fn query_time_slot(plan_id: &str, node: PhysicalASAPNodeId) -> anyhow::Result<MaterializedView>;

crates/data-plane/tests/planner_executor_parity.rs (test helper)

-fn from_oldest_of(served: BTreeMap<String, Vec<StoredWindow>>, expected: &BTreeMap<String, Vec<StoredWindow>>) -> BTreeMap<String, Vec<StoredWindow>>;
+fn within_retention(views: BTreeMap<String, Vec<StoredWindow>>, plan: &InstallablePlan) -> BTreeMap<String, Vec<StoredWindow>>;

Cargo.toml

-asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" }
+asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "566b35ca771e2283b1e93385105cd0401a9a67e6" }
 (same for asap-executor, asap-types)
-asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "389530ce23b121520f0218a4471e376db2c35945" }
+asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "d050037bb127d425cb4160ea9b5960856ef3188c" }
-[patch."https://github.com/ProjectASAP/asap_sketchlib"]
-asap_sketchlib = { git = "https://www.github.com/ProjectASAP/asap_sketchlib", rev = "355093f48f2649df1b86f2d390c2faa145a5f0a0" }

Behavior: before → after

Before (#884) After
Pins ASAPPlanner 1d527bc; asap_sketchlib 389530c, patched to 355093f ASAPPlanner 566b35c; asap_sketchlib d050037 (the Planner's pin, no patch)
View file format 4 5. A format 4 segment is renamed *.stale on open, with "a segment of another plan, group or format version (this data plane reads version 5)". The plan hash changes too, because plan files are now wire version 16.
A DDSketch window of 1,000 ten-sample series on disk 30,196 B (most of it the full-precision sum, min and max) 8,309 B
Writing a window's view states Each state's view rebuilt from a per-row object Read from the window batch's own state column: borrowed when it holds sealed views, written otherwise
Cold read of a persisted view Zero-copy (from_mapped) Zero-copy (from_views); same speed, see the benchmarks below

T2 test fix

T2 checks that push precompute stores the same view rows as the window path.

  • Problem: the test cut the push side's windows to those at or after the oldest window the window path held, then compared exactly. Windows older than a view's retention stay in the store by timing:

    • they leave lazily, at the view's next append;
    • a narrower level is held until its readers commit;
    • expired windows are skipped when the watermark jumps.

    So the count of old windows left at the end differs between runs and between the two modes. The cut only removed extra windows on the push side. When the window path kept an older window than push, the test failed, on a window that no query reads.

  • Example: on refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 7862cb6, sketch-plan-quantile-single (raw data not kept), view 1, 10 s panes, retention 300 s. Both sides hold 46 windows. The window path's oldest window ends at 1699998610000, push's at 1699998670000. The windows the store must keep (ending after 1699998900000) are the same on both sides.

  • Fix (test only): within_retention cuts both sides to the windows the store keeps by retention. Those are the windows ending less than retention_ms before the view's newest window, plus the newest itself (the store's oldest_kept_end rule). These must match exactly. No window that recent is ever skipped or evicted, in either mode, so the check no longer depends on timing. Windows past retention are no longer compared. No query reads them, and neither mode has to keep them.

  • Engine: no change. Eviction (storage::store push / oldest_kept_end) and expiry skipping (precompute::ingestion close_windows) never drop a window within retention, and queries read only those.

  • Since when: the test logic came with push precompute (feat(data_plane): tiered view storage, push precompute by default, faster Remote Write decode #864) and is the same on origin/main. It passes there (2 of 2 runs, 8263b22). In the layout stack it failed on every run (refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 7862cb6, 2 of 2). The window logic did not change, so this is the timing of the old windows, not a regression. The fix fits in the PR that added T2. It is committed here because this is the stack's top.

Before (7862cb6, cd7ffef) After (5f7b20c)
T2 alone failed 2 of 2 on each passed 20 of 20 (two idle hosts, 10 each, ~300 s a run)
T2 with the full suite running alongside listed as flaky passed 20 of 20 (two hosts, 10 each, cargo test --workspace looping alongside)
Windows compared per view push's from the window path's oldest window, against all of the window path's both sides' windows within retention, exactly

How verified

After the re-pin to 566b35c (head c619f61), against #884 659d53b:

At f2da999 (earlier, kept for reference):

  • Gate (fmt, clippy --workspace --all-targets -D warnings, full cargo test --workspace, ulimit -n 65536):

    • fmt and clippy are clean.
    • Tests on 5f7b20c (rebased onto refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 659d53b): 236 passed, 0 failed, 3 ignored. refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 659d53b also has 236 passed and 3 ignored. The restack deleted storage::boundary and its tests, so the count is lower than before the rebase.
    • T2 alone and under load: see "T2 test fix". Two more full-suite runs on another host: 236 passed, 0 failed each. One of the three suite passes that looped alongside T2 had one failing test. Its log was overwritten by the next pass, so the test is not known. The other two passes and the two reruns were clean.
    • The test names listed by cargo test --workspace -- --list match on both trees (243 each, including ignored), except state_codec::tests::a_ten_sample_ddsketch_state_takes_47_compact_bytes, which is renamed ..._23_compact_bytes for the smaller DDSketch head.
  • Parity dump against refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 (659d53b, rerun after the rebase; also byte-identical against 7862cb6 before it), same fixture as steps 5–9 plus a DDSketch query:

    • Queries:
      • sum by (job) (sum_over_time(data[10s]));
      • quantile_over_time(0.9, data[10s]) with a 5% accuracy target.
    • Each runs with and without --no-forward, covering planned, cached, not-ready (after the barrier) and unplanned queries, Remote Write 400 and empty-body responses, /api/v1/status/asap, the unconfigured ClickHouse/Elasticsearch routes, and the /metrics names and label sets.
    • Result: byte-identical (65,517 B on both trees). The Planner chose the same plans for these queries, so there are no plan-driven differences in the dump.
  • Benchmarks (measured before the rebase, against refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 7862cb6; release, one host, cores 0–15, base and new interleaved, 3 runs; runs 2–3 shown for view_read_bench because run 1 of the new tree was disturbed):

    Benchmark refactor: eval/scripts, eval/baselines and deployment Dockerfile (layout step 9) #884 This PR
    view_read_bench KLL, Pread cold (ns/row) 379 / 391 382 / 388
    view_read_bench KLL, Pread warm (ns/row) 345 / 347 342 / 344
    view_read_bench KLL, Mmap cold (ns/row) 411 / 441 421 / 414
    view_read_bench KLL, Mmap warm (ns/row) 341 / 343 335 / 337
    view_read_bench KLL, write (ns/row) 1,174 / 1,166 1,407 / 1,415
    decode_bench one series per sample (µs/sample) 0.105 0.106
    decode_bench 100 samples per series (µs/sample) 0.027 0.027
    ingest_bench 10000 120 views 1 persist, persist-thread CPU (s, 3 runs) 10.94 / 11.03 / 11.06 9.93 / 10.49 / 10.09
    ingest_bench, all-thread CPU (s, 3 runs) 24.93 / 25.08 / 25.05 23.26 / 23.81 / 23.48
    • Cold and warm view reads are unchanged (within run-to-run noise).
    • The KLL view write is about 20% slower (~240 ns/row). It is the window-sealing step on the persist thread, not the query path.
      • A profile shows no new backend hot spot.
      • A standalone microbench of asap_sketchlib's KLL to_view_bytes alone (its source is identical in both revs) takes 264 vs 238 ns/state at 01f3333 vs 355093f. That accounts for part of it.
      • An earlier version of this PR rebuilt a one-column batch per state column to get the views (1,690 ns/row). Reading views from the window's own batch removed that.
    • ingest_bench is not like for like. The new Planner plans its workload with 15 views instead of 11, so persisted bytes (5.90 → 6.11 MB per run) and CPU compare different plans. The new plan still spends less CPU.
  • Reviews: four independent reviews (correctness and parity, layering and naming, dead code and duplication, efficiency).

    • Fixed:
      • the missing plan_id / view_state_key in query_time_slot, a runtime install failure for plans with shared nodes;
      • stale DDSketch sizes in the storage tests;
      • "mapped layout" wording, renamed to the Planner's "view layout";
      • the MAPPED_STATES constant, renamed VIEW_STATES;
      • named DDSketch head offsets;
      • a redundant plain-type guard;
      • peak memory when packing view columns (each view is dropped once copied);
      • writes now read views from the window batch instead of rebuilding a batch;
      • the design doc placement and decision list for format 5.
    • Deferred: none.
  • Remote build and benchmark directories were deleted afterwards.

Design doc

docs/design/tiered-view-storage.md:

  • the header frame now says format version 5;
  • a short "Format version 5" paragraph closes "On-disk format";
  • the Decisions list gains format 5;
  • the 88-byte head is marked as 64 bytes from format 5.

README.md: the pin line.

@zzylol zzylol added area: data plane Runtime ingestion, storage, and query-serving data paths area: query engine PromQL lowering, execution, result shaping, and fallback behavior feature: PromQL PromQL compatibility and execution semantics labels Nov 28, 2026
@zzylol
zzylol force-pushed the refactor/layout-eval-deploy branch from 7862cb6 to 659d53b Compare November 28, 2026 00:56
Bump asap-planner, asap-executor and asap-types from 1d527bc to
f2da999 (main), and asap_sketchlib to 01f3333, the revision the Planner
pins, so cargo builds one copy; the [patch] to 355093f is dropped
(01f3333 contains it).

Planner API changes adapted:
- storage: view bytes via StateColumn::view_bytes (read from each
  window batch's own state column), cold reads via
  StateColumn::from_views, family_has_view_layout; the column kind is
  renamed VIEW_STATES (same code, 7).
- storage::state_codec: the compact DDSketch codec follows the new
  DDSketch view head (no sum, min, max; 64 bytes).
- FORMAT_VERSION 4 -> 5: format 4 segments are set aside on open.
- query: a shared query-time slot carries the plan's plan_id and a
  view_state_key, now required MaterializedView fields.
- SketchAlgorithm renames (KLL, CountMinSketch, HLL, ...) in tests and
  benches; plan files now name sketches by them (wire version 16).
push_precompute_stores_the_window_paths_view_rows trimmed the push side
to the oldest window the window path held and compared the rest
exactly. Windows older than a view's retention linger by timing (lazy
eviction at the next append, a narrower level held until its readers
commit, expired windows skipped when the watermark jumps), so when the
window path happened to keep an older window than push, the test failed
on a window no query reads.

Both sides are now cut to the windows the store keeps by retention
(ending less than retention_ms before the view's newest window, and the
newest), and these must match exactly. No such window is skipped or
evicted on either path, so the comparison no longer depends on timing.
566b35c includes #1518 (KLL and Count-Min sealed into view layouts) and
#1543 (DDSketch bounds once). asap_sketchlib d050037 is the rev it pins
(branch planner-pin/main-a05b35c-shrink-to-fit-dd-bounds). No backend
change: the stored view bytes are the library's to_view_bytes either
way, so FORMAT_VERSION stays 5.
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 area: query engine PromQL lowering, execution, result shaping, and fallback behavior feature: PromQL PromQL compatibility and execution semantics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant