@@ -5,23 +5,25 @@ use std::{any::Any, borrow::Cow, ops::Range, sync::Arc};
5
5
use async_trait:: async_trait;
6
6
use futures:: stream:: BoxStream ;
7
7
use grpcio:: CallOption ;
8
+
8
9
use tikv_client_proto:: { kvrpcpb, metapb, tikvpb:: TikvClient } ;
9
10
use tikv_client_store:: Request ;
10
11
11
- use super :: RawRpcRequest ;
12
12
use crate :: {
13
13
collect_first,
14
+ ColumnFamily ,
15
+ Key ,
16
+ KvPair ,
14
17
pd:: PdClient ,
15
18
request:: {
16
- codec:: RequestCodec , plan :: ResponseWithShard , Collect , CollectSingle , DefaultProcessor ,
17
- KvRequest , Merge , Process , Shardable , SingleKey ,
19
+ codec:: RequestCodec , Collect , CollectSingle , DefaultProcessor , KvRequest ,
20
+ Merge , plan :: ResponseWithShard , Process , Shardable , SingleKey ,
18
21
} ,
19
- store:: { store_stream_for_keys, store_stream_for_ranges, RegionStore } ,
20
- transaction:: HasLocks ,
21
- util:: iter:: FlatMapOkIterExt ,
22
- ColumnFamily , Key , KvPair , Result , Value ,
22
+ Result , store:: { RegionStore , store_stream_for_keys, store_stream_for_ranges} , transaction:: HasLocks , util:: iter:: FlatMapOkIterExt , Value ,
23
23
} ;
24
24
25
+ use super :: RawRpcRequest ;
26
+
25
27
pub fn new_raw_get_request ( key : Vec < u8 > , cf : Option < ColumnFamily > ) -> kvrpcpb:: RawGetRequest {
26
28
let mut req = kvrpcpb:: RawGetRequest :: default ( ) ;
27
29
req. set_key ( key) ;
@@ -30,7 +32,7 @@ pub fn new_raw_get_request(key: Vec<u8>, cf: Option<ColumnFamily>) -> kvrpcpb::R
30
32
req
31
33
}
32
34
33
- kv_request_with_key ! ( kvrpcpb:: RawGetRequest , kvrpcpb:: RawGetResponse ) ;
35
+ impl_kv_request_for_single_key_op ! ( kvrpcpb:: RawGetRequest , kvrpcpb:: RawGetResponse ) ;
34
36
shardable_key ! ( kvrpcpb:: RawGetRequest ) ;
35
37
collect_first ! ( kvrpcpb:: RawGetResponse ) ;
36
38
@@ -64,7 +66,8 @@ pub fn new_raw_batch_get_request(
64
66
req
65
67
}
66
68
67
- kv_request_with_key ! ( kvrpcpb:: RawBatchGetRequest , kvrpcpb:: RawBatchGetResponse ) ;
69
+ impl_kv_request_for_batch_get ! ( kvrpcpb:: RawBatchGetRequest , kvrpcpb:: RawBatchGetResponse ) ;
70
+
68
71
shardable_keys ! ( kvrpcpb:: RawBatchGetRequest ) ;
69
72
70
73
impl Merge < kvrpcpb:: RawBatchGetResponse > for Collect {
@@ -93,7 +96,7 @@ pub fn new_raw_put_request(
93
96
req
94
97
}
95
98
96
- kv_request_with_key ! ( kvrpcpb:: RawPutRequest , kvrpcpb:: RawPutResponse ) ;
99
+ impl_kv_request_for_single_key_op ! ( kvrpcpb:: RawPutRequest , kvrpcpb:: RawPutResponse ) ;
97
100
shardable_key ! ( kvrpcpb:: RawPutRequest ) ;
98
101
collect_first ! ( kvrpcpb:: RawPutResponse ) ;
99
102
@@ -120,13 +123,15 @@ impl<C: RequestCodec> KvRequest<C> for kvrpcpb::RawBatchPutRequest {
120
123
type Response = kvrpcpb:: RawBatchPutResponse ;
121
124
122
125
fn encode_request ( & self , codec : & C ) -> Cow < Self > {
123
- plain_request ! ( self , codec) ;
124
- todo ! ( )
125
- }
126
+ if codec. is_plain ( ) {
127
+ return Cow :: Borrowed ( self ) ;
128
+ }
129
+
130
+ let mut req = self . clone ( ) ;
131
+
132
+ * req. mut_pairs ( ) = codec. encode_pairs ( req. take_pairs ( ) ) ;
126
133
127
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
128
- plain_response ! ( resp, codec) ;
129
- todo ! ( )
134
+ Cow :: Owned ( req)
130
135
}
131
136
}
132
137
@@ -165,20 +170,7 @@ pub fn new_raw_delete_request(
165
170
req
166
171
}
167
172
168
- impl < C : RequestCodec > KvRequest < C > for kvrpcpb:: RawDeleteRequest {
169
- type Response = kvrpcpb:: RawDeleteResponse ;
170
-
171
- fn encode_request ( & self , codec : & C ) -> Cow < Self > {
172
- plain_request ! ( self , codec) ;
173
- todo ! ( )
174
- }
175
-
176
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
177
- plain_response ! ( resp, codec) ;
178
- todo ! ( )
179
- }
180
- }
181
-
173
+ impl_kv_request_for_single_key_op ! ( kvrpcpb:: RawDeleteRequest , kvrpcpb:: RawDeleteResponse ) ;
182
174
shardable_key ! ( kvrpcpb:: RawDeleteRequest ) ;
183
175
collect_first ! ( kvrpcpb:: RawDeleteResponse ) ;
184
176
impl SingleKey for kvrpcpb:: RawDeleteRequest {
@@ -202,13 +194,15 @@ impl<C: RequestCodec> KvRequest<C> for kvrpcpb::RawBatchDeleteRequest {
202
194
type Response = kvrpcpb:: RawBatchDeleteResponse ;
203
195
204
196
fn encode_request ( & self , codec : & C ) -> Cow < Self > {
205
- plain_request ! ( self , codec) ;
206
- todo ! ( )
207
- }
197
+ if codec. is_plain ( ) {
198
+ return Cow :: Borrowed ( self ) ;
199
+ }
200
+
201
+ let mut req = self . clone ( ) ;
208
202
209
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
210
- plain_response ! ( resp , codec ) ;
211
- todo ! ( )
203
+ * req . mut_keys ( ) = codec . encode_keys ( req . take_keys ( ) ) ;
204
+
205
+ Cow :: Owned ( req )
212
206
}
213
207
}
214
208
@@ -231,13 +225,17 @@ impl<C: RequestCodec> KvRequest<C> for kvrpcpb::RawDeleteRangeRequest {
231
225
type Response = kvrpcpb:: RawDeleteRangeResponse ;
232
226
233
227
fn encode_request ( & self , codec : & C ) -> Cow < Self > {
234
- plain_request ! ( self , codec) ;
235
- todo ! ( )
236
- }
228
+ if codec. is_plain ( ) {
229
+ return Cow :: Borrowed ( self ) ;
230
+ }
231
+
232
+ let mut req = self . clone ( ) ;
237
233
238
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
239
- plain_response ! ( resp, codec) ;
240
- todo ! ( )
234
+ let ( start, end) = ( req. take_start_key ( ) , req. take_end_key ( ) ) ;
235
+ * req. mut_start_key ( ) = codec. encode_key ( start) ;
236
+ * req. mut_end_key ( ) = codec. encode_key ( end) ;
237
+
238
+ Cow :: Owned ( req)
241
239
}
242
240
}
243
241
@@ -260,20 +258,7 @@ pub fn new_raw_scan_request(
260
258
req
261
259
}
262
260
263
- impl < C : RequestCodec > KvRequest < C > for kvrpcpb:: RawScanRequest {
264
- type Response = kvrpcpb:: RawScanResponse ;
265
-
266
- fn encode_request ( & self , codec : & C ) -> Cow < Self > {
267
- plain_request ! ( self , codec) ;
268
- todo ! ( )
269
- }
270
-
271
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
272
- plain_response ! ( resp, codec) ;
273
- todo ! ( )
274
- }
275
- }
276
-
261
+ impl_kv_request_for_scan_op ! ( kvrpcpb:: RawScanRequest , kvrpcpb:: RawScanResponse , kvs) ;
277
262
shardable_range ! ( kvrpcpb:: RawScanRequest ) ;
278
263
279
264
impl Merge < kvrpcpb:: RawScanResponse > for Collect {
@@ -306,13 +291,15 @@ impl<C: RequestCodec> KvRequest<C> for kvrpcpb::RawBatchScanRequest {
306
291
type Response = kvrpcpb:: RawBatchScanResponse ;
307
292
308
293
fn encode_request ( & self , codec : & C ) -> Cow < Self > {
309
- plain_request ! ( self , codec) ;
310
- todo ! ( )
311
- }
294
+ if codec. is_plain ( ) {
295
+ return Cow :: Borrowed ( self ) ;
296
+ }
312
297
313
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
314
- plain_response ! ( resp, codec) ;
315
- todo ! ( )
298
+ let mut req = self . clone ( ) ;
299
+
300
+ * req. mut_ranges ( ) = codec. encode_ranges ( req. take_ranges ( ) ) ;
301
+
302
+ Cow :: Owned ( req)
316
303
}
317
304
}
318
305
@@ -361,20 +348,7 @@ pub fn new_cas_request(
361
348
req
362
349
}
363
350
364
- impl < C : RequestCodec > KvRequest < C > for kvrpcpb:: RawCasRequest {
365
- type Response = kvrpcpb:: RawCasResponse ;
366
-
367
- fn encode_request ( & self , codec : & C ) -> Cow < Self > {
368
- plain_request ! ( self , codec) ;
369
- todo ! ( )
370
- }
371
-
372
- fn decode_response ( & self , codec : & C , resp : Self :: Response ) -> Result < Self :: Response > {
373
- plain_response ! ( resp, codec) ;
374
- todo ! ( )
375
- }
376
- }
377
-
351
+ impl_kv_request_for_single_key_op ! ( kvrpcpb:: RawCasRequest , kvrpcpb:: RawCasResponse ) ;
378
352
shardable_key ! ( kvrpcpb:: RawCasRequest ) ;
379
353
collect_first ! ( kvrpcpb:: RawCasResponse ) ;
380
354
impl SingleKey for kvrpcpb:: RawCasRequest {
@@ -397,7 +371,7 @@ impl Process<kvrpcpb::RawCasResponse> for DefaultProcessor {
397
371
}
398
372
399
373
type RawCoprocessorRequestDataBuilder =
400
- Arc < dyn Fn ( metapb:: Region , Vec < kvrpcpb:: KeyRange > ) -> Vec < u8 > + Send + Sync > ;
374
+ Arc < dyn Fn ( metapb:: Region , Vec < kvrpcpb:: KeyRange > ) -> Vec < u8 > + Send + Sync > ;
401
375
402
376
pub fn new_raw_coprocessor_request (
403
377
copr_name : String ,
@@ -467,8 +441,8 @@ impl Shardable for RawCoprocessorRequest {
467
441
468
442
#[ allow( clippy:: type_complexity) ]
469
443
impl
470
- Process < Vec < Result < ResponseWithShard < kvrpcpb:: RawCoprocessorResponse , Vec < kvrpcpb:: KeyRange > > > > >
471
- for DefaultProcessor
444
+ Process < Vec < Result < ResponseWithShard < kvrpcpb:: RawCoprocessorResponse , Vec < kvrpcpb:: KeyRange > > > > >
445
+ for DefaultProcessor
472
446
{
473
447
type Out = Vec < ( Vec < u8 > , Vec < Range < Key > > ) > ;
474
448
@@ -517,29 +491,43 @@ impl_raw_rpc_request!(RawDeleteRangeRequest);
517
491
impl_raw_rpc_request ! ( RawCasRequest ) ;
518
492
519
493
impl HasLocks for kvrpcpb:: RawGetResponse { }
494
+
520
495
impl HasLocks for kvrpcpb:: RawBatchGetResponse { }
496
+
521
497
impl HasLocks for kvrpcpb:: RawPutResponse { }
498
+
522
499
impl HasLocks for kvrpcpb:: RawBatchPutResponse { }
500
+
523
501
impl HasLocks for kvrpcpb:: RawDeleteResponse { }
502
+
524
503
impl HasLocks for kvrpcpb:: RawBatchDeleteResponse { }
504
+
525
505
impl HasLocks for kvrpcpb:: RawScanResponse { }
506
+
526
507
impl HasLocks for kvrpcpb:: RawBatchScanResponse { }
508
+
527
509
impl HasLocks for kvrpcpb:: RawDeleteRangeResponse { }
510
+
528
511
impl HasLocks for kvrpcpb:: RawCasResponse { }
512
+
529
513
impl HasLocks for kvrpcpb:: RawCoprocessorResponse { }
530
514
531
515
#[ cfg( test) ]
532
516
mod test {
533
- use super :: * ;
517
+ use std:: any:: Any ;
518
+
519
+ use futures:: executor;
520
+
521
+ use tikv_client_proto:: kvrpcpb;
522
+
534
523
use crate :: {
535
524
backoff:: { DEFAULT_REGION_BACKOFF , OPTIMISTIC_BACKOFF } ,
525
+ Key ,
536
526
mock:: { MockKvClient , MockPdClient } ,
537
527
request:: Plan ,
538
- Key ,
539
528
} ;
540
- use futures:: executor;
541
- use std:: any:: Any ;
542
- use tikv_client_proto:: kvrpcpb;
529
+
530
+ use super :: * ;
543
531
544
532
#[ test]
545
533
#[ ignore]
0 commit comments