Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to tonic #399

Merged
merged 5 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ jobs:
check:
name: check
runs-on: ubuntu-latest
strategy:
matrix:
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -28,19 +25,14 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
with:
key: ${{ matrix.env }}
- name: make check
run: ${{ matrix.env }} make check
run: make check

unit-test:
name: unit test
env:
CARGO_INCREMENTAL: 0
runs-on: ubuntu-latest
strategy:
matrix:
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -55,19 +47,14 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
with:
key: ${{ matrix.env }}
- name: unit test
run: ${{ matrix.env }} make unit-test
run: make unit-test

integration-test:
name: integration test
env:
CARGO_INCREMENTAL: 0
runs-on: ubuntu-latest
strategy:
matrix:
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -82,8 +69,6 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
with:
key: ${{ matrix.env }}
- name: install tiup
run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
- name: start tiup playground
Expand All @@ -97,4 +82,4 @@ jobs:
sleep 1
done
- name: integration test
run: ${{ matrix.env }} MULTI_REGION=1 make integration-test
run: MULTI_REGION=1 make integration-test
56 changes: 18 additions & 38 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,68 @@ license = "Apache-2.0"
authors = ["The TiKV Project Authors"]
repository = "https://github.com/tikv/client-rust"
description = "The Rust language implementation of TiKV client."
edition = "2018"
edition = "2021"

[features]
default = [ "prost-codec", "prometheus/process" ]
default = ["prometheus/process"]
# Enable integration tests with a running TiKV and PD instance.
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
integration-tests = []
protobuf-codec = [
"grpcio/protobuf-codec",
"tikv-client-proto/protobuf-codec",
"tikv-client-common/protobuf-codec",
"tikv-client-pd/protobuf-codec",
"tikv-client-store/protobuf-codec",
"mock-tikv/protobuf-codec",
]
prost-codec = [
"grpcio/prost-codec",
"tikv-client-proto/prost-codec",
"tikv-client-common/prost-codec",
"tikv-client-pd/prost-codec",
"tikv-client-store/prost-codec",
"mock-tikv/prost-codec",
]

[lib]
name = "tikv_client"

[dependencies]
async-recursion = "0.3"
async-trait = "0.1"
derive-new = "0.5"
either = "1.6"
fail = "0.4"
futures = { version = "0.3", features = ["async-await", "thread-pool"] }
futures-timer = "3.0"
grpcio = { version = "0.10", features = [ "openssl-vendored" ], default-features = false }
futures = { version = "0.3" }
lazy_static = "1"
log = "0.4"
prometheus = { version = "0.13", features = [ "push" ], default-features = false }
prometheus = { version = "0.13", features = ["push"], default-features = false }
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 = { version = "2.3", features = [
"max_level_trace",
"release_max_level_debug",
] }
slog-term = { version = "2.4" }
thiserror = "1"
tokio = { version = "1", features = [ "sync", "rt-multi-thread", "macros" ] }
async-recursion = "0.3"

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"

[dev-dependencies]
clap = "2"
fail = { version = "0.4", features = [ "failpoints" ] }
mock-tikv = {path = "mock-tikv"}
env_logger = "0.10"
fail = { version = "0.4", features = ["failpoints"] }
proptest = "1"
proptest-derive = "0.3"
reqwest = { version = "0.11", default-features = false, features = [
"native-tls-vendored",
] }
serde_json = "1"
serial_test = "0.5.0"
simple_logger = "1"
tokio = { version = "1", features = [ "sync", "rt-multi-thread", "macros" ] }
reqwest = {version = "0.11", default-features = false, features = ["native-tls-vendored"]}
serde_json = "1"
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }

[workspace]
members = [
"tikv-client-common",
"tikv-client-pd",
"tikv-client-proto",
"tikv-client-store",
"mock-tikv"
]

[[test]]
name = "failpoint_tests"
path = "tests/failpoint_tests.rs"
required-features = ["fail/failpoints"]

[patch.crates-io]
raft-proto = { git = "https://github.com/tikv/raft-rs", rev="95c532612ee6a83591fce9a8b51d6afe87b58835"}
protobuf-codegen = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }
protobuf = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }
14 changes: 3 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ export RUSTFLAGS=-Dwarnings

.PHONY: default check unit-test integration-tests test doc docker-pd docker-kv docker all

ENABLE_FEATURES ?=
PD_ADDRS ?= "127.0.0.1:2379"
MULTI_REGION ?= 1

# Use Rust-protobuf instead of Prost to encode and decode protocol buffers.
ifeq ($(RUST_PROTOBUF),1)
ENABLE_FEATURES += protobuf-codec
else
ENABLE_FEATURES += prost-codec
endif
ALL_FEATURES := integration-tests

ALL_FEATURES := ${ENABLE_FEATURES} integration-tests

INTEGRATION_TEST_ARGS := --no-default-features --features "${ENABLE_FEATURES} integration-tests"
INTEGRATION_TEST_ARGS := --no-default-features --features "integration-tests"

default: check

Expand All @@ -25,7 +17,7 @@ check:
cargo clippy --all-targets --no-default-features --features "${ALL_FEATURES}" -- -D clippy::all

unit-test:
cargo test --all --no-default-features --features "${ENABLE_FEATURES}"
cargo test --all --no-default-features

integration-test:
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
Expand Down
4 changes: 3 additions & 1 deletion examples/pessimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use tikv_client::{Config, Key, TransactionClient as Client, TransactionOptions,

#[tokio::main]
async fn main() {
env_logger::init();

// You can try running this example by passing your pd endpoints
// (and SSL options if necessary) through command line arguments.
let args = parse_args("txn");
Expand All @@ -32,7 +34,7 @@ async fn main() {
.begin_optimistic()
.await
.expect("Could not begin a transaction");
for (key, value) in vec![(key1.clone(), value1), (key2, value2)] {
for (key, value) in [(key1.clone(), value1), (key2, value2)] {
txn0.put(key, value).await.expect("Could not set key value");
}
txn0.commit().await.expect("Could not commit");
Expand Down
3 changes: 2 additions & 1 deletion examples/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const VALUE: &str = "Rust";

#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();

// You can try running this example by passing your pd endpoints
// (and SSL options if necessary) through command line arguments.
let args = parse_args("raw");
Expand All @@ -27,7 +29,6 @@ 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.clone();

// 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: 2 additions & 0 deletions examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async fn dels(client: &Client, keys: impl IntoIterator<Item = Key>) {

#[tokio::main]
async fn main() {
env_logger::init();

// You can try running this example by passing your pd endpoints
// (and SSL options if necessary) through command line arguments.
let args = parse_args("txn");
Expand Down
15 changes: 0 additions & 15 deletions mock-tikv/Cargo.toml

This file was deleted.

25 changes: 0 additions & 25 deletions mock-tikv/src/lib.rs

This file was deleted.

Loading