@@ -20,7 +20,6 @@ use crate::region::RegionId;
2020use crate :: region:: RegionVerId ;
2121use crate :: region:: RegionWithLeader ;
2222use crate :: region_cache:: RegionCache ;
23- use crate :: request:: codec:: { ApiV1TxnCodec , Codec } ;
2423use crate :: store:: KvConnect ;
2524use crate :: store:: RegionStore ;
2625use crate :: store:: TikvConnect ;
@@ -51,7 +50,6 @@ use crate::Timestamp;
5150/// So if we use transactional APIs, keys in PD are encoded and PD does not know about the encoding stuff.
5251#[ async_trait]
5352pub trait PdClient : Send + Sync + ' static {
54- type Codec : Codec ;
5553 type KvClient : KvClient + Send + Sync + ' static ;
5654
5755 /// In transactional API, `region` is decoded (keys in raw format).
@@ -193,11 +191,8 @@ pub trait PdClient: Send + Sync + 'static {
193191 . boxed ( )
194192 }
195193
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 {
201196 codec:: decode_bytes_in_place ( & mut region. region . start_key , false ) ?;
202197 codec:: decode_bytes_in_place ( & mut region. region . end_key , false ) ?;
203198 }
@@ -207,30 +202,20 @@ pub trait PdClient: Send + Sync + 'static {
207202 async fn update_leader ( & self , ver_id : RegionVerId , leader : metapb:: Peer ) -> Result < ( ) > ;
208203
209204 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 ;
214205}
215206
216207/// This client converts requests for the logical TiKV cluster into requests
217208/// 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 > {
223210 pd : Arc < RetryClient < Cl > > ,
224211 kv_connect : KvC ,
225212 kv_client_cache : Arc < RwLock < HashMap < String , KvC :: KvClient > > > ,
226- enable_mvcc_codec : bool ,
213+ enable_codec : bool ,
227214 region_cache : RegionCache < RetryClient < Cl > > ,
228- codec : Option < Cod > ,
229215}
230216
231217#[ 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 > {
234219 type KvClient = KvC :: KvClient ;
235220
236221 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
241226 }
242227
243228 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 {
246231 key. to_encoded ( )
247232 } else {
248233 key. clone ( )
249234 } ;
250235
251236 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 )
253238 }
254239
255240 async fn region_for_id ( & self , id : RegionId ) -> Result < RegionWithLeader > {
256241 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 )
258243 }
259244
260245 async fn all_stores ( & self ) -> Result < Vec < Store > > {
@@ -282,40 +267,31 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static> PdClient for PdRpcClien
282267 async fn invalidate_region_cache ( & self , ver_id : RegionVerId ) {
283268 self . region_cache . invalidate_region_cache ( ver_id) . await
284269 }
285-
286- fn get_codec ( & self ) -> & Self :: Codec {
287- self . codec
288- . as_ref ( )
289- . unwrap_or_else ( || panic ! ( "codec not set" ) )
290- }
291270}
292271
293- impl < Cod : Codec > PdRpcClient < Cod , TikvConnect , Cluster > {
272+ impl PdRpcClient < TikvConnect , Cluster > {
294273 pub async fn connect (
295274 pd_endpoints : & [ String ] ,
296275 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 > {
300278 PdRpcClient :: new (
301279 config. clone ( ) ,
302280 |security_mgr| TikvConnect :: new ( security_mgr, config. timeout ) ,
303281 |security_mgr| RetryClient :: connect ( pd_endpoints, security_mgr, config. timeout ) ,
304- enable_mvcc_codec,
305- codec,
282+ enable_codec,
306283 )
307284 . await
308285 }
309286}
310287
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 > {
312289 pub async fn new < PdFut , MakeKvC , MakePd > (
313290 config : Config ,
314291 kv_connect : MakeKvC ,
315292 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 > >
319295 where
320296 PdFut : Future < Output = Result < RetryClient < Cl > > > ,
321297 MakeKvC : FnOnce ( Arc < SecurityManager > ) -> KvC ,
@@ -337,9 +313,8 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static, Cl> PdRpcClient<Cod, Kv
337313 pd : pd. clone ( ) ,
338314 kv_client_cache,
339315 kv_connect : kv_connect ( security_mgr) ,
340- enable_mvcc_codec ,
316+ enable_codec ,
341317 region_cache : RegionCache :: new ( pd) ,
342- codec,
343318 } )
344319 }
345320
@@ -359,10 +334,6 @@ impl<Cod: Codec, KvC: KvConnect + Send + Sync + 'static, Cl> PdRpcClient<Cod, Kv
359334 Err ( e) => Err ( e) ,
360335 }
361336 }
362-
363- pub fn set_codec ( & mut self , codec : Cod ) {
364- self . codec = Some ( codec) ;
365- }
366337}
367338
368339fn make_key_range ( start_key : Vec < u8 > , end_key : Vec < u8 > ) -> kvrpcpb:: KeyRange {
0 commit comments