Skip to content
Draft
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
98 changes: 98 additions & 0 deletions data_plane/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,20 @@ impl RawData {
request: &RawDataRequest,
reads: Option<&RawReads>,
partition: Option<&PartitionReads>,
) -> Result<RawRead, Error> {
self.read_with(metric, request, reads, partition, 1)
}

/// [`Self::read`] with its chunks converted on up to `parallelism`
/// worker-pool threads: the same batches in the same order (spec
/// `parallel-query-exec`, I6). STUB: reads on the calling thread.
pub(crate) fn read_with(
&self,
metric: &str,
request: &RawDataRequest,
reads: Option<&RawReads>,
partition: Option<&PartitionReads>,
_parallelism: usize,
) -> Result<RawRead, Error> {
let columns = column_kinds(metric, request)?;
let Some(metric_data) = self.by_metric.get(metric) else {
Expand Down Expand Up @@ -743,6 +757,7 @@ impl RawData {
Ok(RawRead {
batches,
rows_in_time_range,
chunk_tasks: 0,
})
}
}
Expand Down Expand Up @@ -840,6 +855,9 @@ impl SeriesVerdicts {
pub(crate) struct RawRead {
pub batches: Vec<Batch>,
pub rows_in_time_range: u64,
/// Chunks the read converted on the worker pool (0: read on the
/// calling thread).
pub chunk_tasks: usize,
}

/// Rows of the raw reads of some runs (the query runs: `/metrics`):
Expand Down Expand Up @@ -2991,6 +3009,86 @@ mod tests {
}
}

/// D1 (spec `parallel-query-exec`, I6): a read whose chunks are
/// converted on the worker pool returns the sequential read's batches,
/// cell for cell and in order, and its rows in the time range: a metric
/// and a keyed table, with key and field predicates, with and without
/// the read cache, and with a series partition; at parallelism 4 the
/// chunks ran as pool tasks.
#[test]
fn a_chunk_parallel_read_equals_the_sequential_read() {
let schema = schema();
let all: Vec<RawSample> = samples().into_iter().flatten().collect();
let mut metric = RawData::for_metrics(&["m_store_test".to_string()], 5_000);
metric.append(&all);
metric.seal_through(20_000);
let requests = table_rows();
let mut keyed = table_data(&requests.iter().map(|r| keyed_layout(r)).collect::<Vec<_>>());
keyed.seal_through(20_000);
let table = table_schema();
let field_and_key = [text_is(1, &["a"]), text_is(2, &["i1", "i4"])];
let field = [text_is(2, &["i5", "i2"])];
let cases: Vec<(
&RawData,
&str,
&Arc<Schema>,
&[ScalarExpr<()>],
Option<(i64, i64)>,
)> = vec![
(&metric, "m_store_test", &schema, &[], None),
(
&metric,
"m_store_test",
&schema,
&[],
Some((12_000, 27_000)),
),
(&keyed, TABLE, &table, &[], None),
(&keyed, TABLE, &table, &field_and_key, None),
(&keyed, TABLE, &table, &field, Some((2_100, 27_001))),
];
let partition = PartitionReads::new(SeriesPartition { index: 1, count: 3 });
for (raw, name, schema, predicates, range) in cases {
let request = RawDataRequest {
time_range_ms: range,
schema,
predicates,
};
for (shared, part) in [(false, None), (true, None), (false, Some(&partition))] {
let cache = RawReads::default();
let reads = shared.then_some(&cache);
let sequential = raw.read_with(name, &request, reads, part, 1).unwrap();
assert_eq!(sequential.chunk_tasks, 0);
let cache = RawReads::default();
let reads = shared.then_some(&cache);
let parallel = raw.read_with(name, &request, reads, part, 4).unwrap();
let label = format!(
"{name} {range:?} {} predicates, shared {shared}, partition {}",
predicates.len(),
part.is_some()
);
assert_eq!(
parallel.rows_in_time_range, sequential.rows_in_time_range,
"{label}"
);
assert_eq!(parallel.batches.len(), sequential.batches.len(), "{label}");
for (a, b) in parallel.batches.iter().zip(&sequential.batches) {
assert_eq!(
format!("{:?}", a.to_rows()),
format!("{:?}", b.to_rows()),
"{label}"
);
}
if sequential.batches.len() > 1 {
assert!(
parallel.chunk_tasks > 0,
"{label}: chunks not read on the pool"
);
}
}
}
}

/// Eviction drops the panes ending at or before the cutoff, keeps the
/// pane the cutoff falls in, and no read returns a sample at or
/// before the cutoff: a read of a range starting before it fails (its
Expand Down