From d75e727ced51704350a4faad6f679292258f7bae Mon Sep 17 00:00:00 2001 From: iosmanthus Date: Wed, 15 Jun 2022 18:36:31 +0800 Subject: [PATCH 1/2] prepare tikv cluster properly (#352) * prepare tikv cluster properly Signed-off-by: iosmanthus * fix ilgal config for tikv Signed-off-by: iosmanthus * add some debug info Signed-off-by: iosmanthus * add some debug info Signed-off-by: iosmanthus * add some debug info Signed-off-by: iosmanthus * remove debug info Signed-off-by: iosmanthus * use relative path in ci.yaml Signed-off-by: iosmanthus * add logs for start tiup playground Signed-off-by: iosmanthus * change to do while Signed-off-by: iosmanthus * empty commit Signed-off-by: ekexium Co-authored-by: ekexium --- .github/workflows/ci.yml | 9 ++++++++- config/tikv.toml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95819a6..ef91217 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,6 +105,13 @@ jobs: - name: install tiup run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh - name: start tiup playground - run: /home/runner/.tiup/bin/tiup playground nightly --mode tikv-slim --kv 3 --without-monitor --kv.config /home/runner/work/client-rust/client-rust/config/tikv.toml --pd.config /home/runner/work/client-rust/client-rust/config/pd.toml & + run: | + ~/.tiup/bin/tiup install tikv:nightly pd:nightly + ~/.tiup/bin/tiup playground nightly --mode tikv-slim --kv 3 --without-monitor --kv.config config/tikv.toml --pd.config config/pd.toml & + while :; do + echo "waiting cluster to be ready" + [[ "$(curl -I http://127.0.0.1:2379/pd/api/v1/regions 2>/dev/null | head -n 1 | cut -d$' ' -f2)" -ne "405" ]] || break + sleep 1 + done - name: integration test run: MULTI_REGION=1 make integration-test diff --git a/config/tikv.toml b/config/tikv.toml index 90bb217..0337dd7 100644 --- a/config/tikv.toml +++ b/config/tikv.toml @@ -4,7 +4,7 @@ region-split-keys = 7 batch-split-limit = 100 [raftstore] -region-split-check-diff = "0KB" +region-split-check-diff = "1B" pd-heartbeat-tick-interval = "2s" pd-store-heartbeat-tick-interval = "5s" split-region-check-tick-interval = "1s" From fcda3d0954faa26be00ffbcd8600de326622f6d4 Mon Sep 17 00:00:00 2001 From: ekexium Date: Wed, 15 Jun 2022 19:05:44 +0800 Subject: [PATCH 2/2] impl Clone for Client (#349) * impl Clone for Client Signed-off-by: ekexium * fix clippy Signed-off-by: ekexium * Empty-Commit Signed-off-by: ekexium * cache in github jobs Signed-off-by: ekexium --- .github/workflows/ci.yml | 32 ++++++++------------------------ examples/raw.rs | 1 + src/config.rs | 2 +- src/raw/client.rs | 12 +++++++++++- src/transaction/client.rs | 9 +++++++++ src/transaction/transaction.rs | 4 ++-- 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef91217..82d62fb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,8 @@ jobs: profile: minimal toolchain: nightly override: true + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - uses: actions-rs/cargo@v1 with: command: check @@ -47,6 +49,8 @@ jobs: toolchain: nightly components: clippy override: true + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} @@ -64,18 +68,8 @@ jobs: profile: minimal toolchain: nightly override: true - - run: cargo generate-lockfile - - name: Cache dependencies - uses: actions/cache@v2 - env: - cache-name: cache-dependencies - with: - path: | - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/.cargo/registry/index - ~/.cargo/registry/cache - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - name: unit test run: make unit-test integration-test: @@ -90,18 +84,8 @@ jobs: profile: minimal toolchain: nightly override: true - - run: cargo generate-lockfile - - name: Cache dependencies - uses: actions/cache@v2 - env: - cache-name: cache-dependencies - with: - path: | - ~/.cargo/.crates.toml - ~/.cargo/.crates2.json - ~/.cargo/registry/index - ~/.cargo/registry/cache - key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} + - name: Rust Cache + uses: Swatinem/rust-cache@v1.4.0 - name: install tiup run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh - name: start tiup playground diff --git a/examples/raw.rs b/examples/raw.rs index aefd731..de583d8 100644 --- a/examples/raw.rs +++ b/examples/raw.rs @@ -27,6 +27,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.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 diff --git a/src/config.rs b/src/config.rs index 8f5e28e..a0ee3ab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,7 +8,7 @@ use std::{path::PathBuf, time::Duration}; /// /// See also [`TransactionOptions`](crate::TransactionOptions) which provides more ways to configure /// requests. -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(default)] #[serde(rename_all = "kebab-case")] pub struct Config { diff --git a/src/raw/client.rs b/src/raw/client.rs index 3252e40..6f140ad 100644 --- a/src/raw/client.rs +++ b/src/raw/client.rs @@ -25,7 +25,6 @@ const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240; /// /// The returned results of raw request methods are [`Future`](std::future::Future)s that must be /// awaited to execute. -#[derive(Clone)] pub struct Client { rpc: Arc, cf: Option, @@ -34,6 +33,17 @@ pub struct Client { logger: Logger, } +impl Clone for Client { + fn clone(&self) -> Self { + Self { + rpc: self.rpc.clone(), + cf: self.cf.clone(), + atomic: self.atomic, + logger: self.logger.clone(), + } + } +} + impl Client { /// Create a raw [`Client`] and connect to the TiKV cluster. /// diff --git a/src/transaction/client.rs b/src/transaction/client.rs index fee8e25..69f11bc 100644 --- a/src/transaction/client.rs +++ b/src/transaction/client.rs @@ -38,6 +38,15 @@ pub struct Client { logger: Logger, } +impl Clone for Client { + fn clone(&self) -> Self { + Self { + pd: self.pd.clone(), + logger: self.logger.clone(), + } + } +} + impl Client { /// Create a transactional [`Client`] and connect to the TiKV cluster. /// diff --git a/src/transaction/transaction.rs b/src/transaction/transaction.rs index f067f66..0f4197d 100644 --- a/src/transaction/transaction.rs +++ b/src/transaction/transaction.rs @@ -953,7 +953,7 @@ pub struct TransactionOptions { heartbeat_option: HeartbeatOption, } -#[derive(Clone, PartialEq, Debug)] +#[derive(Clone, PartialEq, Eq, Debug)] pub enum HeartbeatOption { NoHeartbeat, FixedTime(Duration), @@ -1308,7 +1308,7 @@ impl Committer { } } -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] enum TransactionStatus { /// The transaction is read-only [`Snapshot`](super::Snapshot), no need to commit or rollback or panic on drop. ReadOnly,