@@ -20,7 +20,6 @@ use crate::region::RegionId;
20
20
use crate :: region:: RegionVerId ;
21
21
use crate :: region:: RegionWithLeader ;
22
22
use crate :: region_cache:: RegionCache ;
23
- use crate :: request:: codec:: { ApiV1TxnCodec , Codec } ;
24
23
use crate :: store:: KvConnect ;
25
24
use crate :: store:: RegionStore ;
26
25
use crate :: store:: TikvConnect ;
@@ -51,7 +50,6 @@ use crate::Timestamp;
51
50
/// So if we use transactional APIs, keys in PD are encoded and PD does not know about the encoding stuff.
52
51
#[ async_trait]
53
52
pub trait PdClient : Send + Sync + ' static {
54
- type Codec : Codec ;
55
53
type KvClient : KvClient + Send + Sync + ' static ;
56
54
57
55
/// In transactional API, `region` is decoded (keys in raw format).
@@ -193,11 +191,8 @@ pub trait PdClient: Send + Sync + 'static {
193
191
. boxed ( )
194
192
}
195
193
196
- fn decode_region (
197
- mut region : RegionWithLeader ,
198
- enable_mvcc_codec : bool ,
199
- ) -> Result < RegionWithLeader > {
200
- if enable_mvcc_codec {
194
+ fn decode_region ( mut region : RegionWithLeader , enable_codec : bool ) -> Result < RegionWithLeader > {
195
+ if enable_codec {
201
196
codec:: decode_bytes_in_place ( & mut region. region . start_key , false ) ?;
202
197
codec:: decode_bytes_in_place ( & mut region. region . end_key , false ) ?;
203
198
}
@@ -207,30 +202,20 @@ pub trait PdClient: Send + Sync + 'static {
207
202
async fn update_leader ( & self , ver_id : RegionVerId , leader : metapb:: Peer ) -> Result < ( ) > ;
208
203
209
204
async fn invalidate_region_cache ( & self , ver_id : RegionVerId ) ;
210
-
211
- /// Get the codec carried by `PdClient`.
212
- /// The purpose of carrying the codec is to avoid passing it on so many calling paths.
213
- fn get_codec ( & self ) -> & Self :: Codec ;
214
205
}
215
206
216
207
/// This client converts requests for the logical TiKV cluster into requests
217
208
/// for a single TiKV store using PD and internal logic.
218
- pub struct PdRpcClient <
219
- Cod : Codec = ApiV1TxnCodec ,
220
- KvC : KvConnect + Send + Sync + ' static = TikvConnect ,
221
- Cl = Cluster ,
222
- > {
209
+ pub struct PdRpcClient < KvC : KvConnect + Send + Sync + ' static = TikvConnect , Cl = Cluster > {
223
210
pd : Arc < RetryClient < Cl > > ,
224
211
kv_connect : KvC ,
225
212
kv_client_cache : Arc < RwLock < HashMap < String , KvC :: KvClient > > > ,
226
- enable_mvcc_codec : bool ,
213
+ enable_codec : bool ,
227
214
region_cache : RegionCache < RetryClient < Cl > > ,
228
- codec : Option < Cod > ,
229
215
}
230
216
231
217
#[ async_trait]
232
- impl < Cod : Codec , KvC : KvConnect + Send + Sync + ' static > PdClient for PdRpcClient < Cod , KvC > {
233
- type Codec = Cod ;
218
+ impl < KvC : KvConnect + Send + Sync + ' static > PdClient for PdRpcClient < KvC > {
234
219
type KvClient = KvC :: KvClient ;
235
220
236
221
async fn map_region_to_store ( self : Arc < Self > , region : RegionWithLeader ) -> Result < RegionStore > {
@@ -241,20 +226,20 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static> PdClient for PdRpcClien
241
226
}
242
227
243
228
async fn region_for_key ( & self , key : & Key ) -> Result < RegionWithLeader > {
244
- let enable_mvcc_codec = self . enable_mvcc_codec ;
245
- let key = if enable_mvcc_codec {
229
+ let enable_codec = self . enable_codec ;
230
+ let key = if enable_codec {
246
231
key. to_encoded ( )
247
232
} else {
248
233
key. clone ( )
249
234
} ;
250
235
251
236
let region = self . region_cache . get_region_by_key ( & key) . await ?;
252
- Self :: decode_region ( region, enable_mvcc_codec )
237
+ Self :: decode_region ( region, enable_codec )
253
238
}
254
239
255
240
async fn region_for_id ( & self , id : RegionId ) -> Result < RegionWithLeader > {
256
241
let region = self . region_cache . get_region_by_id ( id) . await ?;
257
- Self :: decode_region ( region, self . enable_mvcc_codec )
242
+ Self :: decode_region ( region, self . enable_codec )
258
243
}
259
244
260
245
async fn all_stores ( & self ) -> Result < Vec < Store > > {
@@ -282,40 +267,31 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static> PdClient for PdRpcClien
282
267
async fn invalidate_region_cache ( & self , ver_id : RegionVerId ) {
283
268
self . region_cache . invalidate_region_cache ( ver_id) . await
284
269
}
285
-
286
- fn get_codec ( & self ) -> & Self :: Codec {
287
- self . codec
288
- . as_ref ( )
289
- . unwrap_or_else ( || panic ! ( "codec not set" ) )
290
- }
291
270
}
292
271
293
- impl < Cod : Codec > PdRpcClient < Cod , TikvConnect , Cluster > {
272
+ impl PdRpcClient < TikvConnect , Cluster > {
294
273
pub async fn connect (
295
274
pd_endpoints : & [ String ] ,
296
275
config : Config ,
297
- enable_mvcc_codec : bool , // TODO: infer from `codec`.
298
- codec : Option < Cod > ,
299
- ) -> Result < PdRpcClient < Cod > > {
276
+ enable_codec : bool ,
277
+ ) -> Result < PdRpcClient > {
300
278
PdRpcClient :: new (
301
279
config. clone ( ) ,
302
280
|security_mgr| TikvConnect :: new ( security_mgr, config. timeout ) ,
303
281
|security_mgr| RetryClient :: connect ( pd_endpoints, security_mgr, config. timeout ) ,
304
- enable_mvcc_codec,
305
- codec,
282
+ enable_codec,
306
283
)
307
284
. await
308
285
}
309
286
}
310
287
311
- impl < Cod : Codec , KvC : KvConnect + Send + Sync + ' static , Cl > PdRpcClient < Cod , KvC , Cl > {
288
+ impl < KvC : KvConnect + Send + Sync + ' static , Cl > PdRpcClient < KvC , Cl > {
312
289
pub async fn new < PdFut , MakeKvC , MakePd > (
313
290
config : Config ,
314
291
kv_connect : MakeKvC ,
315
292
pd : MakePd ,
316
- enable_mvcc_codec : bool ,
317
- codec : Option < Cod > ,
318
- ) -> Result < PdRpcClient < Cod , KvC , Cl > >
293
+ enable_codec : bool ,
294
+ ) -> Result < PdRpcClient < KvC , Cl > >
319
295
where
320
296
PdFut : Future < Output = Result < RetryClient < Cl > > > ,
321
297
MakeKvC : FnOnce ( Arc < SecurityManager > ) -> KvC ,
@@ -337,9 +313,8 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static, Cl> PdRpcClient<Cod, Kv
337
313
pd : pd. clone ( ) ,
338
314
kv_client_cache,
339
315
kv_connect : kv_connect ( security_mgr) ,
340
- enable_mvcc_codec ,
316
+ enable_codec ,
341
317
region_cache : RegionCache :: new ( pd) ,
342
- codec,
343
318
} )
344
319
}
345
320
@@ -359,10 +334,6 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static, Cl> PdRpcClient<Cod, Kv
359
334
Err ( e) => Err ( e) ,
360
335
}
361
336
}
362
-
363
- pub fn set_codec ( & mut self , codec : Cod ) {
364
- self . codec = Some ( codec) ;
365
- }
366
337
}
367
338
368
339
fn make_key_range ( start_key : Vec < u8 > , end_key : Vec < u8 > ) -> kvrpcpb:: KeyRange {
0 commit comments