@@ -332,16 +332,24 @@ impl Client {
332
332
Ok ( c) => c,
333
333
Err ( mut err) => {
334
334
err. add_labels_and_update_pin ( None , & mut session, None ) ?;
335
+ if err. is_read_retryable ( ) && self . inner . options . retry_writes != Some ( false ) {
336
+ err. add_label ( RETRYABLE_WRITE_ERROR ) ;
337
+ }
335
338
336
- if err. is_pool_cleared ( ) {
339
+ let op_retry = match self . get_op_retryability ( & op, & session) {
340
+ Retryability :: Read => err. is_read_retryable ( ) ,
341
+ Retryability :: Write => err. is_write_retryable ( ) ,
342
+ _ => false ,
343
+ } ;
344
+ if err. is_pool_cleared ( ) || op_retry {
337
345
return self . execute_retry ( & mut op, & mut session, None , err) . await ;
338
346
} else {
339
347
return Err ( err) ;
340
348
}
341
349
}
342
350
} ;
343
351
344
- let retryability = self . get_retryability ( & conn, & op, & session) . await ?;
352
+ let retryability = self . get_retryability ( & conn, & op, & session) ?;
345
353
346
354
let txn_number = match session {
347
355
Some ( ref mut session) => {
@@ -433,7 +441,7 @@ impl Client {
433
441
Err ( _) => return Err ( first_error) ,
434
442
} ;
435
443
436
- let retryability = self . get_retryability ( & conn, op, session) . await ?;
444
+ let retryability = self . get_retryability ( & conn, op, session) ?;
437
445
if retryability == Retryability :: None {
438
446
return Err ( first_error) ;
439
447
}
@@ -825,35 +833,49 @@ impl Client {
825
833
}
826
834
827
835
/// Returns the retryability level for the execution of this operation.
828
- async fn get_retryability < T : Operation > (
836
+ fn get_op_retryability < T : Operation > (
829
837
& self ,
830
- conn : & Connection ,
831
838
op : & T ,
832
839
session : & Option < & mut ClientSession > ,
833
- ) -> Result < Retryability > {
834
- if ! session
840
+ ) -> Retryability {
841
+ if session
835
842
. as_ref ( )
836
843
. map ( |session| session. in_transaction ( ) )
837
844
. unwrap_or ( false )
838
845
{
839
- match op. retryability ( ) {
840
- Retryability :: Read if self . inner . options . retry_reads != Some ( false ) => {
841
- return Ok ( Retryability :: Read ) ;
842
- }
843
- Retryability :: Write if conn. stream_description ( ) ?. supports_retryable_writes ( ) => {
844
- // commitTransaction and abortTransaction should be retried regardless of the
845
- // value for retry_writes set on the Client
846
- if op. name ( ) == CommitTransaction :: NAME
847
- || op. name ( ) == AbortTransaction :: NAME
848
- || self . inner . options . retry_writes != Some ( false )
849
- {
850
- return Ok ( Retryability :: Write ) ;
851
- }
852
- }
853
- _ => { }
846
+ return Retryability :: None ;
847
+ }
848
+ match op. retryability ( ) {
849
+ Retryability :: Read if self . inner . options . retry_reads != Some ( false ) => {
850
+ Retryability :: Read
851
+ }
852
+ // commitTransaction and abortTransaction should be retried regardless of the
853
+ // value for retry_writes set on the Client
854
+ Retryability :: Write
855
+ if op. name ( ) == CommitTransaction :: NAME
856
+ || op. name ( ) == AbortTransaction :: NAME
857
+ || self . inner . options . retry_writes != Some ( false ) =>
858
+ {
859
+ Retryability :: Write
860
+ }
861
+ _ => Retryability :: None ,
862
+ }
863
+ }
864
+
865
+ /// Returns the retryability level for the execution of this operation on this connection.
866
+ fn get_retryability < T : Operation > (
867
+ & self ,
868
+ conn : & Connection ,
869
+ op : & T ,
870
+ session : & Option < & mut ClientSession > ,
871
+ ) -> Result < Retryability > {
872
+ match self . get_op_retryability ( op, session) {
873
+ Retryability :: Read => Ok ( Retryability :: Read ) ,
874
+ Retryability :: Write if conn. stream_description ( ) ?. supports_retryable_writes ( ) => {
875
+ Ok ( Retryability :: Write )
854
876
}
877
+ _ => Ok ( Retryability :: None ) ,
855
878
}
856
- Ok ( Retryability :: None )
857
879
}
858
880
859
881
async fn update_cluster_time (
0 commit comments