@@ -33,7 +33,11 @@ use crate::{
3333 client:: GlideConnectionOptions ,
3434 cluster_routing:: { Routable , RoutingInfo } ,
3535 cluster_slotmap:: SlotMap ,
36- cluster_topology:: SLOT_SIZE ,
36+ cluster_topology:: {
37+ calculate_topology, get_slot, SlotRefreshState , DEFAULT_NUMBER_OF_REFRESH_SLOTS_RETRIES ,
38+ DEFAULT_REFRESH_SLOTS_RETRY_BASE_DURATION_MILLIS , DEFAULT_REFRESH_SLOTS_RETRY_BASE_FACTOR ,
39+ SLOT_SIZE ,
40+ } ,
3741 cmd,
3842 commands:: cluster_scan:: { cluster_scan, ClusterScanArgs , ObjectType , ScanStateRC } ,
3943 FromRedisValue , InfoDict , ToRedisArgs ,
@@ -69,10 +73,6 @@ use crate::{
6973 self , MultipleNodeRoutingInfo , Redirect , ResponsePolicy , Route , SingleNodeRoutingInfo ,
7074 SlotAddr ,
7175 } ,
72- cluster_topology:: {
73- calculate_topology, get_slot, SlotRefreshState , DEFAULT_NUMBER_OF_REFRESH_SLOTS_RETRIES ,
74- DEFAULT_REFRESH_SLOTS_RETRY_INITIAL_INTERVAL , DEFAULT_REFRESH_SLOTS_RETRY_MAX_INTERVAL ,
75- } ,
7676 connection:: { PubSubSubscriptionInfo , PubSubSubscriptionKind } ,
7777 push_manager:: PushInfo ,
7878 Cmd , ConnectionInfo , ErrorKind , IntoConnectionInfo , RedisError , RedisFuture , RedisResult ,
@@ -84,9 +84,10 @@ use std::time::Duration;
8484#[ cfg( feature = "tokio-comp" ) ]
8585use async_trait:: async_trait;
8686#[ cfg( feature = "tokio-comp" ) ]
87- use backoff_tokio :: future :: retry ;
87+ use tokio_retry2 :: strategy :: { jitter_range , ExponentialFactorBackoff } ;
8888#[ cfg( feature = "tokio-comp" ) ]
89- use backoff_tokio:: { Error as BackoffError , ExponentialBackoff } ;
89+ use tokio_retry2:: { Retry , RetryError } ;
90+
9091#[ cfg( feature = "tokio-comp" ) ]
9192use tokio:: { sync:: Notify , time:: timeout} ;
9293
@@ -1518,16 +1519,24 @@ where
15181519
15191520 let mut res = Ok ( ( ) ) ;
15201521 if !skip_slots_refresh {
1521- let retry_strategy = ExponentialBackoff {
1522- initial_interval : DEFAULT_REFRESH_SLOTS_RETRY_INITIAL_INTERVAL ,
1523- max_interval : DEFAULT_REFRESH_SLOTS_RETRY_MAX_INTERVAL ,
1524- max_elapsed_time : None ,
1525- .. Default :: default ( )
1526- } ;
1522+ let retry_strategy = ExponentialFactorBackoff :: from_millis (
1523+ DEFAULT_REFRESH_SLOTS_RETRY_BASE_DURATION_MILLIS ,
1524+ DEFAULT_REFRESH_SLOTS_RETRY_BASE_FACTOR ,
1525+ )
1526+ . map ( jitter_range ( 0.8 , 1.2 ) )
1527+ . take ( DEFAULT_NUMBER_OF_REFRESH_SLOTS_RETRIES ) ;
15271528 let retries_counter = AtomicUsize :: new ( 0 ) ;
1528- res = retry ( retry_strategy, || {
1529+ res = Retry :: spawn ( retry_strategy, || async {
15291530 let curr_retry = retries_counter. fetch_add ( 1 , atomic:: Ordering :: Relaxed ) ;
15301531 Self :: refresh_slots ( inner. clone ( ) , curr_retry)
1532+ . await
1533+ . map_err ( |err| {
1534+ if err. kind ( ) == ErrorKind :: AllConnectionsUnavailable {
1535+ RetryError :: permanent ( err)
1536+ } else {
1537+ RetryError :: transient ( err)
1538+ }
1539+ } )
15311540 } )
15321541 . await ;
15331542 }
@@ -1706,26 +1715,13 @@ where
17061715 false
17071716 }
17081717
1709- async fn refresh_slots (
1710- inner : Arc < InnerCore < C > > ,
1711- curr_retry : usize ,
1712- ) -> Result < ( ) , BackoffError < RedisError > > {
1718+ async fn refresh_slots ( inner : Arc < InnerCore < C > > , curr_retry : usize ) -> RedisResult < ( ) > {
17131719 // Update the slot refresh last run timestamp
17141720 let now = SystemTime :: now ( ) ;
17151721 let mut last_run_wlock = inner. slot_refresh_state . last_run . write ( ) . await ;
17161722 * last_run_wlock = Some ( now) ;
17171723 drop ( last_run_wlock) ;
1718- Self :: refresh_slots_inner ( inner, curr_retry)
1719- . await
1720- . map_err ( |err| {
1721- if curr_retry > DEFAULT_NUMBER_OF_REFRESH_SLOTS_RETRIES
1722- || err. kind ( ) == ErrorKind :: AllConnectionsUnavailable
1723- {
1724- BackoffError :: Permanent ( err)
1725- } else {
1726- BackoffError :: from ( err)
1727- }
1728- } )
1724+ Self :: refresh_slots_inner ( inner, curr_retry) . await
17291725 }
17301726
17311727 pub ( crate ) fn check_if_all_slots_covered ( slot_map : & SlotMap ) -> bool {
0 commit comments