File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ use crate::Key;
3131use crate :: KvPair ;
3232use crate :: Result ;
3333use crate :: Value ;
34+ use crate :: request:: plan:: is_grpc_error;
3435
3536const MAX_RAW_KV_SCAN_LIMIT : u32 = 10240 ;
3637
@@ -835,6 +836,17 @@ impl<PdC: PdClient> Client<PdC> {
835836 }
836837 Ok ( ( Some ( r) , region. end_key ( ) ) )
837838 }
839+ Err ( err) if is_grpc_error ( & err) => {
840+ debug ! ( "retryable_scan: grpc error: {:?}" , err) ;
841+ plan:: invalidate_cache ( self . rpc . clone ( ) , store. clone ( ) ) . await ;
842+
843+ if let Some ( duration) = scan_args. backoff . next_delay_duration ( ) {
844+ sleep ( duration) . await ;
845+ continue ;
846+ } else {
847+ return Err ( err) ;
848+ }
849+ }
838850 Err ( err) => Err ( err) ,
839851 } ;
840852 }
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ impl<Req: KvRequest + StoreRequest> StoreRequest for Dispatch<Req> {
8787const MULTI_REGION_CONCURRENCY : usize = 16 ;
8888const MULTI_STORES_CONCURRENCY : usize = 16 ;
8989
90- fn is_grpc_error ( e : & Error ) -> bool {
90+ pub ( crate ) fn is_grpc_error ( e : & Error ) -> bool {
9191 matches ! ( e, Error :: GrpcAPI ( _) | Error :: Grpc ( _) )
9292}
9393
@@ -344,6 +344,18 @@ pub(crate) async fn handle_region_error<PdC: PdClient>(
344344 }
345345}
346346
347+ pub ( crate ) async fn invalidate_cache < PdC : PdClient > (
348+ pd_client : Arc < PdC > ,
349+ region_store : RegionStore ,
350+ ) {
351+ let ver_id = region_store. region_with_leader . ver_id ( ) ;
352+ let store_id = region_store. region_with_leader . get_store_id ( ) ;
353+ pd_client. invalidate_region_cache ( ver_id) . await ;
354+ if let Ok ( store_id) = store_id {
355+ pd_client. invalidate_store_cache ( store_id) . await ;
356+ }
357+ }
358+
347359// Returns
348360// 1. Ok(true): error has been resolved, retry immediately
349361// 2. Ok(false): backoff, and then retry
You can’t perform that action at this time.
0 commit comments