Skip to content

Commit a9c1b8f

Browse files
committed
Added request_timeout field to statements
StatementConfig had this field added, and PreparedStatement and Query got getters and setters for that.
1 parent c7bff2d commit a9c1b8f

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

scylla/src/statement/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{sync::Arc, time::Duration};
22

33
use crate::transport::retry_policy::RetryPolicy;
44
use crate::transport::speculative_execution::SpeculativeExecutionPolicy;
@@ -21,6 +21,7 @@ pub struct StatementConfig {
2121

2222
pub tracing: bool,
2323
pub timestamp: Option<i64>,
24+
pub request_timeout: Option<Duration>,
2425
}
2526

2627
impl Default for StatementConfig {
@@ -33,23 +34,20 @@ impl Default for StatementConfig {
3334
speculative_execution_policy: None,
3435
tracing: false,
3536
timestamp: None,
37+
request_timeout: None,
3638
}
3739
}
3840
}
3941

4042
impl Clone for StatementConfig {
4143
fn clone(&self) -> Self {
4244
Self {
43-
consistency: self.consistency,
44-
serial_consistency: self.serial_consistency,
45-
is_idempotent: self.is_idempotent,
4645
retry_policy: self
4746
.retry_policy
4847
.as_ref()
4948
.map(|policy| policy.clone_boxed()),
5049
speculative_execution_policy: self.speculative_execution_policy.clone(),
51-
tracing: self.tracing,
52-
timestamp: self.timestamp,
50+
..*self
5351
}
5452
}
5553
}

scylla/src/statement/prepared_statement.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bytes::{BufMut, Bytes, BytesMut};
22
use smallvec::{smallvec, SmallVec};
33
use std::convert::TryInto;
4+
use std::time::Duration;
45
use thiserror::Error;
56
use uuid::Uuid;
67

@@ -247,6 +248,19 @@ impl PreparedStatement {
247248
self.config.timestamp
248249
}
249250

251+
/// Sets the client-side timeout for this statement.
252+
/// If not None, the driver will stop waiting for the request
253+
/// to finish after `timeout` passed.
254+
/// Otherwise, default session client timeout will be applied.
255+
pub fn set_request_timeout(&mut self, timeout: Option<Duration>) {
256+
self.config.request_timeout = timeout
257+
}
258+
259+
/// Gets client timeout associated with this query
260+
pub fn get_request_timeout(&self) -> Option<Duration> {
261+
self.config.request_timeout
262+
}
263+
250264
/// Sets the name of the partitioner used for this statement.
251265
pub(crate) fn set_partitioner_name(&mut self, partitioner_name: Option<&str>) {
252266
self.partitioner_name = match partitioner_name {

scylla/src/statement/query.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::StatementConfig;
22
use crate::frame::types::{Consistency, SerialConsistency};
33
use crate::transport::retry_policy::RetryPolicy;
4+
use std::time::Duration;
45

56
/// CQL query statement.
67
///
@@ -117,6 +118,19 @@ impl Query {
117118
pub fn get_timestamp(&self) -> Option<i64> {
118119
self.config.timestamp
119120
}
121+
122+
/// Sets the client-side timeout for this statement.
123+
/// If not None, the driver will stop waiting for the request
124+
/// to finish after `timeout` passed.
125+
/// Otherwise, default session client timeout will be applied.
126+
pub fn set_request_timeout(&mut self, timeout: Option<Duration>) {
127+
self.config.request_timeout = timeout
128+
}
129+
130+
/// Gets client timeout associated with this query
131+
pub fn get_request_timeout(&self) -> Option<Duration> {
132+
self.config.request_timeout
133+
}
120134
}
121135

122136
impl From<String> for Query {

0 commit comments

Comments
 (0)