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
15 changes: 14 additions & 1 deletion data_plane/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ pub struct EngineOptions {
/// once per evaluation time, as the plan says; `false` computes it in
/// every query's run (for comparison).
pub share_one_evaluation_results: bool,
/// Raw reads (of query and ingestion runs) return only the series a
/// `Scan`'s label predicates select ([`crate::label_selection`]);
/// `false` reads every series in the time range (for comparison). The
/// answers are the same.
pub label_pushdown: bool,
/// How long a query-time result is kept after its evaluation time,
/// counted back from the newest evaluation time computed.
pub query_time_results_retention_ms: u64,
Expand Down Expand Up @@ -215,6 +220,7 @@ impl Default for EngineOptions {
run_memory_limit_bytes: 4 << 30,
query_threads: std::thread::available_parallelism().map_or(1, usize::from),
share_one_evaluation_results: true,
label_pushdown: true,
query_time_results_retention_ms: 60_000,
query_time_results_max_bytes: 1 << 30,
result_cache: true,
Expand Down Expand Up @@ -403,7 +409,12 @@ impl EngineHandle {
/// invalid or the data plane cannot execute it.
pub fn spawn(plan_json: String, options: EngineOptions) -> anyhow::Result<(Self, Vec<String>)> {
let (mut ingestion, precompute, query, query_texts) = install(&plan_json, &options)?;
let precompute = Arc::new(precompute);
// The ingestion runs' raw reads follow the same pushdown switch as
// the query runs', counted apart.
let ingestion_raw_reads = Arc::new(crate::store::RawReadCounts::default());
let precompute = Arc::new(
precompute.with_raw_reads(options.label_pushdown, ingestion_raw_reads.clone()),
);
// Push mode: the groups the shards build by push.
let push_groups: Vec<Option<PushGroup>> = match options.precompute_mode {
PrecomputeMode::Window => vec![None; precompute.groups().len()],
Expand Down Expand Up @@ -467,6 +478,8 @@ impl EngineHandle {
.map(|(width_ms, views)| (width_ms, views.iter().map(ToString::to_string).collect()))
.collect();
let mut metrics = Metrics::new(&groups, &query_texts);
let query = query.with_raw_reads(options.label_pushdown, metrics.query_raw_reads.clone());
metrics.ingestion_raw_reads = ingestion_raw_reads;
if let Some(tier) = &tier {
let _ = metrics.view_tier.set(tier.clone());
}
Expand Down
28 changes: 26 additions & 2 deletions data_plane/src/ingestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ use asap_executor::values::{Batch, SchemaRef};
use futures::executor::block_on;

use crate::prometheus::MAX_TIME_MS;
use crate::store::{RawData, RawSample, RawShards, RunStore, SeriesPartition, ViewStore};
use crate::store::{
RawData, RawReadCounts, RawSample, RawShards, RunStore, SeriesPartition, ViewStore,
};

/// How ingestion treats sample times.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -365,6 +367,8 @@ impl Ingestion {
runs,
tasks,
limits,
label_pushdown: true,
raw_read_counts: None,
},
))
}
Expand Down Expand Up @@ -923,9 +927,22 @@ pub struct Precompute {
runs: Vec<RefreshGroupRun>,
tasks: RefreshTaskGraph,
limits: Limits,
/// Whether the runs' raw reads select series by the `Scan`'s label
/// predicates ([`crate::label_selection`]); default true.
label_pushdown: bool,
/// Where the runs count their raw reads' rows; `None`: not counted.
raw_read_counts: Option<Arc<RawReadCounts>>,
}

impl Precompute {
/// The runs' raw reads select series by the `Scan`'s label predicates
/// when `label_pushdown`, and count their rows in `counts`.
pub fn with_raw_reads(mut self, label_pushdown: bool, counts: Arc<RawReadCounts>) -> Self {
self.label_pushdown = label_pushdown;
self.raw_read_counts = Some(counts);
self
}

/// Runs `window`'s group's views in one ingestion run over
/// `(end - W, end]`, reading `raw_data` (as it was when the window
/// closed) and `views`, and appends each view's rows to `views`. A view
Expand Down Expand Up @@ -972,7 +989,14 @@ impl Precompute {
return Ok(Computed::AlreadyStored);
}
let outputs = {
let store = Arc::new(RunStore::for_partition(raw_data, views, partition));
let mut store = RunStore::for_partition(raw_data, views, partition);
if !self.label_pushdown {
store = store.without_label_pushdown();
}
if let Some(counts) = &self.raw_read_counts {
store = store.with_raw_read_counts(counts.clone());
}
let store = Arc::new(store);
let instance = group.compiled.instantiate(store)?;
let context = RunContext::new(
Scope::Ingestion {
Expand Down
Loading