Skip to content

Commit da0dd0a

Browse files
Add dedup proto converter debug tracing
1 parent c196a6d commit da0dd0a

1 file changed

Lines changed: 52 additions & 3 deletions

File tree

  • datafusion/proto/src/physical_plan

datafusion/proto/src/physical_plan/mod.rs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,6 +3820,12 @@ impl DeduplicatingSerializer {
38203820
}
38213821
}
38223822

3823+
fn dedup_debug_enabled() -> bool {
3824+
std::env::var("DD_DF_PROTO_DEBUG")
3825+
.map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
3826+
.unwrap_or(false)
3827+
}
3828+
38233829
impl PhysicalProtoConverterExtension for DeduplicatingSerializer {
38243830
fn proto_to_execution_plan(
38253831
&self,
@@ -3872,6 +3878,12 @@ impl PhysicalProtoConverterExtension for DeduplicatingSerializer {
38723878
proto.dynamic_filter_inner_id = Some(self.hash(dynamic_filter.inner_id()))
38733879
}
38743880
proto.expr_id = Some(self.hash(Arc::as_ptr(expr) as *const () as u64));
3881+
if dedup_debug_enabled() && proto.dynamic_filter_inner_id.is_some() {
3882+
eprintln!(
3883+
"[df-proto][ser] dynamic expr_id={:?} dynamic_filter_inner_id={:?} expr={expr}",
3884+
proto.expr_id, proto.dynamic_filter_inner_id
3885+
);
3886+
}
38753887

38763888
Ok(proto)
38773889
}
@@ -3924,12 +3936,24 @@ impl PhysicalProtoConverterExtension for DeduplicatingDeserializer {
39243936
if let Some(expr_id) = proto.expr_id
39253937
&& let Some(cached) = self.cache.borrow().get(&expr_id)
39263938
{
3939+
if dedup_debug_enabled() && proto.dynamic_filter_inner_id.is_some() {
3940+
eprintln!(
3941+
"[df-proto][de] cache_hit expr_id={expr_id} dynamic_filter_inner_id={:?}",
3942+
proto.dynamic_filter_inner_id
3943+
);
3944+
}
39273945
return Ok(Arc::clone(cached));
39283946
}
39293947

39303948
// Cache miss, we must deserialize the expr.
39313949
let mut expr =
39323950
parse_physical_expr_with_converter(proto, ctx, input_schema, codec, self)?;
3951+
if dedup_debug_enabled() && proto.dynamic_filter_inner_id.is_some() {
3952+
eprintln!(
3953+
"[df-proto][de] cache_miss expr_id={:?} dynamic_filter_inner_id={:?}",
3954+
proto.expr_id, proto.dynamic_filter_inner_id
3955+
);
3956+
}
39333957

39343958
// Check if we need to share inner state with a cached dynamic filter
39353959
if let Some(dynamic_filter_id) = proto.dynamic_filter_inner_id {
@@ -3951,11 +3975,21 @@ impl PhysicalProtoConverterExtension for DeduplicatingDeserializer {
39513975
.map_err(|_| internal_datafusion_err!("dynamic_filter_id present in proto, but the expression was not a DynamicFilterPhysicalExpr"))?;
39523976
expr = Arc::new(dynamic_filter_expr.new_from_source(cached_df)?)
39533977
as Arc<dyn PhysicalExpr>;
3978+
if dedup_debug_enabled() {
3979+
eprintln!(
3980+
"[df-proto][de] relinked dynamic_filter_inner_id={dynamic_filter_id} from cached source"
3981+
);
3982+
}
39543983
} else {
39553984
// Cache it
39563985
self.dynamic_filter_cache
39573986
.borrow_mut()
39583987
.insert(dynamic_filter_id, Arc::clone(&expr));
3988+
if dedup_debug_enabled() {
3989+
eprintln!(
3990+
"[df-proto][de] seeded dynamic_filter_inner_id={dynamic_filter_id} into cache"
3991+
);
3992+
}
39593993
}
39603994
};
39613995

@@ -4001,8 +4035,16 @@ impl PhysicalProtoConverterExtension for DeduplicatingProtoConverter {
40014035
codec: &dyn PhysicalExtensionCodec,
40024036
proto: &protobuf::PhysicalPlanNode,
40034037
) -> Result<Arc<dyn ExecutionPlan>> {
4038+
if dedup_debug_enabled() {
4039+
eprintln!("[df-proto][plan-de] start");
4040+
}
40044041
let deserializer = DeduplicatingDeserializer::default();
4005-
proto.try_into_physical_plan_with_converter(ctx, codec, &deserializer)
4042+
let plan =
4043+
proto.try_into_physical_plan_with_converter(ctx, codec, &deserializer)?;
4044+
if dedup_debug_enabled() {
4045+
eprintln!("[df-proto][plan-de] done plan={}", plan.name());
4046+
}
4047+
Ok(plan)
40064048
}
40074049

40084050
fn execution_plan_to_proto(
@@ -4013,12 +4055,19 @@ impl PhysicalProtoConverterExtension for DeduplicatingProtoConverter {
40134055
where
40144056
Self: Sized,
40154057
{
4058+
if dedup_debug_enabled() {
4059+
eprintln!("[df-proto][plan-ser] start plan={}", plan.name());
4060+
}
40164061
let serializer = DeduplicatingSerializer::new();
4017-
protobuf::PhysicalPlanNode::try_from_physical_plan_with_converter(
4062+
let proto = protobuf::PhysicalPlanNode::try_from_physical_plan_with_converter(
40184063
Arc::clone(plan),
40194064
codec,
40204065
&serializer,
4021-
)
4066+
)?;
4067+
if dedup_debug_enabled() {
4068+
eprintln!("[df-proto][plan-ser] done plan={}", plan.name());
4069+
}
4070+
Ok(proto)
40224071
}
40234072

40244073
fn proto_to_physical_expr(

0 commit comments

Comments
 (0)