Skip to content

Commit 0a1de19

Browse files
authored
Migrate to tonic (#399)
* Fix publish issue Signed-off-by: Andy Lok <andylokandy@hotmail.com> * migrate to tonic Signed-off-by: Andy Lok <andylokandy@hotmail.com> * fix Signed-off-by: Andy Lok <andylokandy@hotmail.com> * fix Signed-off-by: Andy Lok <andylokandy@hotmail.com> * address comment Signed-off-by: Andy Lok <andylokandy@hotmail.com> --------- Signed-off-by: Andy Lok <andylokandy@hotmail.com>
1 parent 8875c96 commit 0a1de19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+660
-1723
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ jobs:
1010
check:
1111
name: check
1212
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
1613
steps:
1714
- uses: actions/checkout@v2
1815
- uses: actions-rs/toolchain@v1
@@ -28,19 +25,14 @@ jobs:
2825
repo-token: ${{ secrets.GITHUB_TOKEN }}
2926
- name: Rust Cache
3027
uses: Swatinem/rust-cache@v1.4.0
31-
with:
32-
key: ${{ matrix.env }}
3328
- name: make check
34-
run: ${{ matrix.env }} make check
29+
run: make check
3530

3631
unit-test:
3732
name: unit test
3833
env:
3934
CARGO_INCREMENTAL: 0
4035
runs-on: ubuntu-latest
41-
strategy:
42-
matrix:
43-
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
4436
steps:
4537
- uses: actions/checkout@v2
4638
- uses: actions-rs/toolchain@v1
@@ -55,19 +47,14 @@ jobs:
5547
repo-token: ${{ secrets.GITHUB_TOKEN }}
5648
- name: Rust Cache
5749
uses: Swatinem/rust-cache@v1.4.0
58-
with:
59-
key: ${{ matrix.env }}
6050
- name: unit test
61-
run: ${{ matrix.env }} make unit-test
51+
run: make unit-test
6252

6353
integration-test:
6454
name: integration test
6555
env:
6656
CARGO_INCREMENTAL: 0
6757
runs-on: ubuntu-latest
68-
strategy:
69-
matrix:
70-
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
7158
steps:
7259
- uses: actions/checkout@v2
7360
- uses: actions-rs/toolchain@v1
@@ -82,8 +69,6 @@ jobs:
8269
repo-token: ${{ secrets.GITHUB_TOKEN }}
8370
- name: Rust Cache
8471
uses: Swatinem/rust-cache@v1.4.0
85-
with:
86-
key: ${{ matrix.env }}
8772
- name: install tiup
8873
run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
8974
- name: start tiup playground
@@ -97,4 +82,4 @@ jobs:
9782
sleep 1
9883
done
9984
- name: integration test
100-
run: ${{ matrix.env }} MULTI_REGION=1 make integration-test
85+
run: MULTI_REGION=1 make integration-test

Cargo.toml

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,88 +6,68 @@ license = "Apache-2.0"
66
authors = ["The TiKV Project Authors"]
77
repository = "https://github.com/tikv/client-rust"
88
description = "The Rust language implementation of TiKV client."
9-
edition = "2018"
9+
edition = "2021"
1010

1111
[features]
12-
default = [ "prost-codec", "prometheus/process" ]
12+
default = ["prometheus/process"]
1313
# Enable integration tests with a running TiKV and PD instance.
1414
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
1515
integration-tests = []
16-
protobuf-codec = [
17-
"grpcio/protobuf-codec",
18-
"tikv-client-proto/protobuf-codec",
19-
"tikv-client-common/protobuf-codec",
20-
"tikv-client-pd/protobuf-codec",
21-
"tikv-client-store/protobuf-codec",
22-
"mock-tikv/protobuf-codec",
23-
]
24-
prost-codec = [
25-
"grpcio/prost-codec",
26-
"tikv-client-proto/prost-codec",
27-
"tikv-client-common/prost-codec",
28-
"tikv-client-pd/prost-codec",
29-
"tikv-client-store/prost-codec",
30-
"mock-tikv/prost-codec",
31-
]
3216

3317
[lib]
3418
name = "tikv_client"
3519

3620
[dependencies]
21+
async-recursion = "0.3"
3722
async-trait = "0.1"
3823
derive-new = "0.5"
3924
either = "1.6"
4025
fail = "0.4"
41-
futures = { version = "0.3", features = ["async-await", "thread-pool"] }
42-
futures-timer = "3.0"
43-
grpcio = { version = "0.10", features = [ "openssl-vendored" ], default-features = false }
26+
futures = { version = "0.3" }
4427
lazy_static = "1"
4528
log = "0.4"
46-
prometheus = { version = "0.13", features = [ "push" ], default-features = false }
29+
prometheus = { version = "0.13", features = ["push"], default-features = false }
4730
rand = "0.8"
4831
regex = "1"
4932
semver = "1.0"
5033
serde = "1.0"
5134
serde_derive = "1.0"
52-
slog = { version = "2.3", features = ["max_level_trace", "release_max_level_debug"] }
35+
slog = { version = "2.3", features = [
36+
"max_level_trace",
37+
"release_max_level_debug",
38+
] }
5339
slog-term = { version = "2.4" }
5440
thiserror = "1"
55-
tokio = { version = "1", features = [ "sync", "rt-multi-thread", "macros" ] }
56-
async-recursion = "0.3"
57-
5841
tikv-client-common = { version = "0.2.0", path = "tikv-client-common" }
5942
tikv-client-pd = { version = "0.2.0", path = "tikv-client-pd" }
6043
tikv-client-proto = { version = "0.2.0", path = "tikv-client-proto" }
6144
tikv-client-store = { version = "0.2.0", path = "tikv-client-store" }
62-
45+
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }
46+
tonic = "0.9"
6347

6448
[dev-dependencies]
6549
clap = "2"
66-
fail = { version = "0.4", features = [ "failpoints" ] }
67-
mock-tikv = {path = "mock-tikv"}
50+
env_logger = "0.10"
51+
fail = { version = "0.4", features = ["failpoints"] }
6852
proptest = "1"
6953
proptest-derive = "0.3"
54+
reqwest = { version = "0.11", default-features = false, features = [
55+
"native-tls-vendored",
56+
] }
57+
serde_json = "1"
7058
serial_test = "0.5.0"
7159
simple_logger = "1"
72-
tokio = { version = "1", features = [ "sync", "rt-multi-thread", "macros" ] }
73-
reqwest = {version = "0.11", default-features = false, features = ["native-tls-vendored"]}
74-
serde_json = "1"
60+
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }
7561

7662
[workspace]
7763
members = [
7864
"tikv-client-common",
7965
"tikv-client-pd",
8066
"tikv-client-proto",
8167
"tikv-client-store",
82-
"mock-tikv"
8368
]
8469

8570
[[test]]
8671
name = "failpoint_tests"
8772
path = "tests/failpoint_tests.rs"
8873
required-features = ["fail/failpoints"]
89-
90-
[patch.crates-io]
91-
raft-proto = { git = "https://github.com/tikv/raft-rs", rev="95c532612ee6a83591fce9a8b51d6afe87b58835"}
92-
protobuf-codegen = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }
93-
protobuf = { git = "https://github.com/pingcap/rust-protobuf", rev="82b49fea7e696fd647b5aca0a6c6ec944eab3189" }

Makefile

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,12 @@ export RUSTFLAGS=-Dwarnings
22

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

5-
ENABLE_FEATURES ?=
65
PD_ADDRS ?= "127.0.0.1:2379"
76
MULTI_REGION ?= 1
87

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

16-
ALL_FEATURES := ${ENABLE_FEATURES} integration-tests
17-
18-
INTEGRATION_TEST_ARGS := --no-default-features --features "${ENABLE_FEATURES} integration-tests"
10+
INTEGRATION_TEST_ARGS := --no-default-features --features "integration-tests"
1911

2012
default: check
2113

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

2719
unit-test:
28-
cargo test --all --no-default-features --features "${ENABLE_FEATURES}"
20+
cargo test --all --no-default-features
2921

3022
integration-test:
3123
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture

examples/pessimistic.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use tikv_client::{Config, Key, TransactionClient as Client, TransactionOptions,
77

88
#[tokio::main]
99
async fn main() {
10+
env_logger::init();
11+
1012
// You can try running this example by passing your pd endpoints
1113
// (and SSL options if necessary) through command line arguments.
1214
let args = parse_args("txn");
@@ -32,7 +34,7 @@ async fn main() {
3234
.begin_optimistic()
3335
.await
3436
.expect("Could not begin a transaction");
35-
for (key, value) in vec![(key1.clone(), value1), (key2, value2)] {
37+
for (key, value) in [(key1.clone(), value1), (key2, value2)] {
3638
txn0.put(key, value).await.expect("Could not set key value");
3739
}
3840
txn0.commit().await.expect("Could not commit");

examples/raw.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const VALUE: &str = "Rust";
1212

1313
#[tokio::main]
1414
async fn main() -> Result<()> {
15+
env_logger::init();
16+
1517
// You can try running this example by passing your pd endpoints
1618
// (and SSL options if necessary) through command line arguments.
1719
let args = parse_args("raw");
@@ -27,7 +29,6 @@ async fn main() -> Result<()> {
2729
// When we first create a client we receive a `Connect` structure which must be resolved before
2830
// the client is actually connected and usable.
2931
let client = Client::new_with_config(args.pd, config, None).await?;
30-
let client = client.clone();
3132

3233
// Requests are created from the connected client. These calls return structures which
3334
// implement `Future`. This means the `Future` must be resolved before the action ever takes

examples/transaction.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ async fn dels(client: &Client, keys: impl IntoIterator<Item = Key>) {
6969

7070
#[tokio::main]
7171
async fn main() {
72+
env_logger::init();
73+
7274
// You can try running this example by passing your pd endpoints
7375
// (and SSL options if necessary) through command line arguments.
7476
let args = parse_args("txn");

mock-tikv/Cargo.toml

Lines changed: 0 additions & 15 deletions
This file was deleted.

mock-tikv/src/lib.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)