Skip to content

Commit ef073e3

Browse files
committed
client/session: Added timestamp generator to SessionConfig
Also added an ability to set it through Session Builder
1 parent 0881ae2 commit ef073e3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

scylla/src/client/session.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::policies::host_filter::HostFilter;
3131
use crate::policies::load_balancing::{self, RoutingInfo};
3232
use crate::policies::retry::{RequestInfo, RetryDecision, RetrySession};
3333
use crate::policies::speculative_execution;
34+
use crate::policies::timestamp_generator::TimestampGenerator;
3435
use crate::prepared_statement::{PartitionKeyError, PreparedStatement};
3536
use crate::query::Query;
3637
#[allow(deprecated)]
@@ -181,6 +182,10 @@ pub struct SessionConfig {
181182
/// Generally, this options is best left as default (false).
182183
pub disallow_shard_aware_port: bool,
183184

185+
/// Timestamp generator used for generating timestamps on the client-side
186+
/// If None, server-side timestamps are used.
187+
pub timestamp_generator: Option<Arc<dyn TimestampGenerator>>,
188+
184189
/// If empty, fetch all keyspaces
185190
pub keyspaces_to_fetch: Vec<String>,
186191

@@ -293,6 +298,7 @@ impl SessionConfig {
293298
connect_timeout: Duration::from_secs(5),
294299
connection_pool_size: Default::default(),
295300
disallow_shard_aware_port: false,
301+
timestamp_generator: None,
296302
keyspaces_to_fetch: Vec::new(),
297303
fetch_schema_metadata: true,
298304
keepalive_interval: Some(Duration::from_secs(30)),

scylla/src/client/session_builder.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::cloud::{CloudConfig, CloudConfigError};
1414
use crate::errors::NewSessionError;
1515
use crate::policies::address_translator::AddressTranslator;
1616
use crate::policies::host_filter::HostFilter;
17+
use crate::policies::timestamp_generator::TimestampGenerator;
1718
use crate::statement::Consistency;
1819
#[cfg(feature = "ssl")]
1920
use openssl::ssl::SslContext;
@@ -684,6 +685,28 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
684685
self
685686
}
686687

688+
/// Set the timestamp generator that will generate timestamps on the client-side.
689+
///
690+
/// # Example
691+
/// ```
692+
/// # use scylla::client::session::Session;
693+
/// # use scylla::client::session_builder::SessionBuilder;
694+
/// # use scylla::policies::timestamp_generator::SimpleTimestampGenerator;
695+
/// # use std::sync::Arc;
696+
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
697+
/// let session: Session = SessionBuilder::new()
698+
/// .known_node("127.0.0.1:9042")
699+
/// .timestamp_generator(Arc::new(SimpleTimestampGenerator::new()))
700+
/// .build()
701+
/// .await?;
702+
/// # Ok(())
703+
/// # }
704+
/// ```
705+
pub fn timestamp_generator(mut self, timestamp_generator: Arc<dyn TimestampGenerator>) -> Self {
706+
self.config.timestamp_generator = Some(timestamp_generator);
707+
self
708+
}
709+
687710
/// Set the keyspaces to be fetched, to retrieve their strategy, and schema metadata if enabled
688711
/// No keyspaces, the default value, means all the keyspaces will be fetched.
689712
///

0 commit comments

Comments
 (0)