Skip to content

Commit 1d70873

Browse files
committed
session: added timestamp generator to SessionConfig and an ability to provide it in SessionBuilder
1 parent 3fd276c commit 1d70873

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

scylla/src/transport/session.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use super::node::{InternalKnownNode, KnownNode};
5353
use super::partitioner::PartitionerName;
5454
use super::query_result::MaybeFirstRowError;
5555
use super::query_result::RowsError;
56+
use super::timestamp_generator::TimestampGenerator;
5657
use super::topology::UntranslatedPeer;
5758
use super::{NodeRef, SelfIdentity};
5859
use crate::frame::response::result;
@@ -270,6 +271,10 @@ pub struct SessionConfig {
270271
/// Generally, this options is best left as default (false).
271272
pub disallow_shard_aware_port: bool,
272273

274+
// Timestamp generator used for generating timestamps on the client-side
275+
// If None, server-side timestamps are used.
276+
pub timestamp_generator: Option<Arc<dyn TimestampGenerator>>,
277+
273278
/// If empty, fetch all keyspaces
274279
pub keyspaces_to_fetch: Vec<String>,
275280

@@ -382,6 +387,7 @@ impl SessionConfig {
382387
connect_timeout: Duration::from_secs(5),
383388
connection_pool_size: Default::default(),
384389
disallow_shard_aware_port: false,
390+
timestamp_generator: None,
385391
keyspaces_to_fetch: Vec::new(),
386392
fetch_schema_metadata: true,
387393
keepalive_interval: Some(Duration::from_secs(30)),

scylla/src/transport/session_builder.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::session::{
77
AddressTranslator, CurrentDeserializationApi, GenericSession, LegacyDeserializationApi,
88
SessionConfig,
99
};
10+
use super::timestamp_generator::TimestampGenerator;
1011
use super::Compression;
1112

1213
#[cfg(feature = "cloud")]
@@ -663,6 +664,26 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
663664
self
664665
}
665666

667+
/// Set the timestamp generator that will generate timestamps on the client-side.
668+
///
669+
/// # Example
670+
/// ```
671+
/// # use scylla::{MonotonicTimestampGenerator, Session, SessionBuilder};
672+
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
673+
/// let session: Session = SessionBuilder::new()
674+
/// .known_node("127.0.0.1:9042")
675+
/// .timestamp_generator(Arc::new(MonotonicTimestampGenerator::new()))
676+
/// .build()
677+
/// .await?;
678+
/// # Ok(())
679+
/// # }
680+
/// ```
681+
682+
pub fn timestamp_generator(mut self, timestamp_generator: Arc<dyn TimestampGenerator>) -> Self {
683+
self.config.timestamp_generator = Some(timestamp_generator);
684+
self
685+
}
686+
666687
/// Set the keyspaces to be fetched, to retrieve their strategy, and schema metadata if enabled
667688
/// No keyspaces, the default value, means all the keyspaces will be fetched.
668689
///

0 commit comments

Comments
 (0)