@@ -27,6 +27,7 @@ use std::fmt::Display;
2727use std:: future:: Future ;
2828use std:: io;
2929use std:: net:: SocketAddr ;
30+ use std:: num:: NonZeroU32 ;
3031use std:: str:: FromStr ;
3132use std:: sync:: atomic:: AtomicUsize ;
3233use std:: sync:: atomic:: Ordering ;
@@ -59,7 +60,7 @@ use crate::prepared_statement::{PartitionKeyError, PreparedStatement};
5960use crate :: query:: Query ;
6061use crate :: routing:: Token ;
6162use crate :: statement:: { Consistency , SerialConsistency } ;
62- use crate :: tracing:: { GetTracingConfig , TracingEvent , TracingInfo } ;
63+ use crate :: tracing:: { TracingEvent , TracingInfo } ;
6364use crate :: transport:: cluster:: { Cluster , ClusterData , ClusterNeatDebug } ;
6465use crate :: transport:: connection:: { Connection , ConnectionConfig , VerifiedKeyspaceName } ;
6566use crate :: transport:: connection_pool:: PoolConfig ;
@@ -133,6 +134,9 @@ pub struct Session {
133134 auto_await_schema_agreement_timeout : Option < Duration > ,
134135 refresh_metadata_on_auto_schema_agreement : bool ,
135136 keyspace_name : ArcSwapOption < String > ,
137+ tracing_info_fetch_attempts : NonZeroU32 ,
138+ tracing_info_fetch_interval : Duration ,
139+ tracing_info_fetch_consistency : Consistency ,
136140}
137141
138142/// This implementation deliberately omits some details from Cluster in order
@@ -238,6 +242,22 @@ pub struct SessionConfig {
238242 /// Please do performance measurements before committing to disabling
239243 /// this option.
240244 pub enable_write_coalescing : bool ,
245+
246+ /// Number of attempts to fetch [`TracingInfo`]
247+ /// in [`Session::get_tracing_info`]. Tracing info
248+ /// might not be available immediately on queried node - that's why
249+ /// the driver performs a few attempts with sleeps in between.
250+ pub tracing_info_fetch_attempts : NonZeroU32 ,
251+
252+ /// Delay between attempts to fetch [`TracingInfo`]
253+ /// in [`Session::get_tracing_info`]. Tracing info
254+ /// might not be available immediately on queried node - that's why
255+ /// the driver performs a few attempts with sleeps in between.
256+ pub tracing_info_fetch_interval : Duration ,
257+
258+ /// Consistency level of fetching [`TracingInfo`]
259+ /// in [`Session::get_tracing_info`].
260+ pub tracing_info_fetch_consistency : Consistency ,
241261}
242262
243263/// Describes database server known on Session startup.
@@ -297,6 +317,9 @@ impl SessionConfig {
297317 #[ cfg( feature = "cloud" ) ]
298318 cloud_config : None ,
299319 enable_write_coalescing : true ,
320+ tracing_info_fetch_attempts : NonZeroU32 :: new ( 5 ) . unwrap ( ) ,
321+ tracing_info_fetch_interval : Duration :: from_millis ( 3 ) ,
322+ tracing_info_fetch_consistency : Consistency :: One ,
300323 }
301324 }
302325
@@ -547,6 +570,9 @@ impl Session {
547570 refresh_metadata_on_auto_schema_agreement : config
548571 . refresh_metadata_on_auto_schema_agreement ,
549572 keyspace_name : ArcSwapOption :: default ( ) , // will be set by use_keyspace
573+ tracing_info_fetch_attempts : config. tracing_info_fetch_attempts ,
574+ tracing_info_fetch_interval : config. tracing_info_fetch_interval ,
575+ tracing_info_fetch_consistency : config. tracing_info_fetch_consistency ,
550576 } ;
551577
552578 if let Some ( keyspace_name) = config. used_keyspace {
@@ -1344,8 +1370,24 @@ impl Session {
13441370 /// See [the book](https://rust-driver.docs.scylladb.com/stable/tracing/tracing.html)
13451371 /// for more information about query tracing
13461372 pub async fn get_tracing_info ( & self , tracing_id : & Uuid ) -> Result < TracingInfo , QueryError > {
1347- self . get_tracing_info_custom ( tracing_id, & GetTracingConfig :: default ( ) )
1348- . await
1373+ // tracing_info_fetch_attempts is NonZeroU32 so at least one attempt will be made
1374+ for _ in 0 ..self . tracing_info_fetch_attempts . get ( ) {
1375+ let current_try: Option < TracingInfo > = self
1376+ . try_getting_tracing_info ( tracing_id, Some ( self . tracing_info_fetch_consistency ) )
1377+ . await ?;
1378+
1379+ match current_try {
1380+ Some ( tracing_info) => return Ok ( tracing_info) ,
1381+ None => tokio:: time:: sleep ( self . tracing_info_fetch_interval ) . await ,
1382+ } ;
1383+ }
1384+
1385+ Err ( QueryError :: ProtocolError (
1386+ "All tracing queries returned an empty result, \
1387+ maybe the trace information didn't propagate yet. \
1388+ Consider configuring Session with \
1389+ a longer fetch interval (tracing_info_fetch_interval)",
1390+ ) )
13491391 }
13501392
13511393 /// Gets the name of the keyspace that is currently set, or `None` if no
@@ -1363,35 +1405,6 @@ impl Session {
13631405 self . keyspace_name . load_full ( )
13641406 }
13651407
1366- /// Queries tracing info with custom retry settings.\
1367- /// Tracing info might not be available immediately on queried node -
1368- /// that's why the driver performs a few attempts with sleeps in between.
1369- /// [`GetTracingConfig`] allows to specify a custom querying strategy.
1370- pub async fn get_tracing_info_custom (
1371- & self ,
1372- tracing_id : & Uuid ,
1373- config : & GetTracingConfig ,
1374- ) -> Result < TracingInfo , QueryError > {
1375- // config.attempts is NonZeroU32 so at least one attempt will be made
1376- for _ in 0 ..config. attempts . get ( ) {
1377- let current_try: Option < TracingInfo > = self
1378- . try_getting_tracing_info ( tracing_id, Some ( config. consistency ) )
1379- . await ?;
1380-
1381- match current_try {
1382- Some ( tracing_info) => return Ok ( tracing_info) ,
1383- None => tokio:: time:: sleep ( config. interval ) . await ,
1384- } ;
1385- }
1386-
1387- Err ( QueryError :: ProtocolError (
1388- "All tracing queries returned an empty result, \
1389- maybe information didn't reach this node yet. \
1390- Consider using get_tracing_info_custom with \
1391- bigger interval in GetTracingConfig",
1392- ) )
1393- }
1394-
13951408 // Tries getting the tracing info
13961409 // If the queries return 0 rows then returns None - the information didn't reach this node yet
13971410 // If there is some other error returns this error
@@ -1458,20 +1471,6 @@ impl Session {
14581471 Ok ( Some ( tracing_info) )
14591472 }
14601473
1461- // Returns which replicas are likely to take part in handling the query.
1462- // If a list of replicas cannot be easily narrowed down, all available replicas
1463- // will be returned.
1464- pub fn estimate_replicas_for_query ( & self , statement : & RoutingInfo ) -> Vec < Arc < Node > > {
1465- let cluster_data = self . cluster . get_data ( ) ;
1466- match statement. token {
1467- Some ( token) => {
1468- let cluster_data = self . cluster . get_data ( ) ;
1469- cluster_data. get_token_endpoints ( statement. keyspace . unwrap_or ( "" ) , token)
1470- }
1471- None => cluster_data. get_nodes_info ( ) . to_owned ( ) ,
1472- }
1473- }
1474-
14751474 // This method allows to easily run a query using load balancing, retry policy etc.
14761475 // Requires some information about the query and two closures
14771476 // First closure is used to choose a connection
0 commit comments