Skip to content

Commit 9d9b680

Browse files
authored
*: Re-export protobuf types (LockInfo, Error, and KeyError) (#526)
Signed-off-by: Ping Yu <yuping@pingcap.com>
1 parent c2e2216 commit 9d9b680

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

src/common/errors.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ use crate::proto::kvrpcpb;
88
use crate::region::RegionVerId;
99
use crate::BoundRange;
1010

11+
/// Protobuf-generated region-level error returned by TiKV.
12+
///
13+
/// This type is generated from TiKV's protobuf definitions and may change in a
14+
/// future release even if the wire format is compatible.
15+
#[doc(inline)]
16+
pub use crate::proto::errorpb::Error as ProtoRegionError;
17+
18+
/// Protobuf-generated per-key error returned by TiKV.
19+
///
20+
/// This type is generated from TiKV's protobuf definitions and may change in a
21+
/// future release even if the wire format is compatible.
22+
#[doc(inline)]
23+
pub use crate::proto::kvrpcpb::KeyError as ProtoKeyError;
24+
1125
/// An error originating from the TiKV client or dependencies.
1226
#[derive(Debug, Error)]
1327
#[allow(clippy::large_enum_variant)]
@@ -63,13 +77,13 @@ pub enum Error {
6377
Canceled(#[from] futures::channel::oneshot::Canceled),
6478
/// Errors caused by changes of region information
6579
#[error("Region error: {0:?}")]
66-
RegionError(Box<crate::proto::errorpb::Error>),
80+
RegionError(Box<ProtoRegionError>),
6781
/// Whether the transaction is committed or not is undetermined
6882
#[error("Whether the transaction is committed or not is undetermined")]
6983
UndeterminedError(Box<Error>),
70-
/// Wraps `crate::proto::kvrpcpb::KeyError`
84+
/// Wraps a per-key error returned by TiKV.
7185
#[error("{0:?}")]
72-
KeyError(Box<crate::proto::kvrpcpb::KeyError>),
86+
KeyError(Box<ProtoKeyError>),
7387
/// Multiple errors generated from the ExtractError plan.
7488
#[error("Multiple errors: {0:?}")]
7589
ExtractedErrors(Vec<Error>),
@@ -116,14 +130,14 @@ pub enum Error {
116130
TxnNotFound(kvrpcpb::TxnNotFound),
117131
}
118132

119-
impl From<crate::proto::errorpb::Error> for Error {
120-
fn from(e: crate::proto::errorpb::Error) -> Error {
133+
impl From<ProtoRegionError> for Error {
134+
fn from(e: ProtoRegionError) -> Error {
121135
Error::RegionError(Box::new(e))
122136
}
123137
}
124138

125-
impl From<crate::proto::kvrpcpb::KeyError> for Error {
126-
fn from(e: crate::proto::kvrpcpb::KeyError) -> Error {
139+
impl From<ProtoKeyError> for Error {
140+
fn from(e: ProtoKeyError) -> Error {
127141
Error::KeyError(Box::new(e))
128142
}
129143
}

src/common/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ mod errors;
44
pub mod security;
55

66
pub use self::errors::Error;
7+
pub use self::errors::ProtoKeyError;
8+
pub use self::errors::ProtoRegionError;
79
pub use self::errors::Result;

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ pub use common::security::SecurityManager;
122122
#[doc(inline)]
123123
pub use common::Error;
124124
#[doc(inline)]
125+
pub use common::ProtoKeyError;
126+
#[doc(inline)]
127+
pub use common::ProtoRegionError;
128+
#[doc(inline)]
125129
pub use common::Result;
126130
#[doc(inline)]
127131
pub use config::Config;
@@ -157,6 +161,8 @@ pub use crate::transaction::CheckLevel;
157161
#[doc(inline)]
158162
pub use crate::transaction::Client as TransactionClient;
159163
#[doc(inline)]
164+
pub use crate::transaction::ProtoLockInfo;
165+
#[doc(inline)]
160166
pub use crate::transaction::Snapshot;
161167
#[doc(inline)]
162168
pub use crate::transaction::Transaction;

src/transaction/client.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::backoff::{DEFAULT_REGION_BACKOFF, DEFAULT_STORE_BACKOFF};
99
use crate::config::Config;
1010
use crate::pd::PdClient;
1111
use crate::pd::PdRpcClient;
12-
use crate::proto::kvrpcpb;
1312
use crate::proto::pdpb::Timestamp;
1413
use crate::request::plan::CleanupLocksResult;
1514
use crate::request::EncodeKeyspace;
@@ -29,6 +28,13 @@ use crate::Backoff;
2928
use crate::BoundRange;
3029
use crate::Result;
3130

31+
/// Protobuf-generated lock information returned by TiKV.
32+
///
33+
/// This type is generated from TiKV's protobuf definitions and may change in a
34+
/// future release even if the wire format is compatible.
35+
#[doc(inline)]
36+
pub use crate::proto::kvrpcpb::LockInfo as ProtoLockInfo;
37+
3238
// FIXME: cargo-culted value
3339
const SCAN_LOCK_BATCH_SIZE: u32 = 1024;
3440

@@ -302,7 +308,7 @@ impl Client {
302308
safepoint: &Timestamp,
303309
range: impl Into<BoundRange>,
304310
batch_size: u32,
305-
) -> Result<Vec<crate::proto::kvrpcpb::LockInfo>> {
311+
) -> Result<Vec<ProtoLockInfo>> {
306312
use crate::request::TruncateKeyspace;
307313

308314
let range = range.into().encode_keyspace(self.keyspace, KeyMode::Txn);
@@ -321,10 +327,10 @@ impl Client {
321327
/// timestamp when checking transaction status.
322328
pub async fn resolve_locks(
323329
&self,
324-
locks: Vec<kvrpcpb::LockInfo>,
330+
locks: Vec<ProtoLockInfo>,
325331
timestamp: Timestamp,
326332
mut backoff: Backoff,
327-
) -> Result<Vec<kvrpcpb::LockInfo>> {
333+
) -> Result<Vec<ProtoLockInfo>> {
328334
use crate::request::TruncateKeyspace;
329335

330336
let mut live_locks = locks;

src/transaction/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! **Warning:** It is not advisable to use both raw and transactional functionality in the same keyspace.
1010
1111
pub use client::Client;
12+
pub use client::ProtoLockInfo;
1213
pub(crate) use lock::resolve_locks;
1314
pub(crate) use lock::HasLocks;
1415
pub use snapshot::Snapshot;

0 commit comments

Comments
 (0)