Skip to content

Commit 322e85e

Browse files
committed
DNM Debugging: Assert various read hold stuff
1 parent 7d7d75f commit 322e85e

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

src/adapter/src/coord/timeline.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,13 @@ pub(crate) fn timedomain_for<'a, I>(
411411
where
412412
I: IntoIterator<Item = &'a GlobalId>,
413413
{
414+
let mut orig_uses_ids = Vec::new();
415+
414416
// Gather all the used schemas.
415417
let mut schemas = BTreeSet::new();
416418
for id in uses_ids {
419+
orig_uses_ids.push(id.clone());
420+
417421
let entry = catalog.get_entry_by_global_id(id);
418422
let name = entry.name();
419423
schemas.insert((name.qualifiers.database_spec, name.qualifiers.schema_spec));
@@ -452,6 +456,15 @@ where
452456
collection_ids.extend(global_ids);
453457
}
454458

459+
{
460+
// Assert that we got back a superset of the original ids.
461+
// This should be true, because the query is able to reference only the latest version of
462+
// each object.
463+
for id in orig_uses_ids.iter() {
464+
assert!(collection_ids.contains(id));
465+
}
466+
}
467+
455468
// Gather the dependencies of those items.
456469
let mut id_bundle: CollectionIdBundle = dataflow_builder.sufficient_collections(collection_ids);
457470

src/adapter/src/frontend_peek.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ use std::collections::BTreeMap;
1111
use std::collections::BTreeSet;
1212
use std::sync::Arc;
1313

14-
use itertools::Either;
14+
use itertools::{Either, Itertools};
1515
use mz_adapter_types::dyncfgs::CONSTRAINT_BASED_TIMESTAMP_SELECTION;
1616
use mz_adapter_types::timestamp_selection::ConstraintBasedTimestampSelection;
17+
use mz_compute_client::controller::error::DataflowCreationError::SinceViolation;
1718
use mz_compute_types::ComputeInstanceId;
1819
use mz_expr::{CollectionPlan, ResultSpec};
1920
use mz_ore::cast::{CastFrom, CastLossy};
21+
use mz_ore::collections::CollectionExt;
2022
use mz_ore::now::EpochMillis;
2123
use mz_repr::optimize::{OptimizerFeatures, OverrideFrom};
2224
use mz_repr::role_id::RoleId;
@@ -30,6 +32,7 @@ use mz_sql_parser::ast::{CopyDirection, ExplainStage, Statement};
3032
use mz_transform::EmptyStatisticsOracle;
3133
use mz_transform::dataflow::DataflowMetainfo;
3234
use opentelemetry::trace::TraceContextExt;
35+
use timely::PartialOrder;
3336
use tracing::{Span, debug};
3437
use tracing_opentelemetry::OpenTelemetrySpanExt;
3538

@@ -578,6 +581,36 @@ impl PeekClient {
578581
}
579582
};
580583

584+
{
585+
// Assert that we have a read hold for all the collections in our `input_id_bundle`.
586+
for id in input_id_bundle.iter() {
587+
let s = read_holds.storage_holds.contains_key(&id);
588+
let c = read_holds
589+
.compute_ids()
590+
.map(|(_instance, coll)| coll)
591+
.contains(&id);
592+
assert!(s || c);
593+
}
594+
595+
// Assert that the each part of the `input_id_bundle` corresponds to the right part of
596+
// `read_holds`.
597+
for id in input_id_bundle.storage_ids.iter() {
598+
assert!(read_holds.storage_holds.contains_key(id));
599+
}
600+
for id in input_id_bundle
601+
.compute_ids
602+
.iter()
603+
.flat_map(|(_instance, colls)| colls)
604+
{
605+
assert!(
606+
read_holds
607+
.compute_ids()
608+
.map(|(_instance, coll)| coll)
609+
.contains(id)
610+
);
611+
}
612+
}
613+
581614
// (TODO(peek-seq): The below TODO is copied from the old peek sequencing. We should resolve
582615
// this when we decide what to with `AS OF` in transactions.)
583616
// TODO: Checking for only `InTransaction` and not `Implied` (also `Started`?) seems
@@ -981,6 +1014,34 @@ impl PeekClient {
9811014
.await?
9821015
}
9831016
PeekPlan::SlowPath(dataflow_plan) => {
1017+
{
1018+
// Assert that we have some read holds for all the imports of the dataflow.
1019+
for id in dataflow_plan.desc.source_imports.keys() {
1020+
assert!(read_holds.storage_holds.contains_key(id));
1021+
}
1022+
for id in dataflow_plan.desc.index_imports.keys() {
1023+
assert!(
1024+
read_holds
1025+
.compute_ids()
1026+
.map(|(_instance, coll)| coll)
1027+
.contains(id)
1028+
);
1029+
}
1030+
1031+
// Also check the holds against the as_of. (plus other minor things)
1032+
for (id, h) in read_holds.storage_holds.iter() {
1033+
assert_eq!(*id, h.id);
1034+
let as_of = dataflow_plan.desc.as_of.unwrap().into_element();
1035+
assert!(h.since.less_equal(&as_of));
1036+
}
1037+
for ((instance, id), h) in read_holds.compute_holds.iter() {
1038+
assert_eq!(*id, h.id);
1039+
assert_eq!(*instance, target_cluster_id);
1040+
let as_of = dataflow_plan.desc.as_of.unwrap().into_element();
1041+
assert!(h.since.less_equal(&as_of));
1042+
}
1043+
}
1044+
9841045
self.call_coordinator(|tx| Command::ExecuteSlowPathPeek {
9851046
dataflow_plan: Box::new(dataflow_plan),
9861047
determination,

src/storage-types/src/read_holds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ pub type ChangeTx<T> = Arc<
3131
/// the issuer behind the scenes.
3232
pub struct ReadHold<T: TimelyTimestamp> {
3333
/// Identifies that collection that we have a hold on.
34-
id: GlobalId,
34+
pub id: GlobalId,
3535

3636
/// The times at which we hold.
37-
since: Antichain<T>,
37+
pub since: Antichain<T>,
3838

3939
/// For communicating changes to this read hold back to whoever issued it.
4040
change_tx: ChangeTx<T>,

0 commit comments

Comments
 (0)