Skip to content

Commit 8108bba

Browse files
authored
Merge pull request #690 from wprzytula/execution_profiles_ext
Execution profiles API extensions
2 parents 91a1b8e + a352b89 commit 8108bba

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

scylla/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub use transport::session_builder::SessionBuilder;
134134
#[cfg(feature = "cloud")]
135135
pub use transport::session_builder::CloudSessionBuilder;
136136

137+
pub use transport::execution_profile;
137138
pub use transport::host_filter;
138139
pub use transport::load_balancing;
139140
pub use transport::retry_policy;

scylla/src/transport/execution_profile.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub(crate) mod defaults {
226226
/// # Ok(())
227227
/// # }
228228
/// ```
229+
#[derive(Clone, Debug)]
229230
pub struct ExecutionProfileBuilder {
230231
request_timeout: Option<Option<Duration>>,
231232
consistency: Option<Consistency>,
@@ -378,6 +379,12 @@ impl ExecutionProfileBuilder {
378379
}
379380
}
380381

382+
impl Default for ExecutionProfileBuilder {
383+
fn default() -> Self {
384+
ExecutionProfile::builder()
385+
}
386+
}
387+
381388
/// A profile that groups configurable options regarding query execution.
382389
///
383390
/// Execution profile is immutable as such, but the driver implements double indirection of form:
@@ -399,6 +406,20 @@ pub(crate) struct ExecutionProfileInner {
399406
pub(crate) speculative_execution_policy: Option<Arc<dyn SpeculativeExecutionPolicy>>,
400407
}
401408

409+
impl ExecutionProfileInner {
410+
/// Creates a builder having all options set to the same as set in this ExecutionProfileInner.
411+
pub(crate) fn to_builder(&self) -> ExecutionProfileBuilder {
412+
ExecutionProfileBuilder {
413+
request_timeout: Some(self.request_timeout),
414+
consistency: Some(self.consistency),
415+
serial_consistency: Some(self.serial_consistency),
416+
load_balancing_policy: Some(self.load_balancing_policy.clone()),
417+
retry_policy: Some(self.retry_policy.clone()),
418+
speculative_execution_policy: Some(self.speculative_execution_policy.clone()),
419+
}
420+
}
421+
}
422+
402423
impl ExecutionProfile {
403424
pub(crate) fn new_from_inner(inner: ExecutionProfileInner) -> Self {
404425
Self(Arc::new(inner))
@@ -418,14 +439,7 @@ impl ExecutionProfile {
418439

419440
/// Creates a builder having all options set to the same as set in this ExecutionProfile.
420441
pub fn to_builder(&self) -> ExecutionProfileBuilder {
421-
ExecutionProfileBuilder {
422-
request_timeout: Some(self.0.request_timeout),
423-
consistency: Some(self.0.consistency),
424-
serial_consistency: Some(self.0.serial_consistency),
425-
load_balancing_policy: Some(self.0.load_balancing_policy.clone()),
426-
retry_policy: Some(self.0.retry_policy.clone()),
427-
speculative_execution_policy: Some(self.0.speculative_execution_policy.clone()),
428-
}
442+
self.0.to_builder()
429443
}
430444

431445
/// Returns a new handle to this ExecutionProfile.
@@ -461,6 +475,11 @@ impl ExecutionProfileHandle {
461475
self.0 .0.load_full()
462476
}
463477

478+
/// Creates a builder having all options set to the same as set in the ExecutionProfile pointed by this handle.
479+
pub fn pointee_to_builder(&self) -> ExecutionProfileBuilder {
480+
self.0 .0.load().to_builder()
481+
}
482+
464483
/// Makes the handle point to a new execution profile.
465484
/// All entities (queries/Session) holding this handle will reflect the change.
466485
pub fn map_to_another_profile(&mut self, profile: ExecutionProfile) {

scylla/src/transport/session.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,9 @@ impl Session {
18151815
}
18161816
}
18171817

1818-
fn get_default_execution_profile_handle(&self) -> &ExecutionProfileHandle {
1818+
/// Retrieves the handle to execution profile that is used by this session
1819+
/// by default, i.e. when an executed statement does not define its own handle.
1820+
pub fn get_default_execution_profile_handle(&self) -> &ExecutionProfileHandle {
18191821
&self.default_execution_profile_handle
18201822
}
18211823
}

0 commit comments

Comments
 (0)