Skip to content

Commit 7c8dd4a

Browse files
committed
DNM Debugging: Assert various read hold stuff
1 parent 79b43b7 commit 7c8dd4a

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,13 @@ 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;
1717
use mz_compute_types::ComputeInstanceId;
1818
use mz_expr::{CollectionPlan, ResultSpec};
1919
use mz_ore::cast::{CastFrom, CastLossy};
20+
use mz_ore::collections::CollectionExt;
2021
use mz_ore::now::EpochMillis;
2122
use mz_repr::optimize::{OptimizerFeatures, OverrideFrom};
2223
use mz_repr::role_id::RoleId;
@@ -578,6 +579,36 @@ impl PeekClient {
578579
}
579580
};
580581

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