@@ -2,32 +2,28 @@ use crate::common::{TreeNodeExt, now_ns, serialize_uuid, task_ctx_with_extension
22use crate :: config_extension_ext:: get_config_extension_propagation_headers;
33use crate :: coordinator:: MetricsStore ;
44use crate :: coordinator:: latency_metric:: LatencyMetric ;
5- use crate :: execution_plans :: { ChildrenIsolatorUnionExec , DistributedLeafExec } ;
5+ use crate :: coordinator :: plan_encoding :: encode_task_plan ;
66use crate :: passthrough_headers:: get_passthrough_headers;
77use crate :: protobuf:: tonic_status_to_datafusion_error;
88use crate :: work_unit_feed:: { build_work_unit_batch_msg, set_work_unit_send_time} ;
99use crate :: worker:: generated:: worker as pb;
1010use crate :: worker:: generated:: worker:: coordinator_to_worker_msg:: Inner ;
11- use crate :: worker:: generated:: worker:: set_plan_request:: WorkUnitFeedDeclaration ;
1211use crate :: worker:: { WorkerDispatch , WorkerDispatchRequest } ;
1312use crate :: {
14- BytesCounterMetric , BytesMetricExt , DISTRIBUTED_DATAFUSION_TASK_ID_LABEL , DistributedCodec ,
15- DistributedConfig , DistributedTaskContext , DistributedWorkUnitFeedContext , TaskKey ,
13+ BytesCounterMetric , BytesMetricExt , DISTRIBUTED_DATAFUSION_TASK_ID_LABEL , DistributedConfig ,
14+ DistributedTaskContext , DistributedWorkUnitFeedContext , TaskKey ,
1615 get_distributed_channel_resolver,
1716} ;
1817use datafusion:: common:: Result ;
1918use datafusion:: common:: instant:: Instant ;
2019use datafusion:: common:: runtime:: JoinSet ;
21- use datafusion:: common:: tree_node:: { Transformed , TreeNodeRecursion } ;
20+ use datafusion:: common:: tree_node:: TreeNodeRecursion ;
2221use datafusion:: common:: { DataFusionError , exec_datafusion_err} ;
2322use datafusion:: execution:: TaskContext ;
2423use datafusion:: physical_expr_common:: metrics:: { ExecutionPlanMetricsSet , Label , MetricBuilder } ;
2524use datafusion:: physical_plan:: ExecutionPlan ;
26- use datafusion_proto:: physical_plan:: AsExecutionPlan ;
27- use datafusion_proto:: protobuf:: PhysicalPlanNode ;
2825use futures:: { Stream , StreamExt } ;
2926use http:: Extensions ;
30- use prost:: Message ;
3127use std:: sync:: { Arc , OnceLock } ;
3228use tokio:: sync:: Notify ;
3329use tokio:: sync:: mpsc:: { UnboundedReceiver , UnboundedSender } ;
@@ -128,13 +124,9 @@ impl<'a> StageCoordinator<'a> {
128124 UnboundedReceiver < pb:: WorkerToCoordinatorMsg > ,
129125 ) > {
130126 let session_config = self . task_ctx . session_config ( ) ;
131- let codec = DistributedCodec :: new_combined_with_user ( session_config) ;
132127
133- let ( specialized, work_unit_feed_declarations) = self . task_specialized_plan ( task_i) ?;
134-
135- let plan_proto =
136- PhysicalPlanNode :: try_from_physical_plan ( specialized, & codec) ?. encode_to_vec ( ) ;
137- let plan_size = plan_proto. len ( ) ;
128+ let encoded = encode_task_plan ( self . plan , task_i, self . task_count , session_config) ?;
129+ let plan_size = encoded. plan_proto . len ( ) ;
138130
139131 let task_key = TaskKey {
140132 query_id : serialize_uuid ( & self . query_id ) ,
@@ -143,10 +135,10 @@ impl<'a> StageCoordinator<'a> {
143135 } ;
144136 let msg = pb:: CoordinatorToWorkerMsg {
145137 inner : Some ( Inner :: SetPlanRequest ( pb:: SetPlanRequest {
146- plan_proto,
138+ plan_proto : encoded . plan_proto ,
147139 task_count : self . task_count as u64 ,
148140 task_key : Some ( task_key. clone ( ) ) ,
149- work_unit_feed_declarations,
141+ work_unit_feed_declarations : encoded . feed_declarations ,
150142 target_worker_url : url. to_string ( ) ,
151143 query_start_time_ns : self . metrics . instantiation_time ,
152144 } ) ) ,
@@ -309,48 +301,6 @@ impl<'a> StageCoordinator<'a> {
309301 } ) ;
310302 Ok ( ( ) )
311303 }
312-
313- /// Specializes the [Arc<dyn ExecutionPlan>] for this stage to provided task index. This implies
314- /// trimming down any unnecessary information that the specific `task_i` task is not going to
315- /// need, like unexecuted branches in [ChildrenIsolatorUnionExec], or unexecuted variants of
316- /// [DistributedLeafExec].
317- fn task_specialized_plan (
318- & self ,
319- task_i : usize ,
320- ) -> Result < ( Arc < dyn ExecutionPlan > , Vec < WorkUnitFeedDeclaration > ) > {
321- let session_config = self . task_ctx . session_config ( ) ;
322- let d_cfg = DistributedConfig :: from_config_options ( session_config. options ( ) ) ?;
323- let wuf_registry = & d_cfg. __private_work_unit_feed_registry ;
324-
325- let mut work_unit_feed_declarations = vec ! [ ] ;
326- let d_ctx = DistributedTaskContext {
327- task_index : task_i,
328- task_count : self . task_count ,
329- } ;
330-
331- let plan = Arc :: clone ( self . plan ) ;
332- let transformed = plan. transform_down_with_dt_ctx ( d_ctx, |plan, d_ctx| {
333- if let Some ( wuf) = wuf_registry. get_work_unit_feed ( & plan) {
334- work_unit_feed_declarations. push ( WorkUnitFeedDeclaration {
335- id : serialize_uuid ( & wuf. id ( ) ) ,
336- partitions : plan. properties ( ) . partitioning . partition_count ( ) as u64 ,
337- } ) ;
338- } ;
339-
340- if let Some ( ciu) = plan. downcast_ref :: < ChildrenIsolatorUnionExec > ( ) {
341- let ciu = ciu. to_task_specialized ( d_ctx. task_index ) ;
342- return Ok ( Transformed :: yes ( Arc :: new ( ciu) ) ) ;
343- } ;
344-
345- if let Some ( dle) = plan. downcast_ref :: < DistributedLeafExec > ( ) {
346- let specialized = dle. to_task_specialized ( d_ctx. task_index ) ;
347- return Ok ( Transformed :: yes ( specialized) ) ;
348- }
349-
350- Ok ( Transformed :: no ( plan) )
351- } ) ?;
352- Ok ( ( transformed. data , work_unit_feed_declarations) )
353- }
354304}
355305
356306fn keep_stream_alive < T : ' static > ( notify : Arc < Notify > ) -> impl Stream < Item = T > + ' static {
@@ -359,14 +309,14 @@ fn keep_stream_alive<T: 'static>(notify: Arc<Notify>) -> impl Stream<Item = T> +
359309
360310/// Metrics that measure network details about communications between [DistributedExec] and a worker.
361311#[ derive( Clone ) ]
362- pub ( super ) struct CoordinatorToWorkerMetrics {
363- pub ( super ) plan_bytes_sent : BytesCounterMetric ,
364- pub ( super ) plan_send_latency : Arc < LatencyMetric > ,
365- pub ( super ) instantiation_time : u64 ,
312+ pub ( crate ) struct CoordinatorToWorkerMetrics {
313+ pub ( crate ) plan_bytes_sent : BytesCounterMetric ,
314+ pub ( crate ) plan_send_latency : Arc < LatencyMetric > ,
315+ pub ( crate ) instantiation_time : u64 ,
366316}
367317
368318impl CoordinatorToWorkerMetrics {
369- pub ( super ) fn new ( metrics : & ExecutionPlanMetricsSet ) -> Self {
319+ pub ( crate ) fn new ( metrics : & ExecutionPlanMetricsSet ) -> Self {
370320 Self {
371321 // Metric that measures to total sum of bytes worth of subplans sent.
372322 plan_bytes_sent : MetricBuilder :: new ( metrics)
0 commit comments