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>
This commit is contained in:
ekexium 2022-06-15 19:05:44 +08:00 committed by GitHub
parent d75e727ced
commit fcda3d0954
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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<PdC: PdClient = PdRpcClient> {
rpc: Arc<PdC>,
cf: Option<ColumnFamily>,
@ -34,6 +33,17 @@ pub struct Client<PdC: PdClient = PdRpcClient> {
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<PdRpcClient> {
/// Create a raw [`Client`] and connect to the TiKV cluster.
///

View File

@ -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.
///

View File

@ -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<PdC: PdClient> Committer<PdC> {
}
}
#[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,