Skip to content

Commit 32060bb

Browse files
committed
Merge branch 'master' of https://github.com/tikv/client-rust into andylokandy/master
2 parents 2e81b06 + bbaf317 commit 32060bb

Some content is hidden

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

68 files changed

+14263
-431
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/generated/ diff=false

.github/workflows/ci.yml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ on:
33
push:
44
branches:
55
- master
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
8+
cancel-in-progress: true
9+
10+
env:
11+
CARGO_TERM_COLOR: always
612

713
name: CI
814

@@ -11,42 +17,36 @@ jobs:
1117
name: check
1218
runs-on: ubuntu-latest
1319
steps:
14-
- uses: actions/checkout@v2
15-
- uses: actions-rs/toolchain@v1
16-
with:
17-
profile: minimal
18-
toolchain: nightly
19-
override: true
20-
- run: rustup component add rustfmt clippy
20+
- uses: actions/checkout@v4
2121
- name: Install Protoc
2222
uses: arduino/setup-protoc@v1
2323
with:
2424
version: '3.x'
2525
repo-token: ${{ secrets.GITHUB_TOKEN }}
2626
- name: Rust Cache
27-
uses: Swatinem/rust-cache@v1.4.0
27+
uses: Swatinem/rust-cache@v2
2828
- name: make check
2929
run: make check
30+
- name: Catch unexpected changes in the generated code
31+
run: |
32+
git diff --exit-code
3033
3134
unit-test:
3235
name: unit test
3336
env:
3437
CARGO_INCREMENTAL: 0
3538
runs-on: ubuntu-latest
3639
steps:
37-
- uses: actions/checkout@v2
38-
- uses: actions-rs/toolchain@v1
39-
with:
40-
profile: minimal
41-
toolchain: nightly
42-
override: true
40+
- uses: actions/checkout@v4
4341
- name: Install Protoc
4442
uses: arduino/setup-protoc@v1
4543
with:
4644
version: '3.x'
4745
repo-token: ${{ secrets.GITHUB_TOKEN }}
4846
- name: Rust Cache
49-
uses: Swatinem/rust-cache@v1.4.0
47+
uses: Swatinem/rust-cache@v2
48+
- name: Install latest nextest release
49+
uses: taiki-e/install-action@nextest
5050
- name: unit test
5151
run: make unit-test
5252

@@ -56,19 +56,14 @@ jobs:
5656
CARGO_INCREMENTAL: 0
5757
runs-on: ubuntu-latest
5858
steps:
59-
- uses: actions/checkout@v2
60-
- uses: actions-rs/toolchain@v1
61-
with:
62-
profile: minimal
63-
toolchain: nightly
64-
override: true
59+
- uses: actions/checkout@v4
6560
- name: Install Protoc
6661
uses: arduino/setup-protoc@v1
6762
with:
6863
version: '3.x'
6964
repo-token: ${{ secrets.GITHUB_TOKEN }}
7065
- name: Rust Cache
71-
uses: Swatinem/rust-cache@v1.4.0
66+
uses: Swatinem/rust-cache@v2
7267
- name: install tiup
7368
run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
7469
- name: start tiup playground
@@ -81,5 +76,7 @@ jobs:
8176
[[ "$(curl -I http://127.0.0.1:2379/pd/api/v1/regions 2>/dev/null | head -n 1 | cut -d$' ' -f2)" -ne "405" ]] || break
8277
sleep 1
8378
done
79+
- name: Install latest nextest release
80+
uses: taiki-e/install-action@nextest
8481
- name: integration test
8582
run: MULTI_REGION=1 make integration-test

Cargo.toml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tikv-client"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
keywords = ["TiKV", "KV", "distributed-systems"]
55
license = "Apache-2.0"
66
authors = ["The TiKV Project Authors"]
@@ -9,14 +9,21 @@ description = "The Rust language implementation of TiKV client."
99
edition = "2021"
1010

1111
[features]
12-
default = ["prometheus/process"]
12+
default = ["prometheus"]
13+
prometheus = ["prometheus/push", "prometheus/process"]
1314
# Enable integration tests with a running TiKV and PD instance.
1415
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
1516
integration-tests = []
1617

1718
[lib]
1819
name = "tikv_client"
1920

21+
[workspace]
22+
members = [
23+
".",
24+
"proto-build",
25+
]
26+
2027
[dependencies]
2128
async-recursion = "0.3"
2229
async-trait = "0.1"
@@ -27,19 +34,18 @@ futures = { version = "0.3" }
2734
lazy_static = "1"
2835
log = "0.4"
2936
pin-project = "1"
30-
prometheus = { version = "0.13", features = ["push"], default-features = false }
31-
prost = "0.11"
37+
prometheus = { version = "0.13", default-features = false }
38+
prost = "0.12"
3239
rand = "0.8"
3340
regex = "1"
3441
semver = "1.0"
3542
serde = "1.0"
3643
serde_derive = "1.0"
3744
thiserror = "1"
3845
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }
39-
tonic = { version = "0.9", features = ["tls"] }
46+
tonic = { version = "0.10", features = ["tls"] }
4047

4148
[dev-dependencies]
42-
tempfile = "3.6"
4349
clap = "2"
4450
env_logger = "0.10"
4551
fail = { version = "0.4", features = ["failpoints"] }
@@ -51,14 +57,9 @@ reqwest = { version = "0.11", default-features = false, features = [
5157
serde_json = "1"
5258
serial_test = "0.5.0"
5359
simple_logger = "1"
60+
tempfile = "3.6"
5461
tokio = { version = "1", features = ["sync", "rt-multi-thread", "macros"] }
5562

56-
[build-dependencies]
57-
glob = "0.3"
58-
tonic-build = "0.9"
59-
# Suppress doctest bug (https://stackoverflow.com/questions/66074003/how-to-turn-off-cargo-doc-test-and-compile-for-a-specific-module-in-rust)
60-
tonic-disable-doctest = "0.1.0"
61-
6263
[[test]]
6364
name = "failpoint_tests"
6465
path = "tests/failpoint_tests.rs"

Makefile

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,40 @@ export RUSTFLAGS=-Dwarnings
22

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

5-
PD_ADDRS ?= "127.0.0.1:2379"
6-
MULTI_REGION ?= 1
5+
export PD_ADDRS ?= 127.0.0.1:2379
6+
export MULTI_REGION ?= 1
77

88
ALL_FEATURES := integration-tests
99

1010
INTEGRATION_TEST_ARGS := --features "integration-tests"
1111

1212
default: check
1313

14-
check:
14+
generate:
15+
cargo run -p tikv-client-proto-build
16+
17+
check: generate
1518
cargo check --all --all-targets --features "${ALL_FEATURES}"
1619
cargo fmt -- --check
1720
cargo clippy --all-targets --features "${ALL_FEATURES}" -- -D clippy::all
1821

19-
unit-test:
20-
cargo test --all --no-default-features
22+
unit-test: generate
23+
cargo nextest run --all --no-default-features
2124

22-
integration-test:
25+
integration-test: generate
2326
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
2427
cargo test raw_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
2528
cargo test misc_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
2629

2730
test: unit-test integration-test
2831

29-
doc:
32+
doc:
3033
cargo doc --workspace --exclude tikv-client-proto --document-private-items --no-deps
3134

32-
# Deprecated
33-
# docker-pd:
34-
# docker run -d -v $(shell pwd)/config:/config --net=host --name pd --rm pingcap/pd:latest --name "pd" --data-dir "pd" --client-urls "http://127.0.0.1:2379" --advertise-client-urls "http://127.0.0.1:2379" --config /config/pd.toml
35-
36-
# docker-kv:
37-
# docker run -d -v $(shell pwd)/config:/config --net=host --name kv --rm --ulimit nofile=90000:90000 pingcap/tikv:latest --pd-endpoints "127.0.0.1:2379" --addr "127.0.0.1:2378" --data-dir "kv" --config /config/tikv.toml
38-
39-
# docker: docker-pd docker-kv
40-
4135
tiup:
4236
tiup playground nightly --mode tikv-slim --kv 3 --without-monitor --kv.config $(shell pwd)/config/tikv.toml --pd.config $(shell pwd)/config/pd.toml &
4337

44-
all: check doc test
38+
all: generate check doc test
4539

4640
clean:
4741
cargo clean

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The TiKV client is a Rust library (crate). To use this crate in your project, ad
1717

1818
```toml
1919
[dependencies]
20-
tikv-client = "0.2.0"
20+
tikv-client = "0.3"
2121
```
2222

2323
### Prerequisites
@@ -113,7 +113,11 @@ We welcome your contributions! Contributing code is great, we also appreciate fi
113113

114114
## Building and testing
115115

116-
We use the standard Cargo workflows, e.g., `cargo build` to build and `cargo test` to run unit tests. You will need to use a nightly Rust toolchain to build and run tests.
116+
We use the standard Cargo workflows, e.g., `cargo build` to build and `cargo test/nextest` to run unit tests. You will need to use a nightly Rust toolchain to build and run tests. Could use [nextest](https://nexte.st/index.html) to speed up ut, install nextest first.
117+
118+
```
119+
cargo install cargo-nextest --locked
120+
```
117121

118122
Running integration tests or manually testing the client with a TiKV cluster is a little bit more involved. The easiest way is to use [TiUp](https://github.com/pingcap/tiup) (>= 1.5) to initialise a cluster on your local machine:
119123

@@ -131,7 +135,7 @@ PD_ADDRS="127.0.0.1:2379" cargo test --package tikv-client --test integration_te
131135

132136
We use a standard GitHub PR workflow. We run CI on every PR and require all PRs to build without warnings (including clippy and Rustfmt warnings), pass tests, have a DCO sign-off (use `-s` when you commit, the DCO bot will guide you through completing the DCO agreement for your first PR), and have at least one review. If any of this is difficult for you, don't worry about it and ask on the PR.
133137

134-
To run CI-like tests locally, we recommend you run `cargo clippy`, `cargo test`, and `cargo fmt` before submitting your PR. See above for running integration tests, but you probably won't need to worry about this for your first few PRs.
138+
To run CI-like tests locally, we recommend you run `cargo clippy`, `cargo test/nextest run`, and `cargo fmt` before submitting your PR. See above for running integration tests, but you probably won't need to worry about this for your first few PRs.
135139

136140
Please follow PingCAP's [Rust style guide](https://pingcap.github.io/style-guide/rust/). All code PRs should include new tests or test cases.
137141

examples/raw.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ async fn main() -> Result<()> {
100100
.expect("Could not scan");
101101

102102
let keys: Vec<_> = pairs.into_iter().map(|p| p.key().clone()).collect();
103-
assert_eq!(&keys, &[
104-
Key::from("k1".to_owned()),
105-
Key::from("k2".to_owned()),
106-
]);
103+
assert_eq!(
104+
&keys,
105+
&[Key::from("k1".to_owned()), Key::from("k2".to_owned()),]
106+
);
107107
println!("Scanning from {start:?} to {end:?} gives: {keys:?}");
108108

109109
let k1 = "k1";
@@ -122,15 +122,18 @@ async fn main() -> Result<()> {
122122
.into_iter()
123123
.map(|p| String::from_utf8(p.1).unwrap())
124124
.collect();
125-
assert_eq!(&vals, &[
126-
"v1".to_owned(),
127-
"v2".to_owned(),
128-
"v2".to_owned(),
129-
"v3".to_owned(),
130-
"v1".to_owned(),
131-
"v2".to_owned(),
132-
"v3".to_owned()
133-
]);
125+
assert_eq!(
126+
&vals,
127+
&[
128+
"v1".to_owned(),
129+
"v2".to_owned(),
130+
"v2".to_owned(),
131+
"v3".to_owned(),
132+
"v1".to_owned(),
133+
"v2".to_owned(),
134+
"v3".to_owned()
135+
]
136+
);
134137
println!("Scanning batch scan from {batch_scan_keys:?} gives: {vals:?}");
135138

136139
// Cleanly exit.

examples/transaction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ async fn main() {
110110
let key1_exists = key_exists(&txn, key1.clone()).await;
111111
let key2: Key = b"key_not_exist".to_vec().into();
112112
let key2_exists = key_exists(&txn, key2.clone()).await;
113-
println!("check exists {:?}", vec![
114-
(key1, key1_exists),
115-
(key2, key2_exists)
116-
]);
113+
println!(
114+
"check exists {:?}",
115+
vec![(key1, key1_exists), (key2, key2_exists)]
116+
);
117117

118118
// scan
119119
let key1: Key = b"key1".to_vec().into();

proto-build/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "tikv-client-proto-build"
3+
version = "0.0.0"
4+
publish = false
5+
6+
keywords = ["TiKV", "KV", "distributed-systems"]
7+
license = "Apache-2.0"
8+
authors = ["The TiKV Project Authors"]
9+
repository = "https://github.com/tikv/client-rust"
10+
description = "The Rust language implementation of TiKV client."
11+
edition = "2021"
12+
13+
[dependencies]
14+
glob = "0.3"
15+
tonic-build = { version = "0.10", features = ["cleanup-markdown"] }

build.rs renamed to proto-build/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0.
2-
3-
use tonic_disable_doctest::BuilderEx;
1+
// Copyright 2023 TiKV Project Authors. Licensed under Apache-2.0.
42

53
fn main() {
64
tonic_build::configure()
7-
.disable_doctests_for_types([".google.api.HttpRule"])
5+
.emit_rerun_if_changed(false)
86
.build_server(false)
97
.include_file("mod.rs")
8+
.out_dir("src/generated")
109
.compile(
1110
&glob::glob("proto/*.proto")
1211
.unwrap()

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = ["rustfmt", "clippy"]

0 commit comments

Comments
 (0)