Skip to content

Commit 66b06ab

Browse files
committed
statement: move retry policy to StatementConfig
As StatementConfig is no longer `pub`, we can move retry_policy field there, instead of having it directly on Query, PreparedStatement and Batch.
1 parent 0332880 commit 66b06ab

File tree

6 files changed

+9
-50
lines changed

6 files changed

+9
-50
lines changed

scylla/src/statement/batch.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ pub use crate::frame::request::batch::BatchType;
1717
pub struct Batch {
1818
pub(crate) config: StatementConfig,
1919

20-
// TODO: Move this after #701 is fixed
21-
retry_policy: Option<Arc<dyn RetryPolicy>>,
22-
2320
pub statements: Vec<BatchStatement>,
2421
batch_type: BatchType,
2522
}
@@ -116,13 +113,13 @@ impl Batch {
116113
/// Set the retry policy for this batch, overriding the one from execution profile if not None.
117114
#[inline]
118115
pub fn set_retry_policy(&mut self, retry_policy: Option<Arc<dyn RetryPolicy>>) {
119-
self.retry_policy = retry_policy;
116+
self.config.retry_policy = retry_policy;
120117
}
121118

122119
/// Get the retry policy set for the batch.
123120
#[inline]
124121
pub fn get_retry_policy(&self) -> Option<&Arc<dyn RetryPolicy>> {
125-
self.retry_policy.as_ref()
122+
self.config.retry_policy.as_ref()
126123
}
127124

128125
/// Sets the listener capable of listening what happens during query execution.
@@ -151,7 +148,6 @@ impl Default for Batch {
151148
fn default() -> Self {
152149
Self {
153150
statements: Vec::new(),
154-
retry_policy: None,
155151
batch_type: BatchType::Logged,
156152
config: Default::default(),
157153
}

scylla/src/statement/mod.rs

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

3-
use crate::history::HistoryListener;
43
use crate::transport::execution_profile::ExecutionProfileHandle;
4+
use crate::{history::HistoryListener, retry_policy::RetryPolicy};
55

66
pub mod batch;
77
pub mod prepared_statement;
88
pub mod query;
99

1010
pub use crate::frame::types::{Consistency, SerialConsistency};
1111

12-
#[derive(Debug)]
12+
#[derive(Debug, Clone, Default)]
1313
pub(crate) struct StatementConfig {
1414
pub(crate) consistency: Option<Consistency>,
1515
pub(crate) serial_consistency: Option<Option<SerialConsistency>>,
@@ -23,32 +23,7 @@ pub(crate) struct StatementConfig {
2323
pub(crate) history_listener: Option<Arc<dyn HistoryListener>>,
2424

2525
pub(crate) execution_profile_handle: Option<ExecutionProfileHandle>,
26-
}
27-
28-
#[allow(clippy::derivable_impls)]
29-
impl Default for StatementConfig {
30-
fn default() -> Self {
31-
Self {
32-
consistency: Default::default(),
33-
serial_consistency: None,
34-
is_idempotent: false,
35-
tracing: false,
36-
timestamp: None,
37-
request_timeout: None,
38-
history_listener: None,
39-
execution_profile_handle: None,
40-
}
41-
}
42-
}
43-
44-
impl Clone for StatementConfig {
45-
fn clone(&self) -> Self {
46-
Self {
47-
history_listener: self.history_listener.clone(),
48-
execution_profile_handle: self.execution_profile_handle.clone(),
49-
..*self
50-
}
51-
}
26+
pub(crate) retry_policy: Option<Arc<dyn RetryPolicy>>,
5227
}
5328

5429
impl StatementConfig {

scylla/src/statement/prepared_statement.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ pub struct PreparedStatement {
2525
pub(crate) config: StatementConfig,
2626
pub prepare_tracing_ids: Vec<Uuid>,
2727

28-
// TODO: Move this after #701 is fixed
29-
retry_policy: Option<Arc<dyn RetryPolicy>>,
30-
3128
id: Bytes,
3229
shared: Arc<PreparedStatementSharedData>,
3330
page_size: Option<i32>,
@@ -45,7 +42,6 @@ impl Clone for PreparedStatement {
4542
fn clone(&self) -> Self {
4643
Self {
4744
config: self.config.clone(),
48-
retry_policy: self.retry_policy.clone(),
4945
prepare_tracing_ids: Vec::new(),
5046
id: self.id.clone(),
5147
shared: self.shared.clone(),
@@ -62,7 +58,6 @@ impl PreparedStatement {
6258
is_lwt: bool,
6359
metadata: PreparedMetadata,
6460
statement: String,
65-
retry_policy: Option<Arc<dyn RetryPolicy>>,
6661
page_size: Option<i32>,
6762
config: StatementConfig,
6863
) -> Self {
@@ -72,7 +67,6 @@ impl PreparedStatement {
7267
metadata,
7368
statement,
7469
}),
75-
retry_policy,
7670
prepare_tracing_ids: Vec::new(),
7771
page_size,
7872
config,
@@ -303,13 +297,13 @@ impl PreparedStatement {
303297
/// Set the retry policy for this statement, overriding the one from execution profile if not None.
304298
#[inline]
305299
pub fn set_retry_policy(&mut self, retry_policy: Option<Arc<dyn RetryPolicy>>) {
306-
self.retry_policy = retry_policy;
300+
self.config.retry_policy = retry_policy;
307301
}
308302

309303
/// Get the retry policy set for the statement.
310304
#[inline]
311305
pub fn get_retry_policy(&self) -> Option<&Arc<dyn RetryPolicy>> {
312-
self.retry_policy.as_ref()
306+
self.config.retry_policy.as_ref()
313307
}
314308

315309
/// Sets the listener capable of listening what happens during query execution.

scylla/src/statement/query.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub struct Query {
1414
pub(crate) config: StatementConfig,
1515

1616
// TODO: Move this after #701 is fixed
17-
retry_policy: Option<Arc<dyn RetryPolicy>>,
18-
1917
pub contents: String,
2018
page_size: Option<i32>,
2119
}
@@ -25,7 +23,6 @@ impl Query {
2523
pub fn new(query_text: impl Into<String>) -> Self {
2624
Self {
2725
contents: query_text.into(),
28-
retry_policy: None,
2926
page_size: None,
3027
config: Default::default(),
3128
}
@@ -131,13 +128,13 @@ impl Query {
131128
/// Set the retry policy for this statement, overriding the one from execution profile if not None.
132129
#[inline]
133130
pub fn set_retry_policy(&mut self, retry_policy: Option<Arc<dyn RetryPolicy>>) {
134-
self.retry_policy = retry_policy;
131+
self.config.retry_policy = retry_policy;
135132
}
136133

137134
/// Get the retry policy set for the statement.
138135
#[inline]
139136
pub fn get_retry_policy(&self) -> Option<&Arc<dyn RetryPolicy>> {
140-
self.retry_policy.as_ref()
137+
self.config.retry_policy.as_ref()
141138
}
142139

143140
/// Sets the listener capable of listening what happens during query execution.

scylla/src/transport/caching_session.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,11 @@ where
166166

167167
if let Some(raw) = self.cache.get(&query.contents) {
168168
let page_size = query.get_page_size();
169-
let retry_policy = query.get_retry_policy().cloned();
170169
let mut stmt = PreparedStatement::new(
171170
raw.id.clone(),
172171
raw.is_confirmed_lwt,
173172
raw.metadata.clone(),
174173
query.contents,
175-
retry_policy,
176174
page_size,
177175
query.config,
178176
);

scylla/src/transport/connection.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ impl Connection {
548548
.prepared_flags_contain_lwt_mark(p.prepared_metadata.flags as u32),
549549
p.prepared_metadata,
550550
query.contents.clone(),
551-
query.get_retry_policy().cloned(),
552551
query.get_page_size(),
553552
query.config.clone(),
554553
),

0 commit comments

Comments
 (0)