@@ -188,10 +188,15 @@ impl<PdC: PdClient> Client<PdC> {
188
188
/// # });
189
189
/// ```
190
190
pub async fn get ( & self , key : impl Into < Key > ) -> Result < Option < Value > > {
191
+ self . get_opt ( key, DEFAULT_REGION_BACKOFF ) . await
192
+ }
193
+
194
+ /// Same as [`get`](Client::get) but with custom [`backoff`](crate::Backoff) strategy.
195
+ pub async fn get_opt ( & self , key : impl Into < Key > , backoff : Backoff ) -> Result < Option < Value > > {
191
196
debug ! ( self . logger, "invoking raw get request" ) ;
192
197
let request = new_raw_get_request ( key. into ( ) , self . cf . clone ( ) ) ;
193
198
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
194
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
199
+ . retry_multi_region ( backoff )
195
200
. merge ( CollectSingle )
196
201
. post_process_default ( )
197
202
. plan ( ) ;
@@ -219,11 +224,20 @@ impl<PdC: PdClient> Client<PdC> {
219
224
pub async fn batch_get (
220
225
& self ,
221
226
keys : impl IntoIterator < Item = impl Into < Key > > ,
227
+ ) -> Result < Vec < KvPair > > {
228
+ self . batch_get_opt ( keys, DEFAULT_REGION_BACKOFF ) . await
229
+ }
230
+
231
+ /// Same as [`batch_get`](Client::batch_get) but with custom [`backoff`](crate::Backoff) strategy.
232
+ pub async fn batch_get_opt (
233
+ & self ,
234
+ keys : impl IntoIterator < Item = impl Into < Key > > ,
235
+ backoff : Backoff ,
222
236
) -> Result < Vec < KvPair > > {
223
237
debug ! ( self . logger, "invoking raw batch_get request" ) ;
224
238
let request = new_raw_batch_get_request ( keys. into_iter ( ) . map ( Into :: into) , self . cf . clone ( ) ) ;
225
239
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
226
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
240
+ . retry_multi_region ( backoff )
227
241
. merge ( Collect )
228
242
. plan ( ) ;
229
243
plan. execute ( )
@@ -248,10 +262,20 @@ impl<PdC: PdClient> Client<PdC> {
248
262
/// # });
249
263
/// ```
250
264
pub async fn put ( & self , key : impl Into < Key > , value : impl Into < Value > ) -> Result < ( ) > {
265
+ self . put_opt ( key, value, DEFAULT_REGION_BACKOFF ) . await
266
+ }
267
+
268
+ /// Same as [`put`](Client::put) but with custom [`backoff`](crate::Backoff) strategy.
269
+ pub async fn put_opt (
270
+ & self ,
271
+ key : impl Into < Key > ,
272
+ value : impl Into < Value > ,
273
+ backoff : Backoff ,
274
+ ) -> Result < ( ) > {
251
275
debug ! ( self . logger, "invoking raw put request" ) ;
252
276
let request = new_raw_put_request ( key. into ( ) , value. into ( ) , self . cf . clone ( ) , self . atomic ) ;
253
277
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
254
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
278
+ . retry_multi_region ( backoff )
255
279
. merge ( CollectSingle )
256
280
. extract_error ( )
257
281
. plan ( ) ;
@@ -279,6 +303,15 @@ impl<PdC: PdClient> Client<PdC> {
279
303
pub async fn batch_put (
280
304
& self ,
281
305
pairs : impl IntoIterator < Item = impl Into < KvPair > > ,
306
+ ) -> Result < ( ) > {
307
+ self . batch_put_opt ( pairs, DEFAULT_REGION_BACKOFF ) . await
308
+ }
309
+
310
+ /// Same as [`batch_put`](Client::batch_put) but with custom [`backoff`](crate::Backoff) strategy.
311
+ pub async fn batch_put_opt (
312
+ & self ,
313
+ pairs : impl IntoIterator < Item = impl Into < KvPair > > ,
314
+ backoff : Backoff ,
282
315
) -> Result < ( ) > {
283
316
debug ! ( self . logger, "invoking raw batch_put request" ) ;
284
317
let request = new_raw_batch_put_request (
@@ -287,7 +320,7 @@ impl<PdC: PdClient> Client<PdC> {
287
320
self . atomic ,
288
321
) ;
289
322
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
290
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
323
+ . retry_multi_region ( backoff )
291
324
. extract_error ( )
292
325
. plan ( ) ;
293
326
plan. execute ( ) . await ?;
@@ -312,10 +345,15 @@ impl<PdC: PdClient> Client<PdC> {
312
345
/// # });
313
346
/// ```
314
347
pub async fn delete ( & self , key : impl Into < Key > ) -> Result < ( ) > {
348
+ self . delete_opt ( key, DEFAULT_REGION_BACKOFF ) . await
349
+ }
350
+
351
+ /// Same as [`delete`](Client::delete) but with custom [`backoff`](crate::Backoff) strategy.
352
+ pub async fn delete_opt ( & self , key : impl Into < Key > , backoff : Backoff ) -> Result < ( ) > {
315
353
debug ! ( self . logger, "invoking raw delete request" ) ;
316
354
let request = new_raw_delete_request ( key. into ( ) , self . cf . clone ( ) , self . atomic ) ;
317
355
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
318
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
356
+ . retry_multi_region ( backoff )
319
357
. merge ( CollectSingle )
320
358
. extract_error ( )
321
359
. plan ( ) ;
@@ -341,12 +379,21 @@ impl<PdC: PdClient> Client<PdC> {
341
379
/// # });
342
380
/// ```
343
381
pub async fn batch_delete ( & self , keys : impl IntoIterator < Item = impl Into < Key > > ) -> Result < ( ) > {
382
+ self . batch_delete_opt ( keys, DEFAULT_REGION_BACKOFF ) . await
383
+ }
384
+
385
+ /// Same as [`batch_delete`](Client::batch_delete) but with custom [`backoff`](crate::Backoff) strategy.
386
+ pub async fn batch_delete_opt (
387
+ & self ,
388
+ keys : impl IntoIterator < Item = impl Into < Key > > ,
389
+ backoff : Backoff ,
390
+ ) -> Result < ( ) > {
344
391
debug ! ( self . logger, "invoking raw batch_delete request" ) ;
345
392
self . assert_non_atomic ( ) ?;
346
393
let request =
347
394
new_raw_batch_delete_request ( keys. into_iter ( ) . map ( Into :: into) , self . cf . clone ( ) ) ;
348
395
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
349
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
396
+ . retry_multi_region ( backoff )
350
397
. extract_error ( )
351
398
. plan ( ) ;
352
399
plan. execute ( ) . await ?;
@@ -372,6 +419,7 @@ impl<PdC: PdClient> Client<PdC> {
372
419
self . delete_range_opt ( range, DEFAULT_REGION_BACKOFF ) . await
373
420
}
374
421
422
+ /// Same as [`delete_range`](Client::delete_range) but with custom [`backoff`](crate::Backoff) strategy.
375
423
pub async fn delete_range_opt (
376
424
& self ,
377
425
range : impl Into < BoundRange > ,
@@ -408,8 +456,18 @@ impl<PdC: PdClient> Client<PdC> {
408
456
/// # });
409
457
/// ```
410
458
pub async fn scan ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < KvPair > > {
459
+ self . scan_opt ( range, limit, DEFAULT_REGION_BACKOFF ) . await
460
+ }
461
+
462
+ /// Same as [`scan`](Client::scan) but with custom [`backoff`](crate::Backoff) strategy.
463
+ pub async fn scan_opt (
464
+ & self ,
465
+ range : impl Into < BoundRange > ,
466
+ limit : u32 ,
467
+ backoff : Backoff ,
468
+ ) -> Result < Vec < KvPair > > {
411
469
debug ! ( self . logger, "invoking raw scan request" ) ;
412
- self . scan_inner ( range. into ( ) , limit, false ) . await
470
+ self . scan_inner ( range. into ( ) , limit, false , backoff ) . await
413
471
}
414
472
415
473
/// Create a new 'scan' request that only returns the keys.
@@ -432,9 +490,20 @@ impl<PdC: PdClient> Client<PdC> {
432
490
/// # });
433
491
/// ```
434
492
pub async fn scan_keys ( & self , range : impl Into < BoundRange > , limit : u32 ) -> Result < Vec < Key > > {
493
+ self . scan_keys_opt ( range, limit, DEFAULT_REGION_BACKOFF )
494
+ . await
495
+ }
496
+
497
+ /// Same as [`scan_keys`](Client::scan_keys) but with custom [`backoff`](crate::Backoff) strategy.
498
+ pub async fn scan_keys_opt (
499
+ & self ,
500
+ range : impl Into < BoundRange > ,
501
+ limit : u32 ,
502
+ backoff : Backoff ,
503
+ ) -> Result < Vec < Key > > {
435
504
debug ! ( self . logger, "invoking raw scan_keys request" ) ;
436
505
Ok ( self
437
- . scan_inner ( range, limit, true )
506
+ . scan_inner ( range, limit, true , backoff )
438
507
. await ?
439
508
. into_iter ( )
440
509
. map ( KvPair :: into_key)
@@ -468,9 +537,21 @@ impl<PdC: PdClient> Client<PdC> {
468
537
& self ,
469
538
ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
470
539
each_limit : u32 ,
540
+ ) -> Result < Vec < KvPair > > {
541
+ self . batch_scan_opt ( ranges, each_limit, DEFAULT_REGION_BACKOFF )
542
+ . await
543
+ }
544
+
545
+ /// Same as [`batch_scan`](Client::batch_scan) but with custom [`backoff`](crate::Backoff) strategy.
546
+ pub async fn batch_scan_opt (
547
+ & self ,
548
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
549
+ each_limit : u32 ,
550
+ backoff : Backoff ,
471
551
) -> Result < Vec < KvPair > > {
472
552
debug ! ( self . logger, "invoking raw batch_scan request" ) ;
473
- self . batch_scan_inner ( ranges, each_limit, false ) . await
553
+ self . batch_scan_inner ( ranges, each_limit, false , backoff)
554
+ . await
474
555
}
475
556
476
557
/// Create a new 'batch scan' request that only returns the keys.
@@ -500,10 +581,21 @@ impl<PdC: PdClient> Client<PdC> {
500
581
& self ,
501
582
ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
502
583
each_limit : u32 ,
584
+ ) -> Result < Vec < Key > > {
585
+ self . batch_scan_keys_opt ( ranges, each_limit, DEFAULT_REGION_BACKOFF )
586
+ . await
587
+ }
588
+
589
+ /// Same as [`batch_scan_keys`](Client::batch_scan_keys) but with custom [`backoff`](crate::Backoff) strategy.
590
+ pub async fn batch_scan_keys_opt (
591
+ & self ,
592
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
593
+ each_limit : u32 ,
594
+ backoff : Backoff ,
503
595
) -> Result < Vec < Key > > {
504
596
debug ! ( self . logger, "invoking raw batch_scan_keys request" ) ;
505
597
Ok ( self
506
- . batch_scan_inner ( ranges, each_limit, true )
598
+ . batch_scan_inner ( ranges, each_limit, true , backoff )
507
599
. await ?
508
600
. into_iter ( )
509
601
. map ( KvPair :: into_key)
@@ -527,6 +619,18 @@ impl<PdC: PdClient> Client<PdC> {
527
619
key : impl Into < Key > ,
528
620
previous_value : impl Into < Option < Value > > ,
529
621
new_value : impl Into < Value > ,
622
+ ) -> Result < ( Option < Value > , bool ) > {
623
+ self . compare_and_swap_opt ( key, previous_value, new_value, DEFAULT_REGION_BACKOFF )
624
+ . await
625
+ }
626
+
627
+ /// Same as [`compare_and_swap`](Client::compare_and_swap) but with custom [`backoff`](crate::Backoff) strategy.
628
+ pub async fn compare_and_swap_opt (
629
+ & self ,
630
+ key : impl Into < Key > ,
631
+ previous_value : impl Into < Option < Value > > ,
632
+ new_value : impl Into < Value > ,
633
+ backoff : Backoff ,
530
634
) -> Result < ( Option < Value > , bool ) > {
531
635
debug ! ( self . logger, "invoking raw compare_and_swap request" ) ;
532
636
self . assert_atomic ( ) ?;
@@ -537,7 +641,7 @@ impl<PdC: PdClient> Client<PdC> {
537
641
self . cf . clone ( ) ,
538
642
) ;
539
643
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , req)
540
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
644
+ . retry_multi_region ( backoff )
541
645
. merge ( CollectSingle )
542
646
. post_process_default ( )
543
647
. plan ( ) ;
@@ -550,6 +654,25 @@ impl<PdC: PdClient> Client<PdC> {
550
654
copr_version_req : impl Into < String > ,
551
655
ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
552
656
request_builder : impl Fn ( metapb:: Region , Vec < Range < Key > > ) -> Vec < u8 > + Send + Sync + ' static ,
657
+ ) -> Result < Vec < ( Vec < u8 > , Vec < Range < Key > > ) > > {
658
+ self . coprocessor_opt (
659
+ copr_name,
660
+ copr_version_req,
661
+ ranges,
662
+ request_builder,
663
+ DEFAULT_REGION_BACKOFF ,
664
+ )
665
+ . await
666
+ }
667
+
668
+ /// Same as [`coprocessor`](Client::coprocessor) but with custom [`backoff`](crate::Backoff) strategy.
669
+ pub async fn coprocessor_opt (
670
+ & self ,
671
+ copr_name : impl Into < String > ,
672
+ copr_version_req : impl Into < String > ,
673
+ ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
674
+ request_builder : impl Fn ( metapb:: Region , Vec < Range < Key > > ) -> Vec < u8 > + Send + Sync + ' static ,
675
+ backoff : Backoff ,
553
676
) -> Result < Vec < ( Vec < u8 > , Vec < Range < Key > > ) > > {
554
677
let copr_version_req = copr_version_req. into ( ) ;
555
678
semver:: VersionReq :: from_str ( & copr_version_req) ?;
@@ -561,7 +684,7 @@ impl<PdC: PdClient> Client<PdC> {
561
684
) ;
562
685
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , req)
563
686
. preserve_shard ( )
564
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
687
+ . retry_multi_region ( backoff )
565
688
. post_process_default ( )
566
689
. plan ( ) ;
567
690
plan. execute ( ) . await
@@ -572,6 +695,7 @@ impl<PdC: PdClient> Client<PdC> {
572
695
range : impl Into < BoundRange > ,
573
696
limit : u32 ,
574
697
key_only : bool ,
698
+ backoff : Backoff ,
575
699
) -> Result < Vec < KvPair > > {
576
700
if limit > MAX_RAW_KV_SCAN_LIMIT {
577
701
return Err ( Error :: MaxScanLimitExceeded {
@@ -582,7 +706,7 @@ impl<PdC: PdClient> Client<PdC> {
582
706
583
707
let request = new_raw_scan_request ( range. into ( ) , limit, key_only, self . cf . clone ( ) ) ;
584
708
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
585
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
709
+ . retry_multi_region ( backoff )
586
710
. merge ( Collect )
587
711
. plan ( ) ;
588
712
let res = plan. execute ( ) . await ;
@@ -597,6 +721,7 @@ impl<PdC: PdClient> Client<PdC> {
597
721
ranges : impl IntoIterator < Item = impl Into < BoundRange > > ,
598
722
each_limit : u32 ,
599
723
key_only : bool ,
724
+ backoff : Backoff ,
600
725
) -> Result < Vec < KvPair > > {
601
726
if each_limit > MAX_RAW_KV_SCAN_LIMIT {
602
727
return Err ( Error :: MaxScanLimitExceeded {
@@ -612,7 +737,7 @@ impl<PdC: PdClient> Client<PdC> {
612
737
self . cf . clone ( ) ,
613
738
) ;
614
739
let plan = crate :: request:: PlanBuilder :: new ( self . rpc . clone ( ) , request)
615
- . retry_multi_region ( DEFAULT_REGION_BACKOFF )
740
+ . retry_multi_region ( backoff )
616
741
. merge ( Collect )
617
742
. plan ( ) ;
618
743
plan. execute ( ) . await
0 commit comments