Skip to content

Commit

Permalink
transport/session: Added timestamp generator to SessionConfig
Browse files Browse the repository at this point in the history
Also added an ability to set it through Session Builder
  • Loading branch information
smoczy123 committed Dec 22, 2024
1 parent bcedecb commit a8e4ca9
Show file tree
Hide file tree
Showing 2 changed files with 28 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 @@ -271,6 +272,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 @@ -383,6 +388,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
22 changes: 22 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,27 @@ impl<K: SessionBuilderKind> GenericSessionBuilder<K> {
self
}

/// Set the timestamp generator that will generate timestamps on the client-side.
///
/// # Example
/// ```
/// # use scylla::{Session, SessionBuilder};
/// # use scylla::transport::timestamp_generator::SimpleTimestampGenerator;
/// # use std::sync::Arc;
/// # 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(SimpleTimestampGenerator::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 a8e4ca9

Please sign in to comment.