@@ -2526,67 +2526,73 @@ impl Coordinator {
25262526 }
25272527 }
25282528
2529+ /// Inner method that performs the actual real-time recency timestamp determination.
2530+ /// This is called by both the old peek sequencing code (via `determine_real_time_recent_timestamp`)
2531+ /// and the new command handler for `Command::DetermineRealTimeRecentTimestamp`.
2532+ pub ( crate ) async fn determine_real_time_recent_timestamp (
2533+ & self ,
2534+ source_ids : impl Iterator < Item = GlobalId > ,
2535+ real_time_recency_timeout : Duration ,
2536+ ) -> Result < Option < BoxFuture < ' static , Result < Timestamp , StorageError < Timestamp > > > > , AdapterError >
2537+ {
2538+ let item_ids = source_ids. map ( |gid| self . catalog . resolve_item_id ( & gid) ) ;
2539+
2540+ // Find all dependencies transitively because we need to ensure that
2541+ // RTR queries determine the timestamp from the sources' (i.e.
2542+ // storage objects that ingest data from external systems) remap
2543+ // data. We "cheat" a little bit and filter out any IDs that aren't
2544+ // user objects because we know they are not a RTR source.
2545+ let mut to_visit = VecDeque :: from_iter ( item_ids. filter ( CatalogItemId :: is_user) ) ;
2546+ // If none of the sources are user objects, we don't need to provide
2547+ // a RTR timestamp.
2548+ if to_visit. is_empty ( ) {
2549+ return Ok ( None ) ;
2550+ }
2551+
2552+ let mut timestamp_objects = BTreeSet :: new ( ) ;
2553+
2554+ while let Some ( id) = to_visit. pop_front ( ) {
2555+ timestamp_objects. insert ( id) ;
2556+ to_visit. extend (
2557+ self . catalog ( )
2558+ . get_entry ( & id)
2559+ . uses ( )
2560+ . into_iter ( )
2561+ . filter ( |id| !timestamp_objects. contains ( id) && id. is_user ( ) ) ,
2562+ ) ;
2563+ }
2564+ let timestamp_objects = timestamp_objects
2565+ . into_iter ( )
2566+ . flat_map ( |item_id| self . catalog ( ) . get_entry ( & item_id) . global_ids ( ) )
2567+ . collect ( ) ;
2568+
2569+ let r = self
2570+ . controller
2571+ . determine_real_time_recent_timestamp ( timestamp_objects, real_time_recency_timeout)
2572+ . await ?;
2573+
2574+ Ok ( Some ( r) )
2575+ }
2576+
25292577 /// Checks to see if the session needs a real time recency timestamp and if so returns
25302578 /// a future that will return the timestamp.
2531- pub ( super ) async fn determine_real_time_recent_timestamp (
2579+ pub ( crate ) async fn determine_real_time_recent_timestamp_if_needed (
25322580 & self ,
25332581 session : & Session ,
2534- source_ids : impl Iterator < Item = CatalogItemId > ,
2582+ source_ids : impl Iterator < Item = GlobalId > ,
25352583 ) -> Result < Option < BoxFuture < ' static , Result < Timestamp , StorageError < Timestamp > > > > , AdapterError >
25362584 {
25372585 let vars = session. vars ( ) ;
25382586
2539- // Ideally this logic belongs inside of
2540- // `mz-adapter::coord::timestamp_selection::determine_timestamp`. However, including the
2541- // logic in there would make it extremely difficult and inconvenient to pull the waiting off
2542- // of the main coord thread.
2543- let r = if vars. real_time_recency ( )
2587+ if vars. real_time_recency ( )
25442588 && vars. transaction_isolation ( ) == & IsolationLevel :: StrictSerializable
25452589 && !session. contains_read_timestamp ( )
25462590 {
2547- // Find all dependencies transitively because we need to ensure that
2548- // RTR queries determine the timestamp from the sources' (i.e.
2549- // storage objects that ingest data from external systems) remap
2550- // data. We "cheat" a little bit and filter out any IDs that aren't
2551- // user objects because we know they are not a RTR source.
2552- let mut to_visit = VecDeque :: from_iter ( source_ids. filter ( CatalogItemId :: is_user) ) ;
2553- // If none of the sources are user objects, we don't need to provide
2554- // a RTR timestamp.
2555- if to_visit. is_empty ( ) {
2556- return Ok ( None ) ;
2557- }
2558-
2559- let mut timestamp_objects = BTreeSet :: new ( ) ;
2560-
2561- while let Some ( id) = to_visit. pop_front ( ) {
2562- timestamp_objects. insert ( id) ;
2563- to_visit. extend (
2564- self . catalog ( )
2565- . get_entry ( & id)
2566- . uses ( )
2567- . into_iter ( )
2568- . filter ( |id| !timestamp_objects. contains ( id) && id. is_user ( ) ) ,
2569- ) ;
2570- }
2571- let timestamp_objects = timestamp_objects
2572- . into_iter ( )
2573- . flat_map ( |item_id| self . catalog ( ) . get_entry ( & item_id) . global_ids ( ) )
2574- . collect ( ) ;
2575-
2576- let r = self
2577- . controller
2578- . determine_real_time_recent_timestamp (
2579- timestamp_objects,
2580- * vars. real_time_recency_timeout ( ) ,
2581- )
2582- . await ?;
2583-
2584- Some ( r)
2591+ self . determine_real_time_recent_timestamp ( source_ids, * vars. real_time_recency_timeout ( ) )
2592+ . await
25852593 } else {
2586- None
2587- } ;
2588-
2589- Ok ( r)
2594+ Ok ( None )
2595+ }
25902596 }
25912597
25922598 #[ instrument]
0 commit comments