Skip to content

Commit e3e20f6

Browse files
authored
Merge pull request #772 from wprzytula/unpub-statement-config
statement: unpub StatementConfig
2 parents 774a630 + 66838b9 commit e3e20f6

File tree

7 files changed

+23
-68
lines changed

7 files changed

+23
-68
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: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,35 @@
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)]
13-
pub struct StatementConfig {
14-
pub consistency: Option<Consistency>,
15-
pub serial_consistency: Option<Option<SerialConsistency>>,
12+
#[derive(Debug, Clone, Default)]
13+
pub(crate) struct StatementConfig {
14+
pub(crate) consistency: Option<Consistency>,
15+
pub(crate) serial_consistency: Option<Option<SerialConsistency>>,
1616

17-
pub is_idempotent: bool,
17+
pub(crate) is_idempotent: bool,
1818

19-
pub tracing: bool,
20-
pub timestamp: Option<i64>,
21-
pub request_timeout: Option<Duration>,
19+
pub(crate) tracing: bool,
20+
pub(crate) timestamp: Option<i64>,
21+
pub(crate) request_timeout: Option<Duration>,
2222

23-
pub history_listener: Option<Arc<dyn HistoryListener>>,
23+
pub(crate) history_listener: Option<Arc<dyn HistoryListener>>,
2424

25-
pub 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-
}
25+
pub(crate) execution_profile_handle: Option<ExecutionProfileHandle>,
26+
pub(crate) retry_policy: Option<Arc<dyn RetryPolicy>>,
5227
}
5328

5429
impl StatementConfig {
5530
/// Determines the consistency of a query
5631
#[must_use]
57-
pub fn determine_consistency(&self, default_consistency: Consistency) -> Consistency {
32+
pub(crate) fn determine_consistency(&self, default_consistency: Consistency) -> Consistency {
5833
self.consistency.unwrap_or(default_consistency)
5934
}
6035
}

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
),

scylla/src/transport/session.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::frame::types::LegacyConsistency;
88
use crate::history;
99
use crate::history::HistoryListener;
1010
use crate::prepared_statement::PartitionKeyDecoder;
11-
use crate::retry_policy::RetryPolicy;
1211
use crate::utils::pretty::{CommaSeparatedDisplayer, CqlValueDisplayer};
1312
use arc_swap::ArcSwapOption;
1413
use async_trait::async_trait;
@@ -675,7 +674,6 @@ impl Session {
675674
.run_query(
676675
statement_info,
677676
&query.config,
678-
query.get_retry_policy().map(|rp| &**rp),
679677
execution_profile,
680678
|node: Arc<Node>| async move { node.random_connection().await },
681679
|connection: Arc<Connection>,
@@ -1029,7 +1027,6 @@ impl Session {
10291027
.run_query(
10301028
statement_info,
10311029
&prepared.config,
1032-
prepared.get_retry_policy().map(|rp| &**rp),
10331030
execution_profile,
10341031
|node: Arc<Node>| async move {
10351032
match token {
@@ -1246,7 +1243,6 @@ impl Session {
12461243
.run_query(
12471244
statement_info,
12481245
&batch.config,
1249-
batch.get_retry_policy().map(|rp| &**rp),
12501246
execution_profile,
12511247
|node: Arc<Node>| async move {
12521248
match first_value_token {
@@ -1530,12 +1526,10 @@ impl Session {
15301526
// On success this query's result is returned
15311527
// I tried to make this closures take a reference instead of an Arc but failed
15321528
// maybe once async closures get stabilized this can be fixed
1533-
#[allow(clippy::too_many_arguments)] // <-- remove this once retry policy is put into StatementConfig
15341529
async fn run_query<'a, ConnFut, QueryFut, ResT>(
15351530
&'a self,
15361531
statement_info: RoutingInfo<'a>,
15371532
statement_config: &'a StatementConfig,
1538-
statement_retry_policy: Option<&dyn RetryPolicy>,
15391533
execution_profile: Arc<ExecutionProfileInner>,
15401534
choose_connection: impl Fn(Arc<Node>) -> ConnFut,
15411535
do_query: impl Fn(Arc<Connection>, Consistency, &ExecutionProfileInner) -> QueryFut,
@@ -1580,7 +1574,10 @@ impl Session {
15801574
}
15811575
}
15821576

1583-
let retry_policy = statement_retry_policy.unwrap_or(&*execution_profile.retry_policy);
1577+
let retry_policy = statement_config
1578+
.retry_policy
1579+
.as_deref()
1580+
.unwrap_or(&*execution_profile.retry_policy);
15841581

15851582
let speculative_policy = execution_profile.speculative_execution_policy.as_ref();
15861583

@@ -1858,7 +1855,6 @@ impl Session {
18581855
.run_query(
18591856
info,
18601857
&config,
1861-
None, // No specific retry policy needed for schema agreement
18621858
self.get_default_execution_profile_handle().access(),
18631859
|node: Arc<Node>| async move { node.random_connection().await },
18641860
do_query,

0 commit comments

Comments
 (0)