Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy committed Jul 7, 2023
1 parent bf4d988 commit 401a146
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 47 deletions.
21 changes: 3 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ jobs:
check:
name: check
runs-on: ubuntu-latest
strategy:
matrix:
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -28,19 +25,14 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
with:
key: ${{ matrix.env }}
- name: make check
run: ${{ matrix.env }} make check
run: make check

unit-test:
name: unit test
env:
CARGO_INCREMENTAL: 0
runs-on: ubuntu-latest
strategy:
matrix:
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -55,19 +47,14 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
with:
key: ${{ matrix.env }}
- name: unit test
run: ${{ matrix.env }} make unit-test
run: make unit-test

integration-test:
name: integration test
env:
CARGO_INCREMENTAL: 0
runs-on: ubuntu-latest
strategy:
matrix:
env: [ 'RUST_PROTOBUF=0', 'RUST_PROTOBUF=1' ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -82,8 +69,6 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rust Cache
uses: Swatinem/rust-cache@v1.4.0
with:
key: ${{ matrix.env }}
- name: install tiup
run: curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
- name: start tiup playground
Expand All @@ -97,4 +82,4 @@ jobs:
sleep 1
done
- name: integration test
run: ${{ matrix.env }} MULTI_REGION=1 make integration-test
run: MULTI_REGION=1 make integration-test
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ reqwest = { version = "0.11", default-features = false, features = [
"native-tls-vendored",
] }
serde_json = "1"
env_logger = "0.10"

[workspace]
members = [
Expand Down
14 changes: 3 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@ export RUSTFLAGS=-Dwarnings

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

ENABLE_FEATURES ?=
PD_ADDRS ?= "127.0.0.1:2379"
MULTI_REGION ?= 1

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

ALL_FEATURES := ${ENABLE_FEATURES} integration-tests

INTEGRATION_TEST_ARGS := --no-default-features --features "${ENABLE_FEATURES} integration-tests"
INTEGRATION_TEST_ARGS := --no-default-features --features "integration-tests"

default: check

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

unit-test:
cargo test --all --no-default-features --features "${ENABLE_FEATURES}"
cargo test --all --no-default-features

integration-test:
cargo test txn_ --all ${INTEGRATION_TEST_ARGS} -- --nocapture
Expand Down
2 changes: 2 additions & 0 deletions examples/pessimistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use tikv_client::{Config, Key, TransactionClient as Client, TransactionOptions,

#[tokio::main]
async fn main() {
env_logger::init();

// You can try running this example by passing your pd endpoints
// (and SSL options if necessary) through command line arguments.
let args = parse_args("txn");
Expand Down
3 changes: 2 additions & 1 deletion examples/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const VALUE: &str = "Rust";

#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();

// You can try running this example by passing your pd endpoints
// (and SSL options if necessary) through command line arguments.
let args = parse_args("raw");
Expand All @@ -27,7 +29,6 @@ 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
Expand Down
2 changes: 2 additions & 0 deletions examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ async fn dels(client: &Client, keys: impl IntoIterator<Item = Key>) {

#[tokio::main]
async fn main() {
env_logger::init();

// You can try running this example by passing your pd endpoints
// (and SSL options if necessary) through command line arguments.
let args = parse_args("txn");
Expand Down
4 changes: 2 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

mod ctl;

use futures_timer::Delay;
use log::{info, warn};
use rand::Rng;
use slog::Drain;
use std::{collections::HashSet, convert::TryInto, env, time::Duration};
use tikv_client::{ColumnFamily, Key, RawClient, Result, Transaction, TransactionClient};
use tokio::time::sleep;

const ENV_PD_ADDRS: &str = "PD_ADDRS";
const ENV_ENABLE_MULIT_REGION: &str = "MULTI_REGION";
Expand Down Expand Up @@ -88,7 +88,7 @@ async fn ensure_region_split(
warn!("Stop splitting regions: time limit exceeded");
break;
}
Delay::new(Duration::from_millis(200)).await;
sleep(Duration::from_millis(200)).await;
}

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions tests/failpoint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ async fn count_locks(client: &TransactionClient) -> Result<usize> {
let ts = client.current_timestamp().await.unwrap();
let locks = client.scan_locks(&ts, vec![].., 1024).await?;
// De-duplicated as `scan_locks` will return duplicated locks due to retry on region changes.
let locks_set: HashSet<Vec<u8>> =
HashSet::from_iter(locks.into_iter().map(|mut l| l.take_key()));
let locks_set: HashSet<Vec<u8>> = HashSet::from_iter(locks.into_iter().map(|l| l.key));
Ok(locks_set.len())
}

Expand Down
22 changes: 10 additions & 12 deletions tikv-client-common/src/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,25 @@ impl SecurityManager {
where
Factory: FnOnce(Channel) -> Client,
{
let addr = "http://".to_string() + &SCHEME_REG.replace(addr, "");

info!("connect to rpc server at endpoint: {:?}", addr);

let addr = SCHEME_REG.replace(addr, "").into_owned();
let mut builder = Channel::from_shared(addr)?
.tcp_keepalive(Some(Duration::from_secs(10)))
.keep_alive_timeout(Duration::from_secs(3));

let tls = if self.ca.is_empty() {
ClientTlsConfig::default()
} else {
ClientTlsConfig::new()
if !self.ca.is_empty() {
let tls = ClientTlsConfig::new()
.ca_certificate(Certificate::from_pem(&self.ca))
.identity(Identity::from_pem(
&self.cert,
load_pem_file("private key", &self.key)?,
))
));
builder = builder.tls_config(tls)?;
};

let ch = Channel::from_shared(addr)?
.tcp_keepalive(Some(Duration::from_secs(10)))
.keep_alive_timeout(Duration::from_secs(3))
.tls_config(tls)?
.connect()
.await?;
let ch = builder.connect().await?;

Ok(factory(ch))
}
Expand Down
3 changes: 3 additions & 0 deletions tikv-client-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ futures = "0.3"
lazy_static = { version = "1" }
tonic = "0.9"
prost = "0.11"

[lib]
doctest = false
2 changes: 1 addition & 1 deletion tikv-client-store/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ macro_rules! impl_request {
.clone()
.$fun(req)
.await
.map(|r| Box::new(r) as Box<dyn Any>)
.map(|r| Box::new(r.into_inner()) as Box<dyn Any>)
.map_err(Error::GrpcAPI)
}

Expand Down

0 comments on commit 401a146

Please sign in to comment.