@@ -56,6 +56,7 @@ use tracing::{Instrument, Span};
5656use uuid:: Uuid ;
5757
5858use crate :: active_compute_sink:: { ActiveComputeSink , ActiveCopyTo } ;
59+ use crate :: coord:: statement_logging:: IdsToWatch ;
5960use crate :: coord:: timestamp_selection:: TimestampDetermination ;
6061use crate :: optimize:: OptimizerError ;
6162use crate :: statement_logging:: { StatementEndedExecutionReason , StatementExecutionStrategy } ;
@@ -1211,7 +1212,19 @@ impl crate::coord::Coordinator {
12111212 max_result_size : u64 ,
12121213 max_query_result_size : Option < u64 > ,
12131214 mut ctx_extra : ExecuteContextExtra ,
1215+ ids_to_watch : Option < IdsToWatch > ,
12141216 ) -> Result < ExecuteResponse , AdapterError > {
1217+ // Install watch sets for statement lifecycle logging if enabled.
1218+ if let ( Some ( logging_id) , Some ( ids_to_watch) ) = ( ctx_extra. contents ( ) , ids_to_watch) {
1219+ self . install_peek_watch_sets ( conn_id. clone ( ) , logging_id, ids_to_watch)
1220+ . map_err ( |e| {
1221+ AdapterError :: concurrent_dependency_drop_from_collection_lookup_error (
1222+ e,
1223+ compute_instance,
1224+ )
1225+ } ) ?;
1226+ }
1227+
12151228 let source_arity = intermediate_result_type. arity ( ) ;
12161229
12171230 let planned_peek = PlannedPeek {
@@ -1239,8 +1252,8 @@ impl crate::coord::Coordinator {
12391252 . await
12401253 }
12411254
1242- /// Implements a COPY TO command by validating S3 connection, shipping the dataflow ,
1243- /// and spawning a background task to wait for completion.
1255+ /// Implements a COPY TO command by installing peek watch sets, validating S3 connection ,
1256+ /// shipping the dataflow, and spawning a background task to wait for completion.
12441257 /// This is called from the command handler for ExecuteCopyTo.
12451258 ///
12461259 /// This method inlines the logic from peek_copy_to_preflight and peek_copy_to_dataflow
@@ -1256,6 +1269,8 @@ impl crate::coord::Coordinator {
12561269 target_replica : Option < ReplicaId > ,
12571270 source_ids : BTreeSet < GlobalId > ,
12581271 conn_id : ConnectionId ,
1272+ ctx_extra : ExecuteContextExtra ,
1273+ ids_to_watch : Option < IdsToWatch > ,
12591274 tx : oneshot:: Sender < Result < ExecuteResponse , AdapterError > > ,
12601275 ) {
12611276 // Helper to send error and return early
@@ -1264,6 +1279,22 @@ impl crate::coord::Coordinator {
12641279 let _ = tx. send ( Err ( e) ) ;
12651280 } ;
12661281
1282+ // Install watch sets for statement lifecycle logging if enabled.
1283+ if let ( Some ( logging_id) , Some ( ids_to_watch) ) = ( ctx_extra. contents ( ) , ids_to_watch) {
1284+ if let Err ( e) = self . install_peek_watch_sets ( conn_id. clone ( ) , logging_id, ids_to_watch) {
1285+ let err = AdapterError :: concurrent_dependency_drop_from_collection_lookup_error (
1286+ e,
1287+ compute_instance,
1288+ ) ;
1289+ send_err ( tx, err) ;
1290+ return ;
1291+ }
1292+ }
1293+
1294+ // We retire the execution context immediately, as the coordinator doesn't need
1295+ // to track the execution for statement logging purposes (the frontend handles that).
1296+ let _ = ctx_extra. retire ( ) ;
1297+
12671298 let sink_id = df_desc. sink_id ( ) ;
12681299
12691300 // # Inlined from peek_copy_to_preflight
0 commit comments