Skip to content

Commit af5fd91

Browse files
authored
Merge pull request #1375 from wprzytula/degenericise-run-request
session: Degenericise `run_request` & unify autohandling of specific responses
2 parents 64d721e + 0c3ac9e commit af5fd91

File tree

1 file changed

+14
-32
lines changed

1 file changed

+14
-32
lines changed

scylla/src/client/session.rs

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,6 @@ impl Session {
11151115
RunRequestResult::Completed(response) => response,
11161116
};
11171117

1118-
self.handle_set_keyspace_response(&response).await?;
1119-
self.handle_auto_await_schema_agreement(&response, coordinator.node().host_id)
1120-
.await?;
1121-
11221118
let (result, paging_state_response) =
11231119
response.into_query_result_and_paging_state(coordinator)?;
11241120
span.record_result_fields(&result);
@@ -1491,10 +1487,6 @@ impl Session {
14911487
RunRequestResult::Completed(response) => response,
14921488
};
14931489

1494-
self.handle_set_keyspace_response(&response).await?;
1495-
self.handle_auto_await_schema_agreement(&response, coordinator.node().host_id)
1496-
.await?;
1497-
14981490
let (result, paging_state_response) =
14991491
response.into_query_result_and_paging_state(coordinator)?;
15001492
span.record_result_fields(&result);
@@ -1858,17 +1850,16 @@ impl Session {
18581850
/// On success, this request's result is returned.
18591851
// I tried to make this closures take a reference instead of an Arc but failed
18601852
// maybe once async closures get stabilized this can be fixed
1861-
async fn run_request<'a, QueryFut, ResT>(
1853+
async fn run_request<'a, QueryFut>(
18621854
&'a self,
18631855
statement_info: RoutingInfo<'a>,
18641856
statement_config: &'a StatementConfig,
18651857
execution_profile: Arc<ExecutionProfileInner>,
18661858
run_request_once: impl Fn(Arc<Connection>, Consistency, &ExecutionProfileInner) -> QueryFut,
18671859
request_span: &'a RequestSpan,
1868-
) -> Result<(RunRequestResult<ResT>, Coordinator), ExecutionError>
1860+
) -> Result<(RunRequestResult<NonErrorQueryResponse>, Coordinator), ExecutionError>
18691861
where
1870-
QueryFut: Future<Output = Result<ResT, RequestAttemptError>>,
1871-
ResT: AllowedRunRequestResTType,
1862+
QueryFut: Future<Output = Result<NonErrorQueryResponse, RequestAttemptError>>,
18721863
{
18731864
let history_listener_and_id: Option<(&'a dyn HistoryListener, history::RequestId)> =
18741865
statement_config
@@ -2021,6 +2012,13 @@ impl Session {
20212012
}
20222013
}
20232014

2015+
// Automatically handle meaningful responses.
2016+
if let Ok((RunRequestResult::Completed(ref response), ref coordinator)) = result {
2017+
self.handle_set_keyspace_response(response).await?;
2018+
self.handle_auto_await_schema_agreement(response, coordinator.node().host_id)
2019+
.await?;
2020+
}
2021+
20242022
result.map_err(RequestError::into_execution_error)
20252023
}
20262024

@@ -2029,16 +2027,15 @@ impl Session {
20292027
/// If request fails, retry session is used to perform retries.
20302028
///
20312029
/// Returns None, if provided plan is empty.
2032-
async fn run_request_speculative_fiber<'a, QueryFut, ResT>(
2030+
async fn run_request_speculative_fiber<'a, QueryFut>(
20332031
&'a self,
20342032
request_plan: impl Iterator<Item = (NodeRef<'a>, Shard)>,
20352033
run_request_once: impl Fn(Arc<Connection>, Consistency, &ExecutionProfileInner) -> QueryFut,
20362034
execution_profile: &ExecutionProfileInner,
20372035
mut context: ExecuteRequestContext<'a>,
2038-
) -> Option<Result<(RunRequestResult<ResT>, Coordinator), RequestError>>
2036+
) -> Option<Result<(RunRequestResult<NonErrorQueryResponse>, Coordinator), RequestError>>
20392037
where
2040-
QueryFut: Future<Output = Result<ResT, RequestAttemptError>>,
2041-
ResT: AllowedRunRequestResTType,
2038+
QueryFut: Future<Output = Result<NonErrorQueryResponse, RequestAttemptError>>,
20422039
{
20432040
let mut last_error: Option<RequestError> = None;
20442041
let mut current_consistency: Consistency = context
@@ -2079,7 +2076,7 @@ impl Session {
20792076

20802077
let attempt_id: Option<history::AttemptId> =
20812078
context.log_attempt_start(connect_address);
2082-
let request_result: Result<ResT, RequestAttemptError> =
2079+
let request_result: Result<NonErrorQueryResponse, RequestAttemptError> =
20832080
run_request_once(connection, current_consistency, execution_profile)
20842081
.instrument(span.clone())
20852082
.await;
@@ -2348,21 +2345,6 @@ impl Session {
23482345
}
23492346
}
23502347

2351-
// run_request, run_request_speculative_fiber, etc have a template type called ResT.
2352-
// There was a bug where ResT was set to QueryResponse, which could
2353-
// be an error response. This was not caught by retry policy which
2354-
// assumed all errors would come from analyzing Result<ResT, ExecutionError>.
2355-
// This trait is a guard to make sure that this mistake doesn't
2356-
// happen again.
2357-
// When using run_request make sure that the ResT type is NOT able
2358-
// to contain any errors.
2359-
// See https://github.com/scylladb/scylla-rust-driver/issues/501
2360-
pub(crate) trait AllowedRunRequestResTType {}
2361-
2362-
impl AllowedRunRequestResTType for Uuid {}
2363-
impl AllowedRunRequestResTType for QueryResult {}
2364-
impl AllowedRunRequestResTType for NonErrorQueryResponse {}
2365-
23662348
struct ExecuteRequestContext<'a> {
23672349
is_idempotent: bool,
23682350
consistency_set_on_statement: Option<Consistency>,

0 commit comments

Comments
 (0)