@@ -231,12 +231,11 @@ impl RpcClient {
231
231
key : & Key ,
232
232
cf : Option < ColumnFamily > ,
233
233
) -> impl Future < Item = RawContext , Error = Error > {
234
- Self :: region_context ( inner, key)
235
- . map ( move |( region, client) | RawContext :: new ( region, client, cf) )
234
+ Self :: region_context ( inner, key) . map ( |( region, client) | RawContext :: new ( region, client, cf) )
236
235
}
237
236
238
237
fn txn ( inner : Arc < RpcClientInner > , key : & Key ) -> impl Future < Item = TxnContext , Error = Error > {
239
- Self :: region_context ( inner, key) . map ( move |( region, _client) | TxnContext :: new ( region) )
238
+ Self :: region_context ( inner, key) . map ( |( region, _client) | TxnContext :: new ( region) )
240
239
}
241
240
242
241
#[ inline]
@@ -248,16 +247,10 @@ impl RpcClient {
248
247
& self ,
249
248
key : Key ,
250
249
cf : Option < ColumnFamily > ,
251
- ) -> impl Future < Item = Value , Error = Error > {
250
+ ) -> impl Future < Item = Option < Value > , Error = Error > {
252
251
Self :: raw ( self . inner ( ) , & key, cf)
253
- . and_then ( move |context| context. client ( ) . raw_get ( context, key) )
254
- . and_then ( move |value| {
255
- if value. is_empty ( ) {
256
- Err ( Error :: NoSuchKey )
257
- } else {
258
- Ok ( value)
259
- }
260
- } )
252
+ . and_then ( |context| context. client ( ) . raw_get ( context, key) )
253
+ . map ( |value| if value. is_empty ( ) { None } else { Some ( value) } )
261
254
}
262
255
263
256
pub fn raw_batch_get (
@@ -274,8 +267,8 @@ impl RpcClient {
274
267
let inner = Arc :: clone ( & inner) ;
275
268
let cf = cf. clone ( ) ;
276
269
let task = Self :: region_context_by_id ( inner, region. id )
277
- . map ( move |( region, client) | RawContext :: new ( region, client, cf) )
278
- . and_then ( move |context| {
270
+ . map ( |( region, client) | RawContext :: new ( region, client, cf) )
271
+ . and_then ( |context| {
279
272
context. client ( ) . raw_batch_get ( context, keys. into_iter ( ) )
280
273
} ) ;
281
274
tasks. push ( task) ;
@@ -296,7 +289,7 @@ impl RpcClient {
296
289
} else {
297
290
Either :: B (
298
291
Self :: raw ( self . inner ( ) , & key, cf)
299
- . and_then ( move |context| context. client ( ) . raw_put ( context, key, value) ) ,
292
+ . and_then ( |context| context. client ( ) . raw_put ( context, key, value) ) ,
300
293
)
301
294
}
302
295
}
@@ -319,10 +312,8 @@ impl RpcClient {
319
312
let inner = Arc :: clone ( & inner) ;
320
313
let cf = cf. clone ( ) ;
321
314
let task = Self :: region_context_by_id ( inner, region. id )
322
- . map ( move |( region, client) | RawContext :: new ( region, client, cf) )
323
- . and_then ( move |context| {
324
- context. client ( ) . raw_batch_put ( context, pairs)
325
- } ) ;
315
+ . map ( |( region, client) | RawContext :: new ( region, client, cf) )
316
+ . and_then ( |context| context. client ( ) . raw_batch_put ( context, pairs) ) ;
326
317
tasks. push ( task) ;
327
318
}
328
319
future:: join_all ( tasks)
@@ -338,7 +329,7 @@ impl RpcClient {
338
329
cf : Option < ColumnFamily > ,
339
330
) -> impl Future < Item = ( ) , Error = Error > {
340
331
Self :: raw ( self . inner ( ) , & key, cf)
341
- . and_then ( move |context| context. client ( ) . raw_delete ( context, key) )
332
+ . and_then ( |context| context. client ( ) . raw_delete ( context, key) )
342
333
}
343
334
344
335
pub fn raw_batch_delete (
@@ -355,8 +346,8 @@ impl RpcClient {
355
346
let inner = Arc :: clone ( & inner) ;
356
347
let cf = cf. clone ( ) ;
357
348
let task = Self :: region_context_by_id ( inner, region. id )
358
- . map ( move |( region, client) | RawContext :: new ( region, client, cf) )
359
- . and_then ( move |context| context. client ( ) . raw_batch_delete ( context, keys) ) ;
349
+ . map ( |( region, client) | RawContext :: new ( region, client, cf) )
350
+ . and_then ( |context| context. client ( ) . raw_batch_delete ( context, keys) ) ;
360
351
tasks. push ( task) ;
361
352
}
362
353
future:: join_all ( tasks)
@@ -386,35 +377,33 @@ impl RpcClient {
386
377
) ;
387
378
let inner = Arc :: clone ( & self . inner ) ;
388
379
loop_fn ( ( inner, scan) , |( inner, scan) | {
389
- inner
390
- . locate_key ( scan. start_key ( ) )
391
- . and_then ( move |location| {
392
- let region = location. into_inner ( ) ;
393
- let cf = scan. cf . clone ( ) ;
394
- Self :: region_context_by_id ( Arc :: clone ( & inner) , region. id )
395
- . map ( move |( region, client) | {
396
- ( scan, region. range ( ) , RawContext :: new ( region, client, cf) )
397
- } )
398
- . and_then ( move |( mut scan, region_range, context) | {
399
- let ( start_key, end_key) = scan. range ( ) ;
400
- context
401
- . client ( )
402
- . raw_scan ( context, start_key, end_key, scan. limit , scan. key_only )
403
- . map ( move |pairs| ( scan, region_range, pairs) )
404
- } )
405
- . map ( move |( mut scan, region_range, mut pairs) | {
406
- let limit = scan. limit ;
407
- scan. result_mut ( ) . append ( & mut pairs) ;
408
- if scan. result ( ) . len ( ) as u32 >= limit {
409
- Loop :: Break ( scan. into_inner ( ) )
410
- } else {
411
- match scan. next ( region_range) {
412
- ScanRegionsStatus :: Continue => Loop :: Continue ( ( inner, scan) ) ,
413
- ScanRegionsStatus :: Break => Loop :: Break ( scan. into_inner ( ) ) ,
414
- }
380
+ inner. locate_key ( scan. start_key ( ) ) . and_then ( |location| {
381
+ let region = location. into_inner ( ) ;
382
+ let cf = scan. cf . clone ( ) ;
383
+ Self :: region_context_by_id ( Arc :: clone ( & inner) , region. id )
384
+ . map ( |( region, client) | {
385
+ ( scan, region. range ( ) , RawContext :: new ( region, client, cf) )
386
+ } )
387
+ . and_then ( |( mut scan, region_range, context) | {
388
+ let ( start_key, end_key) = scan. range ( ) ;
389
+ context
390
+ . client ( )
391
+ . raw_scan ( context, start_key, end_key, scan. limit , scan. key_only )
392
+ . map ( |pairs| ( scan, region_range, pairs) )
393
+ } )
394
+ . map ( |( mut scan, region_range, mut pairs) | {
395
+ let limit = scan. limit ;
396
+ scan. result_mut ( ) . append ( & mut pairs) ;
397
+ if scan. result ( ) . len ( ) as u32 >= limit {
398
+ Loop :: Break ( scan. into_inner ( ) )
399
+ } else {
400
+ match scan. next ( region_range) {
401
+ ScanRegionsStatus :: Continue => Loop :: Continue ( ( inner, scan) ) ,
402
+ ScanRegionsStatus :: Break => Loop :: Break ( scan. into_inner ( ) ) ,
415
403
}
416
- } )
417
- } )
404
+ }
405
+ } )
406
+ } )
418
407
} )
419
408
}
420
409
@@ -438,31 +427,27 @@ impl RpcClient {
438
427
let scan: ScanRegionsContext < ( ) , Option < ColumnFamily > > = ScanRegionsContext :: new ( range, cf) ;
439
428
let inner = Arc :: clone ( & self . inner ) ;
440
429
loop_fn ( ( inner, scan) , |( inner, scan) | {
441
- inner
442
- . locate_key ( scan. start_key ( ) )
443
- . and_then ( move |location| {
444
- let region = location. into_inner ( ) ;
445
- let cf = scan. clone ( ) ;
446
- Self :: region_context_by_id ( Arc :: clone ( & inner) , region. id )
447
- . map ( move |( region, client) | {
448
- ( scan, region. range ( ) , RawContext :: new ( region, client, cf) )
449
- } )
450
- . and_then ( move |( mut scan, region_range, context) | {
451
- let ( start_key, end_key) = scan. range ( ) ;
452
- let start_key = start_key. expect ( "start key must be specified" ) ;
453
- let end_key = end_key. expect ( "end key must be specified" ) ;
454
- context
455
- . client ( )
456
- . raw_delete_range ( context, start_key, end_key)
457
- . map ( move |_| ( scan, region_range) )
458
- } )
459
- . map (
460
- move |( mut scan, region_range) | match scan. next ( region_range) {
461
- ScanRegionsStatus :: Continue => Loop :: Continue ( ( inner, scan) ) ,
462
- ScanRegionsStatus :: Break => Loop :: Break ( ( ) ) ,
463
- } ,
464
- )
465
- } )
430
+ inner. locate_key ( scan. start_key ( ) ) . and_then ( |location| {
431
+ let region = location. into_inner ( ) ;
432
+ let cf = scan. clone ( ) ;
433
+ Self :: region_context_by_id ( Arc :: clone ( & inner) , region. id )
434
+ . map ( |( region, client) | {
435
+ ( scan, region. range ( ) , RawContext :: new ( region, client, cf) )
436
+ } )
437
+ . and_then ( |( mut scan, region_range, context) | {
438
+ let ( start_key, end_key) = scan. range ( ) ;
439
+ let start_key = start_key. expect ( "start key must be specified" ) ;
440
+ let end_key = end_key. expect ( "end key must be specified" ) ;
441
+ context
442
+ . client ( )
443
+ . raw_delete_range ( context, start_key, end_key)
444
+ . map ( |_| ( scan, region_range) )
445
+ } )
446
+ . map ( |( mut scan, region_range) | match scan. next ( region_range) {
447
+ ScanRegionsStatus :: Continue => Loop :: Continue ( ( inner, scan) ) ,
448
+ ScanRegionsStatus :: Break => Loop :: Break ( ( ) ) ,
449
+ } )
450
+ } )
466
451
} )
467
452
}
468
453
}
0 commit comments