Skip to content

Commit acfa500

Browse files
authored
Merge branch 'master' into master
2 parents 35459b6 + d932a20 commit acfa500

File tree

16 files changed

+180
-147
lines changed

16 files changed

+180
-147
lines changed

.travis.yml

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
1-
branches:
2-
only:
3-
# This is where pull requests from "bors r+" are built.
4-
- staging
5-
# This is where pull requests from "bors try" are built.
6-
- trying
7-
# Enable building pull requests.
8-
- master
1+
sudo: false
92

103
language: rust
11-
sudo: false
4+
os:
5+
- linux
6+
# - windows # TODO: https://github.com/pingcap/kvproto/issues/355
7+
- osx
8+
rust:
9+
- stable
10+
- nightly
1211
env:
1312
global:
1413
- RUST_BACKTRACE=1
1514
- RUSTFLAGS="-D warnings"
16-
cache: cargo
17-
18-
rust:
19-
os:
20-
- linux
21-
- windows
22-
- osx
2315

24-
matrix:
25-
include:
26-
# This build uses stable and checks rustfmt and clippy.
27-
# We don't check them on nightly since their lints and formatting may differ.
28-
- rust: stable
29-
install:
30-
- rustup component add rustfmt-preview
31-
- rustup component add clippy-preview
32-
before_script:
33-
- cargo fmt --all -- --check
34-
- cargo clippy --all -- -D clippy
35-
# Since many users will use nightlies, also test that.
36-
- rust: nightly
16+
addons:
17+
apt:
18+
update: true
19+
sources:
20+
- sourceline: 'ppa:maarten-fonville/protobuf'
21+
packages:
22+
- protobuf-compiler
23+
homebrew:
24+
packages:
25+
- protobuf
26+
- cmake
27+
- go
3728

29+
install:
30+
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then rustup component add rustfmt; fi
31+
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then rustup component add clippy; fi
32+
- if [[ $TRAVIS_OS_NAME == "windows" ]]; then choco install golang cmake strawberryperl protoc; fi
33+
- if [[ $TRAVIS_OS_NAME == "windows" ]]; then export PATH="$PATH:/c/Go/bin/:/c/Program Files/CMake/bin"; fi
3834

3935
script:
40-
- docker run -d --net=host --name pd --rm pingcap/pd --name "pd" --data-dir "pd" --client-urls "http://127.0.0.1:2379" --advertise-client-urls "http://127.0.0.1:2379"
41-
- docker run -d --net=host --name kv --rm pingcap/tikv --pd-endpoints "127.0.0.1:2379" --addr "127.0.0.1:2378" --data-dir "kv"
36+
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then cargo fmt -- --check; fi
37+
- if [[ $TRAVIS_RUST_VERSION == "stable" && $TRAVIS_OS_NAME == "linux" ]]; then cargo clippy -- -D clippy::all; fi
4238
- cargo test --all -- --nocapture
43-
# Validate benches still work.
44-
- cargo bench --all -- --test
39+
# For now we only run full integration tests on Linux. Here's why:
40+
# * Docker on OS X is not supported by Travis.
41+
# * Docker on Windows seems to not have the correct binary at `"/c/Program Files/Docker/Docker/DockerCli.exe" to switch it to Linux containers.
42+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then docker run -d --net=host --name pd --rm pingcap/pd --name "pd" --data-dir "pd" --client-urls "http://127.0.0.1:2379" --advertise-client-urls "http://127.0.0.1:2379"; fi
43+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then docker run -d --net=host --name kv --rm --ulimit nofile=90000:90000 pingcap/tikv --pd-endpoints "127.0.0.1:2379" --addr "127.0.0.1:2378" --data-dir "kv"; fi
44+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then docker ps; fi
45+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then docker logs pd; fi
46+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then docker logs kv; fi
47+
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then PD_ADDR="127.0.0.1:2379" cargo test --all --features integration-tests -- --nocapture; fi

Cargo.toml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,37 @@ repository = "https://github.com/tikv/client-rust"
88
description = "The rust language implementation of TiKV client."
99
edition = "2018"
1010

11+
[features]
12+
default = []
13+
# Enable integration tests with a running TiKV and PD instance.
14+
# Use $PD_ADDRS, comma separated, to set the addresses the tests use.
15+
integration-tests = []
16+
1117
[lib]
1218
name = "tikv_client"
1319

1420
[dependencies]
21+
failure = "0.1"
1522
futures = "0.1"
16-
serde = "1.0"
17-
serde_derive = "1.0"
23+
fxhash = "0.2"
1824
grpcio = { version = "0.4", features = [ "secure" ] }
25+
lazy_static = "0.2.1"
26+
log = "0.3.9"
1927
protobuf = "~2.0"
28+
serde = "1.0"
29+
serde_derive = "1.0"
2030
tokio-core = "0.1"
2131
tokio-timer = "0.2"
22-
fxhash = "0.2"
23-
lazy_static = "0.2.1"
24-
log = "0.3.9"
25-
failure = "0.1"
2632

2733
[dependencies.kvproto]
2834
git = "https://github.com/pingcap/kvproto.git"
35+
branch = "raft-0.5.0"
2936

3037
[dependencies.prometheus]
3138
version = "0.4.2"
3239
default-features = false
3340
features = ["push", "process"]
3441

3542
[dev-dependencies]
36-
tempdir = "0.3"
3743
clap = "2.32"
44+
tempdir = "0.3"

appveyor.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/raw.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ fn main() -> Result<()> {
3333
Config::new(args.pd)
3434
};
3535

36-
// When we first create a client we recieve a `Connect` structure which must be resolved before
36+
// When we first create a client we receive a `Connect` structure which must be resolved before
3737
// the client is actually connected and usable.
38-
let unconnnected_client = Client::new(&config);
38+
let unconnnected_client = Client::new(config);
3939
let client = unconnnected_client.wait()?;
4040

4141
// Requests are created from the connected client. These calls return structures which
@@ -45,9 +45,8 @@ fn main() -> Result<()> {
4545
// Here we set the key `TiKV` to have the value `Rust` associated with it.
4646
let put_request = client.put(KEY, VALUE);
4747
put_request.wait()?; // Returns a `tikv_client::Error` on failure.
48-
println!("Put key \"{}\", value \"{}\".", KEY, VALUE);
48+
println!("Put key {:?}, value {:?}.", KEY, VALUE);
4949

50-
//
5150
// Unlike a standard Rust HashMap all calls take owned values. This is because under the hood
5251
// protobufs must take ownership of the data. If we only took a borrow we'd need to internally
5352
// clone it. This is against Rust API guidelines, so you must manage this yourself.
@@ -56,47 +55,54 @@ fn main() -> Result<()> {
5655
// This type is practical to use for real things, and usage forces an internal copy.
5756
//
5857
// It is best to pass a `Vec<u8>` in terms of explictness and speed. `String`s and a few other
59-
// types are supported as well, but it all ends up as `Vec<u8>` in the end.
60-
let key: String = String::from(KEY);
61-
let value: Value = client.get(key.clone()).wait()?.expect("value must exist");
62-
assert_eq!(value.as_ref(), VALUE.as_bytes());
63-
println!("Get key \"{:?}\" returned value \"{:?}\".", value, KEY);
58+
// types are supported as well, but it all ends up as `Vec<u8>` in the end.
59+
let value: Option<Value> = client.get(KEY).wait()?;
60+
assert_eq!(value, Some(Value::from(VALUE)));
61+
println!("Get key {:?} returned value {:?}.", Key::from(KEY), value);
6462

6563
// You can also set the `ColumnFamily` used by the request.
6664
// This is *advanced usage* and should have some special considerations.
67-
client
68-
.delete(key.clone())
69-
.wait()
70-
.expect("Could not delete value");
71-
println!("Key: {:?} deleted", key);
65+
client.delete(KEY).wait().expect("Could not delete value");
66+
println!("Key: {:?} deleted", Key::from(KEY));
7267

73-
// Get returns None for non-existing key
74-
assert!(client.get(key).wait()?.is_none());
75-
76-
let pairs: Vec<KvPair> = (1..3)
77-
.map(|i| KvPair::from((Key::from(format!("k{}", i)), Value::from(format!("v{}", i)))))
78-
.collect();
79-
client
80-
.batch_put(pairs.clone())
68+
// Here we check if the key has been deleted from the key-value store.
69+
let value: Option<Value> = client
70+
.get(KEY)
8171
.wait()
82-
.expect("Could not put pairs");
72+
.expect("Could not get just deleted entry");
73+
assert!(value.is_none());
8374

84-
let keys = vec![Key::from(b"k1".to_vec()), Key::from(b"k2".to_vec())];
75+
// You can ask to write multiple key-values at the same time, it is much more
76+
// performant because it is passed in one request to the key-value store.
77+
let pairs = vec![
78+
KvPair::from(("k1", "v1")),
79+
KvPair::from(("k2", "v2")),
80+
KvPair::from(("k3", "v3")),
81+
];
82+
client.batch_put(pairs).wait().expect("Could not put pairs");
8583

84+
// Same thing when you want to retrieve multiple values.
85+
let keys = vec![Key::from("k1"), Key::from("k2")];
8686
let values = client
8787
.batch_get(keys.clone())
8888
.wait()
8989
.expect("Could not get values");
9090
println!("Found values: {:?} for keys: {:?}", values, keys);
9191

92-
let start: Key = b"k1".to_vec().into();
93-
let end: Key = b"k2".to_vec().into();
94-
client
95-
.scan(start.clone()..end.clone(), 10)
92+
// Scanning a range of keys is also possible giving it two bounds
93+
// it will returns all entries between these two.
94+
let start = "k1";
95+
let end = "k2";
96+
let pairs = client
97+
.scan(start..=end, 10)
9698
.key_only()
9799
.wait()
98100
.expect("Could not scan");
99101

102+
let keys: Vec<_> = pairs.into_iter().map(|p| p.key().clone()).collect();
103+
assert_eq!(&keys, &[Key::from("k1"), Key::from("k2")]);
104+
println!("Scaning from {:?} to {:?} gives: {:?}", start, end, keys);
105+
100106
// Cleanly exit.
101107
Ok(())
102108
}

examples/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn main() {
8484
Config::new(args.pd)
8585
};
8686

87-
let txn = Client::new(&config)
87+
let txn = Client::new(config)
8888
.wait()
8989
.expect("Could not connect to tikv");
9090

rust-toolchain

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
// Long and nested future chains can quickly result in large generic types.
1515
#![type_length_limit = "16777216"]
16+
#![allow(clippy::redundant_closure)]
1617

1718
//! TiKV Client for Rust.
1819
//!
@@ -101,7 +102,7 @@
101102
//! ]).with_security("root.ca", "internal.cert", "internal.key");
102103
//!
103104
//! // Get an unresolved connection.
104-
//! let connect = Client::new(&config);
105+
//! let connect = Client::new(config);
105106
//!
106107
//! // Resolve the connection into a client.
107108
//! let client = connect.wait();
@@ -360,7 +361,6 @@ impl fmt::Debug for Value {
360361
Ok(s) => write!(f, "Value({:?})", s),
361362
Err(_) => write!(f, "Value({})", HexRepr(&self.0)),
362363
}
363-
364364
}
365365
}
366366

0 commit comments

Comments
 (0)