Skip to content

Commit

Permalink
transport/connection: Added logic for setting a timestamp
Browse files Browse the repository at this point in the history
Generated timestamp is only set if user did not provide one
  • Loading branch information
smoczy123 committed Dec 22, 2024
1 parent 7b89da9 commit 0a42cf5
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,17 @@ impl Connection {
page_size: Option<PageSize>,
paging_state: PagingState,
) -> Result<QueryResponse, UserRequestError> {
let mut timestamp = None;
if query.get_timestamp().is_none() {
if let Some(x) = self.config.timestamp_generator.as_ref() {
timestamp = Some(x.next_timestamp());
}
}

if timestamp.is_none() {
timestamp = query.get_timestamp()
}

let query_frame = query::Query {
contents: Cow::Borrowed(&query.contents),
parameters: query::QueryParameters {
Expand All @@ -1059,7 +1070,7 @@ impl Connection {
page_size: page_size.map(Into::into),
paging_state,
skip_metadata: false,
timestamp: query.get_timestamp(),
timestamp,
},
};

Expand Down Expand Up @@ -1112,14 +1123,25 @@ impl Connection {
page_size: Option<PageSize>,
paging_state: PagingState,
) -> Result<QueryResponse, UserRequestError> {
let mut timestamp = None;
if prepared_statement.get_timestamp().is_none() {
if let Some(x) = self.config.timestamp_generator.as_ref() {
timestamp = Some(x.next_timestamp());
}
}

if timestamp.is_none() {
timestamp = prepared_statement.get_timestamp()
}

let execute_frame = execute::Execute {
id: prepared_statement.get_id().to_owned(),
parameters: query::QueryParameters {
consistency,
serial_consistency,
values: Cow::Borrowed(values),
page_size: page_size.map(Into::into),
timestamp: prepared_statement.get_timestamp(),
timestamp,
skip_metadata: prepared_statement.get_use_cached_result_metadata(),
paging_state,
},
Expand Down Expand Up @@ -1251,14 +1273,24 @@ impl Connection {
});

let values = RawBatchValuesAdapter::new(values, contexts);
let mut timestamp = None;
if batch.get_timestamp().is_none() {
if let Some(x) = self.config.timestamp_generator.as_ref() {
timestamp = Some(x.next_timestamp());
}
}

if timestamp.is_none() {
timestamp = batch.get_timestamp()
}

let batch_frame = batch::Batch {
statements: Cow::Borrowed(&batch.statements),
values,
batch_type: batch.get_type(),
consistency,
serial_consistency,
timestamp: batch.get_timestamp(),
timestamp,
};

loop {
Expand Down

0 comments on commit 0a42cf5

Please sign in to comment.