Skip to content

Commit 4db9895

Browse files
committed
Revert "*: Support API v2 (part 1) (#415)"
This reverts commit 4b0e844.
1 parent bbaf317 commit 4db9895

File tree

15 files changed

+95
-306
lines changed

15 files changed

+95
-306
lines changed

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@
9494

9595
pub mod backoff;
9696
#[doc(hidden)]
97-
pub mod proto; // export `proto` to enable user customized codec
98-
#[doc(hidden)]
9997
pub mod raw;
10098
pub mod request;
10199
#[doc(hidden)]
@@ -106,6 +104,7 @@ mod compat;
106104
mod config;
107105
mod kv;
108106
mod pd;
107+
mod proto;
109108
mod region;
110109
mod region_cache;
111110
mod stats;
@@ -146,8 +145,6 @@ pub use crate::raw::Client as RawClient;
146145
#[doc(inline)]
147146
pub use crate::raw::ColumnFamily;
148147
#[doc(inline)]
149-
pub use crate::request::codec;
150-
#[doc(inline)]
151148
pub use crate::request::RetryOptions;
152149
#[doc(inline)]
153150
pub use crate::timestamp::Timestamp;

src/mock.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::proto::metapb::RegionEpoch;
1818
use crate::proto::metapb::{self};
1919
use crate::region::RegionId;
2020
use crate::region::RegionWithLeader;
21-
use crate::request::codec::ApiV1TxnCodec;
2221
use crate::store::KvConnect;
2322
use crate::store::RegionStore;
2423
use crate::store::Request;
@@ -31,7 +30,7 @@ use crate::Timestamp;
3130

3231
/// Create a `PdRpcClient` with it's internals replaced with mocks so that the
3332
/// client can be tested without doing any RPC calls.
34-
pub async fn pd_rpc_client() -> PdRpcClient<ApiV1TxnCodec, MockKvConnect, MockCluster> {
33+
pub async fn pd_rpc_client() -> PdRpcClient<MockKvConnect, MockCluster> {
3534
let config = Config::default();
3635
PdRpcClient::new(
3736
config.clone(),
@@ -44,7 +43,6 @@ pub async fn pd_rpc_client() -> PdRpcClient<ApiV1TxnCodec, MockKvConnect, MockCl
4443
))
4544
},
4645
false,
47-
Some(ApiV1TxnCodec::default()),
4846
)
4947
.await
5048
.unwrap()
@@ -73,18 +71,9 @@ pub struct MockKvConnect;
7371

7472
pub struct MockCluster;
7573

74+
#[derive(new)]
7675
pub struct MockPdClient {
7776
client: MockKvClient,
78-
codec: ApiV1TxnCodec,
79-
}
80-
81-
impl MockPdClient {
82-
pub fn new(client: MockKvClient) -> MockPdClient {
83-
MockPdClient {
84-
client,
85-
codec: ApiV1TxnCodec::default(),
86-
}
87-
}
8877
}
8978

9079
#[async_trait]
@@ -113,7 +102,6 @@ impl MockPdClient {
113102
pub fn default() -> MockPdClient {
114103
MockPdClient {
115104
client: MockKvClient::default(),
116-
codec: ApiV1TxnCodec::default(),
117105
}
118106
}
119107

@@ -177,7 +165,6 @@ impl MockPdClient {
177165

178166
#[async_trait]
179167
impl PdClient for MockPdClient {
180-
type Codec = ApiV1TxnCodec;
181168
type KvClient = MockKvClient;
182169

183170
async fn map_region_to_store(self: Arc<Self>, region: RegionWithLeader) -> Result<RegionStore> {
@@ -227,8 +214,4 @@ impl PdClient for MockPdClient {
227214
}
228215

229216
async fn invalidate_region_cache(&self, _ver_id: crate::region::RegionVerId) {}
230-
231-
fn get_codec(&self) -> &Self::Codec {
232-
&self.codec
233-
}
234217
}

src/pd/client.rs

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::region::RegionId;
2020
use crate::region::RegionVerId;
2121
use crate::region::RegionWithLeader;
2222
use crate::region_cache::RegionCache;
23-
use crate::request::codec::{ApiV1TxnCodec, Codec};
2423
use crate::store::KvConnect;
2524
use crate::store::RegionStore;
2625
use 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]
5352
pub 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

368339
fn make_key_range(start_key: Vec<u8>, end_key: Vec<u8>) -> kvrpcpb::KeyRange {

0 commit comments

Comments
 (0)