Skip to content

Commit fcda3d0

Browse files
author
ekexium
authored
impl Clone for Client (#349)
* impl Clone for Client Signed-off-by: ekexium <ekexium@gmail.com> * fix clippy Signed-off-by: ekexium <ekexium@gmail.com> * Empty-Commit Signed-off-by: ekexium <ekexium@fastmail.com> * cache in github jobs Signed-off-by: ekexium <ekexium@fastmail.com>
1 parent d75e727 commit fcda3d0

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
profile: minimal
1818
toolchain: nightly
1919
override: true
20+
- name: Rust Cache
21+
uses: Swatinem/rust-cache@v1.4.0
2022
- uses: actions-rs/cargo@v1
2123
with:
2224
command: check
@@ -47,6 +49,8 @@ jobs:
4749
toolchain: nightly
4850
components: clippy
4951
override: true
52+
- name: Rust Cache
53+
uses: Swatinem/rust-cache@v1.4.0
5054
- uses: actions-rs/clippy-check@v1
5155
with:
5256
token: ${{ secrets.GITHUB_TOKEN }}
@@ -64,18 +68,8 @@ jobs:
6468
profile: minimal
6569
toolchain: nightly
6670
override: true
67-
- run: cargo generate-lockfile
68-
- name: Cache dependencies
69-
uses: actions/cache@v2
70-
env:
71-
cache-name: cache-dependencies
72-
with:
73-
path: |
74-
~/.cargo/.crates.toml
75-
~/.cargo/.crates2.json
76-
~/.cargo/registry/index
77-
~/.cargo/registry/cache
78-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
71+
- name: Rust Cache
72+
uses: Swatinem/rust-cache@v1.4.0
7973
- name: unit test
8074
run: make unit-test
8175
integration-test:
@@ -90,18 +84,8 @@ jobs:
9084
profile: minimal
9185
toolchain: nightly
9286
override: true
93-
- run: cargo generate-lockfile
94-
- name: Cache dependencies
95-
uses: actions/cache@v2
96-
env:
97-
cache-name: cache-dependencies
98-
with:
99-
path: |
100-
~/.cargo/.crates.toml
101-
~/.cargo/.crates2.json
102-
~/.cargo/registry/index
103-
~/.cargo/registry/cache
104-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }}
87+
- name: Rust Cache
88+
uses: Swatinem/rust-cache@v1.4.0
10589
- name: install tiup
10690
run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
10791
- name: start tiup playground

examples/raw.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async fn main() -> Result<()> {
2727
// When we first create a client we receive a `Connect` structure which must be resolved before
2828
// the client is actually connected and usable.
2929
let client = Client::new_with_config(args.pd, config, None).await?;
30+
let client = client.clone();
3031

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

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{path::PathBuf, time::Duration};
88
///
99
/// See also [`TransactionOptions`](crate::TransactionOptions) which provides more ways to configure
1010
/// requests.
11-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
11+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
1212
#[serde(default)]
1313
#[serde(rename_all = "kebab-case")]
1414
pub struct Config {

src/raw/client.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240;
2525
///
2626
/// The returned results of raw request methods are [`Future`](std::future::Future)s that must be
2727
/// awaited to execute.
28-
#[derive(Clone)]
2928
pub struct Client<PdC: PdClient = PdRpcClient> {
3029
rpc: Arc<PdC>,
3130
cf: Option<ColumnFamily>,
@@ -34,6 +33,17 @@ pub struct Client<PdC: PdClient = PdRpcClient> {
3433
logger: Logger,
3534
}
3635

36+
impl Clone for Client {
37+
fn clone(&self) -> Self {
38+
Self {
39+
rpc: self.rpc.clone(),
40+
cf: self.cf.clone(),
41+
atomic: self.atomic,
42+
logger: self.logger.clone(),
43+
}
44+
}
45+
}
46+
3747
impl Client<PdRpcClient> {
3848
/// Create a raw [`Client`] and connect to the TiKV cluster.
3949
///

src/transaction/client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ pub struct Client {
3838
logger: Logger,
3939
}
4040

41+
impl Clone for Client {
42+
fn clone(&self) -> Self {
43+
Self {
44+
pd: self.pd.clone(),
45+
logger: self.logger.clone(),
46+
}
47+
}
48+
}
49+
4150
impl Client {
4251
/// Create a transactional [`Client`] and connect to the TiKV cluster.
4352
///

src/transaction/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ pub struct TransactionOptions {
953953
heartbeat_option: HeartbeatOption,
954954
}
955955

956-
#[derive(Clone, PartialEq, Debug)]
956+
#[derive(Clone, PartialEq, Eq, Debug)]
957957
pub enum HeartbeatOption {
958958
NoHeartbeat,
959959
FixedTime(Duration),
@@ -1308,7 +1308,7 @@ impl<PdC: PdClient> Committer<PdC> {
13081308
}
13091309
}
13101310

1311-
#[derive(PartialEq)]
1311+
#[derive(PartialEq, Eq)]
13121312
enum TransactionStatus {
13131313
/// The transaction is read-only [`Snapshot`](super::Snapshot), no need to commit or rollback or panic on drop.
13141314
ReadOnly,

0 commit comments

Comments
 (0)