@@ -774,7 +774,7 @@ impl<PdC: PdClient> Client<PdC> {
774
774
let scan_args = ScanInnerArgs {
775
775
start_key : current_key. clone ( ) ,
776
776
range : range. clone ( ) ,
777
- limit,
777
+ limit : current_limit ,
778
778
key_only,
779
779
reverse,
780
780
backoff : backoff. clone ( ) ,
@@ -789,12 +789,7 @@ impl<PdC: PdClient> Client<PdC> {
789
789
current_limit -= kvs. len ( ) as u32 ;
790
790
result. append ( & mut kvs) ;
791
791
}
792
- if end_key
793
- . as_ref ( )
794
- . map ( |ek| ek <= next_key. as_ref ( ) )
795
- . unwrap_or ( false )
796
- || next_key. is_empty ( )
797
- {
792
+ if end_key. clone ( ) . is_some_and ( |ek| ek <= next_key) {
798
793
break ;
799
794
} else {
800
795
current_key = next_key;
@@ -928,13 +923,11 @@ struct ScanInnerArgs {
928
923
#[ cfg( test) ]
929
924
mod tests {
930
925
use std:: any:: Any ;
931
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
932
926
use std:: sync:: Arc ;
933
927
934
928
use super :: * ;
935
929
use crate :: mock:: MockKvClient ;
936
930
use crate :: mock:: MockPdClient ;
937
- use crate :: proto:: errorpb:: EpochNotMatch ;
938
931
use crate :: proto:: kvrpcpb;
939
932
use crate :: Result ;
940
933
@@ -1016,63 +1009,4 @@ mod tests {
1016
1009
) ;
1017
1010
Ok ( ( ) )
1018
1011
}
1019
-
1020
- #[ tokio:: test]
1021
- async fn test_raw_scan_retryer ( ) -> Result < ( ) > {
1022
- let epoch_not_match_error = EpochNotMatch {
1023
- current_regions : vec ! [ ] ,
1024
- } ;
1025
- let region_error = errorpb:: Error {
1026
- epoch_not_match : Some ( epoch_not_match_error) ,
1027
- ..Default :: default ( )
1028
- } ;
1029
- let flag = Arc :: new ( AtomicBool :: new ( true ) ) ;
1030
- let tikv_flag = flag. clone ( ) ;
1031
- let error_handler_flag = flag. clone ( ) ;
1032
- let mock_tikv_client = MockKvClient :: with_dispatch_hook ( move |req : & dyn Any | {
1033
- if req. downcast_ref :: < RawScanRequest > ( ) . is_some ( ) {
1034
- let v = tikv_flag. clone ( ) . load ( Ordering :: Relaxed ) ;
1035
- let resp = if v {
1036
- RawScanResponse {
1037
- region_error : Some ( region_error. clone ( ) ) ,
1038
- ..Default :: default ( )
1039
- }
1040
- } else {
1041
- RawScanResponse {
1042
- ..Default :: default ( )
1043
- }
1044
- } ;
1045
- Ok ( Box :: new ( resp) as Box < dyn Any > )
1046
- } else {
1047
- unreachable ! ( )
1048
- }
1049
- } ) ;
1050
- let mock_pd_client = MockPdClient :: new ( mock_tikv_client) ;
1051
- let client = Client {
1052
- rpc : Arc :: new ( mock_pd_client) ,
1053
- cf : Some ( ColumnFamily :: Default ) ,
1054
- backoff : DEFAULT_REGION_BACKOFF ,
1055
- atomic : false ,
1056
- keyspace : Keyspace :: Enable { keyspace_id : 0 } ,
1057
- } ;
1058
-
1059
- let scan_args = ScanInnerArgs {
1060
- start_key : "k1" . to_string ( ) . into ( ) ,
1061
- range : BoundRange :: from ( "k1" . to_owned ( ) .."k2" . to_owned ( ) ) ,
1062
- limit : 10 ,
1063
- key_only : false ,
1064
- reverse : false ,
1065
- backoff : Backoff :: no_backoff ( ) ,
1066
- } ;
1067
- let error_handler = |_, _, _| {
1068
- error_handler_flag. clone ( ) . store ( false , Ordering :: Relaxed ) ;
1069
- Box :: pin ( async move {
1070
- let res: Result < bool > = Ok ( true ) ;
1071
- res
1072
- } )
1073
- } as _ ;
1074
- client. retryable_scan ( scan_args, error_handler) . await ?;
1075
- assert ! ( !error_handler_flag. load( Ordering :: Relaxed ) ) ;
1076
- Ok ( ( ) )
1077
- }
1078
1012
}
0 commit comments