Skip to content

Commit

Permalink
session: added timestamp generator to SessionConfig and an ability to…
Browse files Browse the repository at this point in the history
… provide it in SessionBuilder
  • Loading branch information
smoczy123 committed Dec 3, 2024
1 parent 3fd276c commit 1d70873
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scylla/src/transport/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use super::node::{InternalKnownNode, KnownNode};
use super::partitioner::PartitionerName;
use super::query_result::MaybeFirstRowError;
use super::query_result::RowsError;
use super::timestamp_generator::TimestampGenerator;
use super::topology::UntranslatedPeer;
use super::{NodeRef, SelfIdentity};
use crate::frame::response::result;
Expand Down Expand Up @@ -270,6 +271,10 @@ pub struct SessionConfig {
/// Generally, this options is best left as default (false).
pub disallow_shard_aware_port: bool,

// Timestamp generator used for generating timestamps on the client-side
// If None, server-side timestamps are used.
pub timestamp_generator: Option<Arc<dyn TimestampGenerator>>,

/// If empty, fetch all keyspaces
pub keyspaces_to_fetch: Vec<String>,

Expand Down Expand Up @@ -382,6 +387,7 @@ impl SessionConfig {
connect_timeout: Duration::from_secs(5),
connection_pool_size: Default::default(),
disallow_shard_aware_port: false,
timestamp_generator: None,
keyspaces_to_fetch: Vec::new(),
fetch_schema_metadata: true,
keepalive_interval: Some(Duration::from_secs(30)),
Expand Down
21 changes: 21 additions & 0 deletions scylla/src/transport/session_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::session::{
AddressTranslator, CurrentDeserializationApi, GenericSession, LegacyDeserializationApi,
SessionConfig,
};
use super::timestamp_generator::TimestampGenerator;
use super::Compression;

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

/// Set the timestamp generator that will generate timestamps on the client-side.
///
/// # Example
/// ```
/// # use scylla::{MonotonicTimestampGenerator, Session, SessionBuilder};
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let session: Session = SessionBuilder::new()
/// .known_node("127.0.0.1:9042")
/// .timestamp_generator(Arc::new(MonotonicTimestampGenerator::new()))
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn timestamp_generator(mut self, timestamp_generator: Arc<dyn TimestampGenerator>) -> Self {
self.config.timestamp_generator = Some(timestamp_generator);
self
}

/// Set the keyspaces to be fetched, to retrieve their strategy, and schema metadata if enabled
/// No keyspaces, the default value, means all the keyspaces will be fetched.
///
Expand Down

0 comments on commit 1d70873

Please sign in to comment.