@@ -1115,10 +1115,6 @@ impl Session {
1115
1115
RunRequestResult :: Completed ( response) => response,
1116
1116
} ;
1117
1117
1118
- self . handle_set_keyspace_response ( & response) . await ?;
1119
- self . handle_auto_await_schema_agreement ( & response, coordinator. node ( ) . host_id )
1120
- . await ?;
1121
-
1122
1118
let ( result, paging_state_response) =
1123
1119
response. into_query_result_and_paging_state ( coordinator) ?;
1124
1120
span. record_result_fields ( & result) ;
@@ -1491,10 +1487,6 @@ impl Session {
1491
1487
RunRequestResult :: Completed ( response) => response,
1492
1488
} ;
1493
1489
1494
- self . handle_set_keyspace_response ( & response) . await ?;
1495
- self . handle_auto_await_schema_agreement ( & response, coordinator. node ( ) . host_id )
1496
- . await ?;
1497
-
1498
1490
let ( result, paging_state_response) =
1499
1491
response. into_query_result_and_paging_state ( coordinator) ?;
1500
1492
span. record_result_fields ( & result) ;
@@ -1858,17 +1850,16 @@ impl Session {
1858
1850
/// On success, this request's result is returned.
1859
1851
// I tried to make this closures take a reference instead of an Arc but failed
1860
1852
// 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 > (
1862
1854
& ' a self ,
1863
1855
statement_info : RoutingInfo < ' a > ,
1864
1856
statement_config : & ' a StatementConfig ,
1865
1857
execution_profile : Arc < ExecutionProfileInner > ,
1866
1858
run_request_once : impl Fn ( Arc < Connection > , Consistency , & ExecutionProfileInner ) -> QueryFut ,
1867
1859
request_span : & ' a RequestSpan ,
1868
- ) -> Result < ( RunRequestResult < ResT > , Coordinator ) , ExecutionError >
1860
+ ) -> Result < ( RunRequestResult < NonErrorQueryResponse > , Coordinator ) , ExecutionError >
1869
1861
where
1870
- QueryFut : Future < Output = Result < ResT , RequestAttemptError > > ,
1871
- ResT : AllowedRunRequestResTType ,
1862
+ QueryFut : Future < Output = Result < NonErrorQueryResponse , RequestAttemptError > > ,
1872
1863
{
1873
1864
let history_listener_and_id: Option < ( & ' a dyn HistoryListener , history:: RequestId ) > =
1874
1865
statement_config
@@ -2021,6 +2012,13 @@ impl Session {
2021
2012
}
2022
2013
}
2023
2014
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
+
2024
2022
result. map_err ( RequestError :: into_execution_error)
2025
2023
}
2026
2024
@@ -2029,16 +2027,15 @@ impl Session {
2029
2027
/// If request fails, retry session is used to perform retries.
2030
2028
///
2031
2029
/// 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 > (
2033
2031
& ' a self ,
2034
2032
request_plan : impl Iterator < Item = ( NodeRef < ' a > , Shard ) > ,
2035
2033
run_request_once : impl Fn ( Arc < Connection > , Consistency , & ExecutionProfileInner ) -> QueryFut ,
2036
2034
execution_profile : & ExecutionProfileInner ,
2037
2035
mut context : ExecuteRequestContext < ' a > ,
2038
- ) -> Option < Result < ( RunRequestResult < ResT > , Coordinator ) , RequestError > >
2036
+ ) -> Option < Result < ( RunRequestResult < NonErrorQueryResponse > , Coordinator ) , RequestError > >
2039
2037
where
2040
- QueryFut : Future < Output = Result < ResT , RequestAttemptError > > ,
2041
- ResT : AllowedRunRequestResTType ,
2038
+ QueryFut : Future < Output = Result < NonErrorQueryResponse , RequestAttemptError > > ,
2042
2039
{
2043
2040
let mut last_error: Option < RequestError > = None ;
2044
2041
let mut current_consistency: Consistency = context
@@ -2079,7 +2076,7 @@ impl Session {
2079
2076
2080
2077
let attempt_id: Option < history:: AttemptId > =
2081
2078
context. log_attempt_start ( connect_address) ;
2082
- let request_result: Result < ResT , RequestAttemptError > =
2079
+ let request_result: Result < NonErrorQueryResponse , RequestAttemptError > =
2083
2080
run_request_once ( connection, current_consistency, execution_profile)
2084
2081
. instrument ( span. clone ( ) )
2085
2082
. await ;
@@ -2348,21 +2345,6 @@ impl Session {
2348
2345
}
2349
2346
}
2350
2347
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
-
2366
2348
struct ExecuteRequestContext < ' a > {
2367
2349
is_idempotent : bool ,
2368
2350
consistency_set_on_statement : Option < Consistency > ,
0 commit comments