From 7ac8dacd34877607df3f0019d04f50c245947a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Thu, 24 Oct 2024 14:38:28 +0200 Subject: [PATCH 1/4] CassConsistency: adjust converion to serial variants of Consistency According to the comment in rust-driver: // Apparently, Consistency can be set to Serial or LocalSerial in SELECT statements // to make them use Paxos. --- scylla-rust-wrapper/src/cass_types.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scylla-rust-wrapper/src/cass_types.rs b/scylla-rust-wrapper/src/cass_types.rs index 7c73c604..3faa8238 100644 --- a/scylla-rust-wrapper/src/cass_types.rs +++ b/scylla-rust-wrapper/src/cass_types.rs @@ -855,6 +855,8 @@ impl TryFrom for Consistency { CassConsistency::CASS_CONSISTENCY_LOCAL_QUORUM => Ok(Consistency::LocalQuorum), CassConsistency::CASS_CONSISTENCY_EACH_QUORUM => Ok(Consistency::EachQuorum), CassConsistency::CASS_CONSISTENCY_LOCAL_ONE => Ok(Consistency::LocalOne), + CassConsistency::CASS_CONSISTENCY_LOCAL_SERIAL => Ok(Consistency::LocalSerial), + CassConsistency::CASS_CONSISTENCY_SERIAL => Ok(Consistency::Serial), _ => Err(()), } } From daeba254c0ea8387218a909afab4186aa7aff62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Thu, 24 Oct 2024 17:21:21 +0200 Subject: [PATCH 2/4] cluster: set tracing consistency Implemented `cass_cluster_set_tracing_consistency`. Set the default ( * Default: CASS_CONSISTENCY_ONE). --- scylla-rust-wrapper/src/cluster.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scylla-rust-wrapper/src/cluster.rs b/scylla-rust-wrapper/src/cluster.rs index d11a3d44..5d7f6ea2 100644 --- a/scylla-rust-wrapper/src/cluster.rs +++ b/scylla-rust-wrapper/src/cluster.rs @@ -43,6 +43,8 @@ const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_millis(5000); const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30); // - keepalive timeout is 60 secs const DEFAULT_KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(60); +// - tracing consistency is ONE +const DEFAULT_TRACING_CONSISTENCY: Consistency = Consistency::One; const DRIVER_NAME: &str = "ScyllaDB Cpp-Rust Driver"; const DRIVER_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -183,6 +185,7 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster { .connection_timeout(DEFAULT_CONNECT_TIMEOUT) .keepalive_interval(DEFAULT_KEEPALIVE_INTERVAL) .keepalive_timeout(DEFAULT_KEEPALIVE_TIMEOUT) + .tracing_info_fetch_consistency(DEFAULT_TRACING_CONSISTENCY) }; Box::into_raw(Box::new(CassCluster { @@ -408,6 +411,22 @@ pub unsafe extern "C" fn cass_cluster_set_request_timeout( }) } +#[no_mangle] +pub unsafe extern "C" fn cass_cluster_set_tracing_consistency( + cluster_raw: *mut CassCluster, + consistency: CassConsistency, +) { + let cluster = ptr_to_ref_mut(cluster_raw); + + let consistency = Consistency::try_from(consistency) + .expect("Invalid consistency passed to `cass_cluster_set_tracing_consistency`."); + + cluster + .session_builder + .config + .tracing_info_fetch_consistency = consistency; +} + #[no_mangle] pub unsafe extern "C" fn cass_cluster_set_port( cluster_raw: *mut CassCluster, From 1a8b77805609700abfaee0d20af42e93343d4ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Thu, 24 Oct 2024 17:26:09 +0200 Subject: [PATCH 3/4] cluster: set tracing info fetch interval Implemented `cass_cluster_set_tracing_retry_wait_time`. Set the default (3ms). --- scylla-rust-wrapper/src/cluster.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scylla-rust-wrapper/src/cluster.rs b/scylla-rust-wrapper/src/cluster.rs index 5d7f6ea2..2820e37f 100644 --- a/scylla-rust-wrapper/src/cluster.rs +++ b/scylla-rust-wrapper/src/cluster.rs @@ -43,6 +43,8 @@ const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_millis(5000); const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30); // - keepalive timeout is 60 secs const DEFAULT_KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(60); +// - tracing info fetch interval is 3 millis +const DEFAULT_TRACING_INFO_FETCH_INTERVAL: Duration = Duration::from_millis(3); // - tracing consistency is ONE const DEFAULT_TRACING_CONSISTENCY: Consistency = Consistency::One; @@ -185,6 +187,7 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster { .connection_timeout(DEFAULT_CONNECT_TIMEOUT) .keepalive_interval(DEFAULT_KEEPALIVE_INTERVAL) .keepalive_timeout(DEFAULT_KEEPALIVE_TIMEOUT) + .tracing_info_fetch_interval(DEFAULT_TRACING_INFO_FETCH_INTERVAL) .tracing_info_fetch_consistency(DEFAULT_TRACING_CONSISTENCY) }; @@ -411,6 +414,17 @@ pub unsafe extern "C" fn cass_cluster_set_request_timeout( }) } +#[no_mangle] +pub unsafe extern "C" fn cass_cluster_set_tracing_retry_wait_time( + cluster_raw: *mut CassCluster, + retry_wait_time_ms: c_uint, +) { + let cluster = ptr_to_ref_mut(cluster_raw); + + cluster.session_builder.config.tracing_info_fetch_interval = + Duration::from_millis(retry_wait_time_ms.into()); +} + #[no_mangle] pub unsafe extern "C" fn cass_cluster_set_tracing_consistency( cluster_raw: *mut CassCluster, From 93c68a8b25e977517c3e74901fec90014b1c7506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Uzarski?= Date: Thu, 24 Oct 2024 17:51:23 +0200 Subject: [PATCH 4/4] cluster: set tracing info fetch timeout rust-driver does not expose such config option. However, it does expose maximum number of retries for tracing info fetch. Having tracing info fetch timeout and interval (between each retry), we can compute the number of retries that should be performed to fetch the tracing info. --- scylla-rust-wrapper/src/cluster.rs | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scylla-rust-wrapper/src/cluster.rs b/scylla-rust-wrapper/src/cluster.rs index 2820e37f..cadab7f3 100644 --- a/scylla-rust-wrapper/src/cluster.rs +++ b/scylla-rust-wrapper/src/cluster.rs @@ -22,6 +22,7 @@ use scylla::{SessionBuilder, SessionConfig}; use std::collections::HashMap; use std::convert::TryInto; use std::future::Future; +use std::num::NonZeroU32; use std::os::raw::{c_char, c_int, c_uint}; use std::sync::Arc; use std::time::Duration; @@ -43,6 +44,8 @@ const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_millis(5000); const DEFAULT_KEEPALIVE_INTERVAL: Duration = Duration::from_secs(30); // - keepalive timeout is 60 secs const DEFAULT_KEEPALIVE_TIMEOUT: Duration = Duration::from_secs(60); +// - tracing info fetch timeout is 15 millis +const DEFAULT_TRACING_INFO_FETCH_TIMEOUT: Duration = Duration::from_millis(15); // - tracing info fetch interval is 3 millis const DEFAULT_TRACING_INFO_FETCH_INTERVAL: Duration = Duration::from_millis(3); // - tracing consistency is ONE @@ -113,6 +116,11 @@ pub struct CassCluster { auth_password: Option, client_id: Option, + + /// The default timeout for tracing info fetch. + /// Rust-driver only defines the number of retries. + /// However, this can be easily computed: `tracing_max_wait_time / tracing_retry_wait_time`. + tracing_max_wait_time: Duration, } impl CassCluster { @@ -159,6 +167,19 @@ pub fn build_session_builder( session_builder = session_builder.user(username, password) } + // Compute the number of retries for tracing info fetch + // based on the timeout and interval provided by user. + let tracing_info_fetch_attemps = { + let attemps = cluster.tracing_max_wait_time.as_millis() + / session_builder + .config + .tracing_info_fetch_interval + .as_millis(); + + NonZeroU32::new(attemps as u32).unwrap_or_else(|| NonZeroU32::new(1).unwrap()) + }; + session_builder = session_builder.tracing_info_fetch_attempts(tracing_info_fetch_attemps); + async move { let load_balancing = load_balancing_config.clone().build().await; execution_profile_builder = execution_profile_builder.load_balancing_policy(load_balancing); @@ -204,6 +225,7 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster { execution_profile_map: Default::default(), load_balancing_config: Default::default(), client_id: None, + tracing_max_wait_time: DEFAULT_TRACING_INFO_FETCH_TIMEOUT, })) } @@ -414,6 +436,16 @@ pub unsafe extern "C" fn cass_cluster_set_request_timeout( }) } +#[no_mangle] +pub unsafe extern "C" fn cass_cluster_set_tracing_max_wait_time( + cluster_raw: *mut CassCluster, + max_wait_time_ms: c_uint, +) { + let cluster = ptr_to_ref_mut(cluster_raw); + + cluster.tracing_max_wait_time = Duration::from_millis(max_wait_time_ms.into()); +} + #[no_mangle] pub unsafe extern "C" fn cass_cluster_set_tracing_retry_wait_time( cluster_raw: *mut CassCluster,