Skip to content

fix(query-time results): keep a shared node's result when it reads only views - #898

Draft
zzylol wants to merge 2 commits into
feat/collector-views-filefrom
fix/query-time-results-views-only
Draft

zzylol wants to merge 2 commits into
feat/collector-views-filefrom
fix/query-time-results-views-only

Conversation

@zzylol

@zzylol zzylol commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: a query-time OneEvaluation result (for example, the 1-minute SummaryMerge that several quantile queries share) was kept only at evaluation times at or before the raw-data watermark. A data plane whose views all come from a collector has no raw data, so it has no watermark. Every query run then recomputed the shared merge.
  • Change: a result of a shared node that reads only views is kept at any time, under the same rule the result cache uses for a root's final answer. A successful run means every window it read was stored, and a stored window changes only through a revision, which the entry's revision check already catches. A node that reads raw data keeps the watermark rule.
  • Effect: on the live demo workload W3 (four DDSketch quantile queries over 10k series at 10 samples/s, asked every 5 s), the collector arm's ASAPQuery-backend falls from 0.222 to 0.122 cores. Query-time computes per 5 s tick fall from 6 to 2. Answers and A == B are unchanged.

Review guide

Behavior: before → after

The workload has four quantile_over_time(q, data[1m]) / max(...) queries at a 5% target, every 5 s. The plan shares one SummaryMerge (the 1-minute merge of 5 s DDSketch windows) and one Project. In the collector arm, the views come from collector states and no raw samples are stored.

per 5 s tick, collector arm before after
query-time result computes / hits 6 / 0 2 / 3
query-* thread CPU 0.80 s 0.35 s
ASAPQuery-backend CPU (10-minute steady state) 0.222 cores 0.122 cores

The raw-ingest arm already shared most results through its watermark: 0.194 → 0.193 cores. Now it also keeps results at times the watermark has not yet reached.

Interfaces

crates/storage/src/store.rs

 impl<E: Clone> QueryTimeResults<E> {
     /// `node`'s output at `time_ms`, as of `views`: stored, or computed now
     /// by `compute` (once, however many runs ask at once, when `node` reads
     /// only views, `reads_raw_data` false, or `time_ms` is at or before
     /// `watermark_ms`; by each run otherwise).
     pub fn get_or_compute(
         &self,
         node: PhysicalASAPNodeId,
         time_ms: i64,
         watermark_ms: Option<i64>,
+        reads_raw_data: bool,
         views: &ViewStore,
         compute: impl FnOnce() -> Result<Vec<Batch>, E>,
     ) -> Result<Arc<Vec<Batch>>, E>;
 }

Usage: an instant query quantile_over_time(0.5, data[1m]) at T reaches CompiledQueries::output for the shared SummaryMerge node. That call is now results.get_or_compute(merge, T, snapshot.watermark_ms /* None: no raw data */, false /* reads only views */, &snapshot.views, run). The first query at T computes the merge, and the other three read it. This is checked by queries_sharing_a_merge_of_collector_windows_compute_it_once (1 compute, 1 hit) and on the live demo (2 computes, 3 hits per tick).

Algorithm changes

Keep rule of the query-time partition.

  • Before:
    1. A result is kept only if time_ms <= watermark.
    2. Otherwise each run computes it.
    3. Retention counts back from the watermark.
  • After:
    1. A node that reads raw data (a Scan reached without passing a view) keeps step 1.
    2. A node that reads only views is kept at any time.
    3. Retention counts back from the later of the watermark and the time just kept. That time is a successful run's time, so it is never a client's far-future time: such a run fails on a missing window and moves nothing.
  • Correctness: a view range read fails unless the stored windows tile the range exactly (ViewStore::read). So a kept result read only stored windows. A window changes only through merge_late, replace_window or mark_incomplete, which all call revised. changed_since then makes the entry stale. This is the same reasoning CompiledQueries::evaluate already applies to the result cache's final answers.
  • Complexity: unchanged per call. Memory: the collector arm now holds query-time results (91 MB of results, bounded by the existing retention and max_bytes). Before, it held none.

Decisions and open questions

None.

Verification

scope result notes
data_plane --test collector_views 14 passed new: queries_sharing_a_merge_of_collector_windows_compute_it_once, failing first with (computes, hits) = (2, 0)
data_plane --test shared_results 2 passed
data_plane suites range_isolation, no_forward, push_precompute, planner_executor_answers, server, query_protocols, result_cache, range_queries 56 passed, 3 ignored ignored tests were ignored on the base too
storage --lib query_time_results 2 passed new: query_time_results_of_a_node_reading_only_views_need_no_watermark (kept without a watermark; a failed far-future run keeps nothing and evicts nothing; retention from the newest time kept)
query (all) 4 passed
cargo fmt --check; cargo clippy -p storage -p query -p data_plane --all-targets -D warnings clean

Live demo (10-minute steady state each, same host, same feed, measured from per-process CPU and RSS; binary = #893 + #894 + this PR + the collector label-columns fix):

before after
A: ASAPQuery-backend CPU 0.222 cores 0.122 cores
B: ASAPQuery-backend CPU 0.194 cores 0.193 cores
A: ASAPQuery-backend RSS, mean 249 MiB 283 MiB (now holds shared results)
A == B ratio, every query (120 samples each) 1.0000 1.0000
within 5 % of Prometheus, min 1.000 1.000

A perf profile before the fix (30 s at 499 Hz) showed 78% of A's samples on the query-* threads, against 39% for B.

Follow-ups

  • Not in this PR: in both arms, the profile puts about 14% of the process's samples in <Vec<u8> as Debug>::fmt, instantiated in ASAPPlanner's asap_executor. The likely caller is group_seed (operators/summary), which hashes format!("{:?}", label) for each group. It is the only {:?} formatting on the operators' per-group path. Hashing the key bytes directly would avoid it, but that code belongs to the ASAPPlanner repository.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf

zzylol and others added 2 commits November 30, 2026 15:52
…s compute it once (failing first)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
…ly views

A query-time OneEvaluation result was kept only at a time at or before
the raw-data watermark. A node reading only views (a merge of collector
view windows; with no raw data there is no watermark at all) was then
computed again by every query run that read it. Its run succeeding
means every window it read was stored, and a stored window changes only
by a revision, which the entry's revision check already catches: the
same rule the result cache applies to a root's final answer. Retention
counts back from the watermark or the newest time kept, never from a
client's time no stored window reaches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bo8kYWd83zXwh2Nobf
@zzylol zzylol added bug Something isn't working area: data plane Runtime ingestion, storage, and query-serving data paths area: query engine PromQL lowering, execution, result shaping, and fallback behavior labels Nov 30, 2026
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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant