Skip to content

Commit

Permalink
Combine workspace into a unicrate (#402)
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Lok <[email protected]>
  • Loading branch information
andylokandy authored Jul 10, 2023
1 parent bae5ee9 commit e49bc09
Show file tree
Hide file tree
Showing 93 changed files with 346 additions and 655 deletions.
26 changes: 9 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,20 @@ fail = "0.4"
futures = { version = "0.3" }
lazy_static = "1"
log = "0.4"
pin-project = "1"
prometheus = { version = "0.13", features = ["push"], default-features = false }
prost = "0.11"
rand = "0.8"
regex = "1"
semver = "1.0"
serde = "1.0"
serde_derive = "1.0"
slog = { version = "2.3", features = [
"max_level_trace",
"release_max_level_debug",
] }
slog-term = { version = "2.4" }
thiserror = "1"
tikv-client-common = { version = "0.2.0", path = "tikv-client-common" }
tikv-client-pd = { version = "0.2.0", path = "tikv-client-pd" }
tikv-client-proto = { version = "0.2.0", path = "tikv-client-proto" }
tikv-client-store = { version = "0.2.0", path = "tikv-client-store" }
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }
tonic = "0.9"
tonic = { version = "0.9", features = ["tls"] }

[dev-dependencies]
tempfile = "3.6"
clap = "2"
env_logger = "0.10"
fail = { version = "0.4", features = ["failpoints"] }
Expand All @@ -59,13 +53,11 @@ serial_test = "0.5.0"
simple_logger = "1"
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }

[workspace]
members = [
"tikv-client-common",
"tikv-client-pd",
"tikv-client-proto",
"tikv-client-store",
]
[build-dependencies]
glob = "0.3"
tonic-build = "0.9"
# Suppress doctest bug (https://stackoverflow.com/questions/66074003/how-to-turn-off-cargo-doc-test-and-compile-for-a-specific-module-in-rust)
tonic-disable-doctest = "0.1.0"

[[test]]
name = "failpoint_tests"
Expand Down
5 changes: 4 additions & 1 deletion tikv-client-proto/build.rs → build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.

use tonic_disable_doctest::BuilderEx;

fn main() {
tonic_build::configure()
.disable_doctests_for_types([".google.api.HttpRule"])
.build_server(false)
.include_file("mod.rs")
.compile(
&glob::glob("proto/*.proto")
.unwrap()
.collect::<Result<Vec<_>, _>>()
.unwrap(),
&["include", "proto"],
&["proto/include", "proto"],
)
.unwrap();
}
2 changes: 1 addition & 1 deletion examples/pessimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() {
};

// init
let client = Client::new_with_config(args.pd, config, None)
let client = Client::new_with_config(args.pd, config)
.await
.expect("Could not connect to tikv");

Expand Down
2 changes: 1 addition & 1 deletion examples/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<()> {

// When we first create a client we receive a `Connect` structure which must be resolved before
// the client is actually connected and usable.
let client = Client::new_with_config(args.pd, config, None).await?;
let client = Client::new_with_config(args.pd, config).await?;

// Requests are created from the connected client. These calls return structures which
// implement `Future`. This means the `Future` must be resolved before the action ever takes
Expand Down
2 changes: 1 addition & 1 deletion examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn main() {
Config::default()
};

let txn = Client::new_with_config(args.pd, config, None)
let txn = Client::new_with_config(args.pd, config)
.await
.expect("Could not connect to tikv");

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions tikv-client-common/src/errors.rs → src/common/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ pub enum Error {
Canceled(#[from] futures::channel::oneshot::Canceled),
/// Errors caused by changes of region information
#[error("Region error: {0:?}")]
RegionError(Box<tikv_client_proto::errorpb::Error>),
RegionError(Box<crate::proto::errorpb::Error>),
/// Whether the transaction is committed or not is undetermined
#[error("Whether the transaction is committed or not is undetermined")]
UndeterminedError(Box<Error>),
/// Wraps `tikv_client_proto::kvrpcpb::KeyError`
/// Wraps `crate::proto::kvrpcpb::KeyError`
#[error("{0:?}")]
KeyError(Box<tikv_client_proto::kvrpcpb::KeyError>),
KeyError(Box<crate::proto::kvrpcpb::KeyError>),
/// Multiple errors generated from the ExtractError plan.
#[error("Multiple errors: {0:?}")]
ExtractedErrors(Vec<Error>),
Expand Down Expand Up @@ -105,14 +105,14 @@ pub enum Error {
},
}

impl From<tikv_client_proto::errorpb::Error> for Error {
fn from(e: tikv_client_proto::errorpb::Error) -> Error {
impl From<crate::proto::errorpb::Error> for Error {
fn from(e: crate::proto::errorpb::Error) -> Error {
Error::RegionError(Box::new(e))
}
}

impl From<tikv_client_proto::kvrpcpb::KeyError> for Error {
fn from(e: tikv_client_proto::kvrpcpb::KeyError) -> Error {
impl From<crate::proto::kvrpcpb::KeyError> for Error {
fn from(e: crate::proto::kvrpcpb::KeyError) -> Error {
Error::KeyError(Box::new(e))
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2023 TiKV Project Authors. Licensed under Apache-2.0.

mod errors;
pub mod security;

pub use self::errors::Error;
pub use self::errors::Result;
7 changes: 4 additions & 3 deletions tikv-client-common/src/security.rs → src/common/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use std::path::Path;
use std::path::PathBuf;
use std::time::Duration;

// use grpcio::{Channel, ChannelBuilder, ChannelCredentialsBuilder, Environment};
use log::info;
use regex::Regex;
use tonic::transport::Certificate;
use tonic::transport::Channel;
use tonic::transport::ClientTlsConfig;
use tonic::transport::Identity;

use crate::internal_err;
use crate::Result;

lazy_static::lazy_static! {
Expand Down Expand Up @@ -116,7 +117,7 @@ mod tests {
let example_ca = temp.path().join("ca");
let example_cert = temp.path().join("cert");
let example_pem = temp.path().join("key");
for (id, f) in (&[&example_ca, &example_cert, &example_pem])
for (id, f) in [&example_ca, &example_cert, &example_pem]
.iter()
.enumerate()
{
Expand All @@ -125,7 +126,7 @@ mod tests {
let cert_path: PathBuf = format!("{}", example_cert.display()).into();
let key_path: PathBuf = format!("{}", example_pem.display()).into();
let ca_path: PathBuf = format!("{}", example_ca.display()).into();
let mgr = SecurityManager::load(&ca_path, &cert_path, &key_path).unwrap();
let mgr = SecurityManager::load(ca_path, cert_path, &key_path).unwrap();
assert_eq!(mgr.ca, vec![0]);
assert_eq!(mgr.cert, vec![1]);
let key = load_pem_file("private key", &key_path).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/kv/bound_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use std::ops::RangeToInclusive;

#[cfg(test)]
use proptest_derive::Arbitrary;
use tikv_client_proto::kvrpcpb;

use super::Key;
use crate::proto::kvrpcpb;

/// A struct for expressing ranges. This type is semi-opaque and is not really meant for users to
/// deal with directly. Most functions which operate on ranges will accept any types which
Expand Down
3 changes: 1 addition & 2 deletions src/kv/codec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::io::Write;
use std::ptr;

use tikv_client_common::internal_err;

use crate::internal_err;
use crate::Result;

const ENC_GROUP_SIZE: usize = 8;
Expand Down
2 changes: 1 addition & 1 deletion src/kv/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use proptest::arbitrary::any_with;
use proptest::collection::size_range;
#[cfg(test)]
use proptest_derive::Arbitrary;
use tikv_client_proto::kvrpcpb;

use super::HexRepr;
use crate::kv::codec::BytesEncoder;
use crate::kv::codec::{self};
use crate::proto::kvrpcpb;

const _PROPTEST_KEY_MAX: usize = 1024 * 2; // 2 KB

Expand Down
2 changes: 1 addition & 1 deletion src/kv/kvpair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use std::str;

#[cfg(test)]
use proptest_derive::Arbitrary;
use tikv_client_proto::kvrpcpb;

use super::HexRepr;
use super::Key;
use super::Value;
use crate::proto::kvrpcpb;

/// A key/value pair.
///
Expand Down
20 changes: 8 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
//! # use futures::prelude::*;
//! # fn main() -> Result<()> {
//! # futures::executor::block_on(async {
//! let client = RawClient::new(vec!["127.0.0.1:2379"], None).await?;
//! let client = RawClient::new(vec!["127.0.0.1:2379"]).await?;
//! client.put("key".to_owned(), "value".to_owned()).await?;
//! let value = client.get("key".to_owned()).await?;
//! # Ok(())
Expand All @@ -81,7 +81,7 @@
//! # use futures::prelude::*;
//! # fn main() -> Result<()> {
//! # futures::executor::block_on(async {
//! let txn_client = TransactionClient::new(vec!["127.0.0.1:2379"], None).await?;
//! let txn_client = TransactionClient::new(vec!["127.0.0.1:2379"]).await?;
//! let mut txn = txn_client.begin_optimistic().await?;
//! txn.put("key".to_owned(), "value".to_owned()).await?;
//! let value = txn.get("key".to_owned()).await?;
Expand All @@ -95,17 +95,17 @@
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::arc_with_non_send_sync)]

#[macro_use]
pub mod request;
#[macro_use]
#[doc(hidden)]
pub mod transaction;

mod backoff;
mod common;
mod compat;
mod config;
mod kv;
mod pd;
mod proto;
#[doc(hidden)]
pub mod raw;
mod region;
Expand All @@ -120,18 +120,14 @@ mod mock;
#[cfg(test)]
mod proptests;

#[macro_use]
extern crate slog;
extern crate slog_term;

#[doc(inline)]
pub use config::Config;
pub use common::security::SecurityManager;
#[doc(inline)]
pub use tikv_client_common::security::SecurityManager;
pub use common::Error;
#[doc(inline)]
pub use tikv_client_common::Error;
pub use common::Result;
#[doc(inline)]
pub use tikv_client_common::Result;
pub use config::Config;

#[doc(inline)]
pub use crate::backoff::Backoff;
Expand Down
21 changes: 5 additions & 16 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ use std::sync::Arc;

use async_trait::async_trait;
use derive_new::new;
use slog::Drain;
use slog::Logger;
use tikv_client_proto::metapb::RegionEpoch;
use tikv_client_proto::metapb::{self};
use tikv_client_store::KvClient;
use tikv_client_store::KvConnect;
use tikv_client_store::Request;

use crate::pd::PdClient;
use crate::pd::PdRpcClient;
use crate::pd::RetryClient;
use crate::proto::metapb::RegionEpoch;
use crate::proto::metapb::{self};
use crate::region::RegionId;
use crate::region::RegionWithLeader;
use crate::store::KvClient;
use crate::store::KvConnect;
use crate::store::RegionStore;
use crate::store::Request;
use crate::Config;
use crate::Error;
use crate::Key;
Expand All @@ -34,14 +32,6 @@ use crate::Timestamp;
/// client can be tested without doing any RPC calls.
pub async fn pd_rpc_client() -> PdRpcClient<MockKvConnect, MockCluster> {
let config = Config::default();
let plain = slog_term::PlainSyncDecorator::new(std::io::stdout());
let logger = Logger::root(
slog_term::FullFormat::new(plain)
.build()
.filter_level(slog::Level::Info)
.fuse(),
o!(),
);
PdRpcClient::new(
config.clone(),
|_| MockKvConnect,
Expand All @@ -53,7 +43,6 @@ pub async fn pd_rpc_client() -> PdRpcClient<MockKvConnect, MockCluster> {
))
},
false,
logger,
)
.await
.unwrap()
Expand Down
Loading

0 comments on commit e49bc09

Please sign in to comment.