Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ version = "0.1.0"
# `asap-planner` to plan, `asap-executor` to execute, and `asap-types` for
# the plan types `common`'s boundary names (such as `QueryLanguage`).
# Elsewhere, Planner IR types are reached through `asap_executor::planner`.
asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" }
asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" }
asap-types = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "1d527bca445b6372f0eb72aafd725d04a3a77dfb" }
asap-planner = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "566b35ca771e2283b1e93385105cd0401a9a67e6" }
asap-executor = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "566b35ca771e2283b1e93385105cd0401a9a67e6" }
asap-types = { git = "https://github.com/ProjectASAP/ASAPPlanner", rev = "566b35ca771e2283b1e93385105cd0401a9a67e6" }
# The sketch library the Planner's executor pins, for the byte encodings of
# the sketch states the data plane persists; keep it at the Planner's rev
# (here overridden below for the executor too).
asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "389530ce23b121520f0218a4471e376db2c35945" }
# the sketch states the data plane persists; keep it at exactly the Planner's
# rev, so cargo builds one copy for both.
asap_sketchlib = { git = "https://github.com/ProjectASAP/asap_sketchlib", rev = "d050037bb127d425cb4160ea9b5960856ef3188c" }

serde = { version = "1.0", features = ["derive"] }
# `float_roundtrip`: a plan file reloads to the plan it was written from
Expand All @@ -58,10 +58,3 @@ prometheus_remote_write = { path = "crates/adapters/ingest/prometheus-remote-wri
query = { path = "crates/query" }
storage = { path = "crates/storage" }
victoriametrics_remote_write = { path = "crates/adapters/ingest/victoriametrics-remote-write" }

# asap_sketchlib#271's head, ahead of the Planner's pin (389530c): DDSketch
# view merges in place, with width-specialized loops (a 1 h quantile over
# cold windows 3x faster). Drop when the Planner's pin moves past it. The
# `www.` URL is a distinct source, so it may patch the one the Planner names.
[patch."https://github.com/ProjectASAP/asap_sketchlib"]
asap_sketchlib = { git = "https://www.github.com/ProjectASAP/asap_sketchlib", rev = "355093f48f2649df1b86f2d390c2faa145a5f0a0" }
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test --workspace --locked
```

The Planner revision is pinned in `Cargo.toml` (ASAPPlanner `1d527bc` for
`asap-planner`, `asap-executor` and `asap-types`; `asap_sketchlib` patched to
`355093f`); see
The Planner revision is pinned in `Cargo.toml` (ASAPPlanner `566b35c`; `asap_sketchlib` at
the Planner's own pin, `d050037`); see
[scripts/ci/README.md](scripts/ci/README.md).
11 changes: 9 additions & 2 deletions benchmarks/micro/tier_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ async fn main() {
let plan_text = serde_json::to_string(&plan).unwrap();
println!(
"plan states (mentions): {:?}",
["DDSketch", "\"Kll\"", "Hll", "Cms", "Counter", "Max"]
.map(|k| (k, plan_text.matches(k).count()))
[
"DDSketch",
"\"KLL\"",
"\"HLL\"",
"CountMinSketch",
"Counter",
"Max"
]
.map(|k| (k, plan_text.matches(k).count()))
);

let now_ms = std::time::SystemTime::now()
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/micro/view_read_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
let _ = std::fs::remove_dir_all(&dir);

let family = match family_name {
"kll" => FieldDataType::Sketch(SketchAlgorithm::Kll),
"kll" => FieldDataType::Sketch(SketchAlgorithm::KLL),
"ddsketch" => FieldDataType::Sketch(SketchAlgorithm::DDSketch),
"counter" => FieldDataType::ExactAggregate(ExactKind::Counter, ExactParams::Counter),
other => panic!("unknown family {other}: kll, ddsketch or counter"),
Expand Down
60 changes: 38 additions & 22 deletions crates/data-plane/tests/planner_executor_parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ fn same_within(a: &[Answer], b: &[Answer], relative: f64) -> bool {
fn tolerance(plan: &InstallablePlan) -> f64 {
let randomized = serde_json::to_string(&plan.dag)
.unwrap()
.contains("\"Kll\"");
.contains("\"KLL\"");
if randomized {
0.05
} else {
Expand Down Expand Up @@ -1055,26 +1055,41 @@ fn shapes(views: &BTreeMap<String, Vec<StoredWindow>>) -> BTreeMap<String, Vec<W
.collect()
}

/// `served`'s windows of each view from the oldest window `expected` holds
/// of it. Windows past a view's retention leave the store lazily (at the
/// view's next append), and a narrower level is held until its readers
/// commit, so how many such windows linger at the end of a run depends on
/// the order windows were committed in, which differs between push and the
/// window path; and windows that far back are skipped when the watermark
/// jumps past them, which depends on when each shard reports. Neither is
/// read by a query.
fn from_oldest_of(
served: BTreeMap<String, Vec<StoredWindow>>,
expected: &BTreeMap<String, Vec<StoredWindow>>,
/// Each view's windows within its retention of its newest window: those
/// ending less than `retention_ms` before it, and the newest itself (the
/// windows the store keeps by retention, `storage::store`'s
/// `oldest_kept_end`). Both data planes must hold exactly these: no window
/// that recent is skipped as expired or evicted. Older windows leave the
/// store lazily (at the view's next append), and a narrower level is held
/// until its readers commit, so how many such windows linger at the end of
/// a run depends on the order windows were committed in and on when each
/// shard reported, which differ between push and the window path and from
/// run to run; and no query reads them.
fn within_retention(
views: BTreeMap<String, Vec<StoredWindow>>,
plan: &InstallablePlan,
) -> BTreeMap<String, Vec<StoredWindow>> {
served
let retention_ms: BTreeMap<String, i64> = plan
.ingestion_refresh_groups()
.unwrap()
.iter()
.flat_map(|group| &group.views)
.map(|view| {
let retention = i64::try_from(view.retention_ms()).unwrap_or(i64::MAX);
(format!("{}", view.node_id), retention)
})
.collect();
views
.into_iter()
.map(|(view, windows)| {
let oldest = expected
.get(&view)
.and_then(|w| w.first())
.map_or(i64::MIN, |w| w.0 .1);
let windows = windows.into_iter().filter(|w| w.0 .1 >= oldest).collect();
let newest_end = windows.last().map_or(i64::MIN, |w| w.0 .1);
// A view of no refresh group keeps every window.
let retention = retention_ms.get(&view).copied().unwrap_or(i64::MAX);
let oldest_kept_end = newest_end.saturating_sub(retention);
let windows = windows
.into_iter()
.filter(|w| w.0 .1 > oldest_kept_end || w.0 .1 == newest_end)
.collect();
(view, windows)
})
.collect()
Expand Down Expand Up @@ -1120,8 +1135,9 @@ fn first_difference(
"shapes differ".into()
}

/// T2. Push precompute stores the same view rows as the window path: per
/// (view, window), the same keys and the same states (exact values, or
/// T2. Push precompute stores the same view rows as the window path: the
/// same windows within each view's retention, and per (view, window) the
/// same keys and the same states (exact values, or
/// sketch bytes). KLL plans store the same windows and keys; their states
/// may differ within the target, which T1 checks through the answers.
#[tokio::test(flavor = "multi_thread")]
Expand All @@ -1148,8 +1164,8 @@ async fn push_precompute_stores_the_window_paths_view_rows() {
data_plane_over(&plan, &points, start_ms, false, window, Views::InMemory).await;
let (_, by_push) =
data_plane_over(&plan, &points, start_ms, false, push, Views::InMemory).await;
let expected = stored_views(&by_window);
let served = from_oldest_of(stored_views(&by_push), &expected);
let expected = within_retention(stored_views(&by_window), &plan);
let served = within_retention(stored_views(&by_push), &plan);
compared_views += expected.len();
let equal = if tolerance(&plan) > 1e-9 {
shapes(&expected) == shapes(&served)
Expand Down
2 changes: 1 addition & 1 deletion crates/data-plane/tests/push_precompute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ async fn per_series_breakers_are_concatenated() {
}
let randomized = serde_json::to_string(&plan.dag)
.unwrap()
.contains("\"Kll\"");
.contains("\"KLL\"");
if randomized {
// KLL compacts at random: same windows and keys, answers within 5%
// (T1); here only the shape.
Expand Down
2 changes: 1 addition & 1 deletion crates/data-plane/tests/view_persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async fn kll_views_answer_alike_after_a_restart() {
.unwrap();
let plan = plan_workload(&workload, &common::inputs(false)).unwrap().0;
let plan = serde_json::to_string(&plan).unwrap();
assert!(plan.contains("Kll"), "the plan builds no KLL");
assert!(plan.contains("\"KLL\""), "the plan builds no KLL");
answers_alike_after_a_restart("kll", query, &plan).await;
}

Expand Down
16 changes: 12 additions & 4 deletions crates/query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ impl CompiledQueries {
BTreeSet::new()
};
let mut slots: Vec<MaterializedView> = views.to_vec();
for &node in &shared {
slots.push(query_time_slot(node)?);
if !shared.is_empty() {
let plan_id = dag.plan_id();
for &node in &shared {
slots.push(query_time_slot(&plan_id, node)?);
}
}
let mut compiled: BTreeMap<PhysicalASAPNodeId, Result<Run, String>> = BTreeMap::new();
for &node in shared.iter().chain(&dag.roots) {
Expand Down Expand Up @@ -471,11 +474,16 @@ fn scans_below(
}

/// The view slot a shared node is bound as: its whole output at the run's
/// evaluation time, refreshed on first read and kept for that evaluation.
fn query_time_slot(node: PhysicalASAPNodeId) -> anyhow::Result<MaterializedView> {
/// evaluation time, refreshed on first read and kept for that evaluation;
/// a view of plan `plan_id` (`PhysicalASAPDAG::plan_id`) whose state key
/// names only that node.
fn query_time_slot(plan_id: &str, node: PhysicalASAPNodeId) -> anyhow::Result<MaterializedView> {
Ok(serde_json::from_value(serde_json::json!({
"node_id": node,
"refresh": "on_first_read",
"plan_id": plan_id,
"view_state_key": {"definition_id": format!("query-time-result-{node}"), "window": null,
"logical_properties": {"parameters": null}},
"coverage": {"definition_id": format!("query-time-result-{node}"), "selection": []},
"inputs": {"materialized_views": []},
"retention_ms": 0,
Expand Down
Loading