Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- run: rustup component add rustfmt clippy
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand All @@ -35,11 +29,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand All @@ -57,11 +46,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand Down
11 changes: 1 addition & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@ integration-test:

test: unit-test integration-test

doc:
doc:
cargo doc --workspace --exclude tikv-client-proto --document-private-items --no-deps

# Deprecated
# docker-pd:
# docker run -d -v $(shell pwd)/config:/config --net=host --name pd --rm pingcap/pd:latest --name "pd" --data-dir "pd" --client-urls "http://127.0.0.1:2379" --advertise-client-urls "http://127.0.0.1:2379" --config /config/pd.toml

# docker-kv:
# docker run -d -v $(shell pwd)/config:/config --net=host --name kv --rm --ulimit nofile=90000:90000 pingcap/tikv:latest --pd-endpoints "127.0.0.1:2379" --addr "127.0.0.1:2378" --data-dir "kv" --config /config/tikv.toml

# docker: docker-pd docker-kv

tiup:
tiup playground nightly --mode tikv-slim --kv 3 --without-monitor --kv.config $(shell pwd)/config/tikv.toml --pd.config $(shell pwd)/config/pd.toml &

Expand Down
29 changes: 16 additions & 13 deletions examples/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ async fn main() -> Result<()> {
.expect("Could not scan");

let keys: Vec<_> = pairs.into_iter().map(|p| p.key().clone()).collect();
assert_eq!(&keys, &[
Key::from("k1".to_owned()),
Key::from("k2".to_owned()),
]);
assert_eq!(
&keys,
&[Key::from("k1".to_owned()), Key::from("k2".to_owned()),]
);
println!("Scanning from {start:?} to {end:?} gives: {keys:?}");

let k1 = "k1";
Expand All @@ -122,15 +122,18 @@ async fn main() -> Result<()> {
.into_iter()
.map(|p| String::from_utf8(p.1).unwrap())
.collect();
assert_eq!(&vals, &[
"v1".to_owned(),
"v2".to_owned(),
"v2".to_owned(),
"v3".to_owned(),
"v1".to_owned(),
"v2".to_owned(),
"v3".to_owned()
]);
assert_eq!(
&vals,
&[
"v1".to_owned(),
"v2".to_owned(),
"v2".to_owned(),
"v3".to_owned(),
"v1".to_owned(),
"v2".to_owned(),
"v3".to_owned()
]
);
println!("Scanning batch scan from {batch_scan_keys:?} gives: {vals:?}");

// Cleanly exit.
Expand Down
8 changes: 4 additions & 4 deletions examples/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ async fn main() {
let key1_exists = key_exists(&txn, key1.clone()).await;
let key2: Key = b"key_not_exist".to_vec().into();
let key2_exists = key_exists(&txn, key2.clone()).await;
println!("check exists {:?}", vec![
(key1, key1_exists),
(key2, key2_exists)
]);
println!(
"check exists {:?}",
vec![(key1, key1_exists), (key2, key2_exists)]
);

// scan
let key1: Key = b"key1".to_vec().into();
Expand Down
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "clippy"]
20 changes: 12 additions & 8 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
edition = "2021"
version = "Two"
reorder_imports = true
imports_granularity = "Item"
group_imports = "StdExternalCrate"
where_single_line = true
trailing_comma = "Vertical"
overflow_delimited_expr = true
format_code_in_doc_comments = true
normalize_comments = true

# Those options are disabled for not supported in stable rust.
# We should enable them back once stabilized.
#
# version = "Two"
Comment thread
Xuanwo marked this conversation as resolved.
# imports_granularity = "Item"
# group_imports = "StdExternalCrate"
# where_single_line = true
# trailing_comma = "Vertical"
# overflow_delimited_expr = true
# format_code_in_doc_comments = true
# normalize_comments = true
32 changes: 20 additions & 12 deletions src/kv/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,26 @@ pub mod test {
#[test]
fn test_enc_dec_bytes() {
let pairs = vec![
(vec![], vec![0, 0, 0, 0, 0, 0, 0, 0, 247], vec![
255, 255, 255, 255, 255, 255, 255, 255, 8,
]),
(vec![0], vec![0, 0, 0, 0, 0, 0, 0, 0, 248], vec![
255, 255, 255, 255, 255, 255, 255, 255, 7,
]),
(vec![1, 2, 3], vec![1, 2, 3, 0, 0, 0, 0, 0, 250], vec![
254, 253, 252, 255, 255, 255, 255, 255, 5,
]),
(vec![1, 2, 3, 0], vec![1, 2, 3, 0, 0, 0, 0, 0, 251], vec![
254, 253, 252, 255, 255, 255, 255, 255, 4,
]),
(
vec![],
vec![0, 0, 0, 0, 0, 0, 0, 0, 247],
vec![255, 255, 255, 255, 255, 255, 255, 255, 8],
),
(
vec![0],
vec![0, 0, 0, 0, 0, 0, 0, 0, 248],
vec![255, 255, 255, 255, 255, 255, 255, 255, 7],
),
(
vec![1, 2, 3],
vec![1, 2, 3, 0, 0, 0, 0, 0, 250],
vec![254, 253, 252, 255, 255, 255, 255, 255, 5],
),
(
vec![1, 2, 3, 0],
vec![1, 2, 3, 0, 0, 0, 0, 0, 251],
vec![254, 253, 252, 255, 255, 255, 255, 255, 4],
),
(
vec![1, 2, 3, 4, 5, 6, 7],
vec![1, 2, 3, 4, 5, 6, 7, 0, 254],
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
// To support both prost & rust-protobuf.
#![cfg_attr(feature = "prost-codec", allow(clippy::useless_conversion))]
#![allow(clippy::field_reassign_with_default)]
#![allow(clippy::arc_with_non_send_sync)]

pub mod backoff;
#[doc(hidden)]
Expand Down
4 changes: 3 additions & 1 deletion src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ pub struct MockKvClient {

impl MockKvClient {
pub fn with_dispatch_hook<F>(dispatch: F) -> MockKvClient
where F: Fn(&dyn Any) -> Result<Box<dyn Any>> + Send + Sync + 'static {
where
F: Fn(&dyn Any) -> Result<Box<dyn Any>> + Send + Sync + 'static,
{
MockKvClient {
addr: String::new(),
dispatch: Some(Arc::new(dispatch)),
Expand Down
34 changes: 20 additions & 14 deletions src/pd/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,19 @@ pub mod test {
let mut stream = executor::block_on_stream(stream);

let result: Vec<Key> = stream.next().unwrap().unwrap().1;
assert_eq!(result, vec![
vec![1].into(),
vec![2].into(),
vec![3].into(),
vec![5, 2].into()
]);
assert_eq!(stream.next().unwrap().unwrap().1, vec![
vec![12].into(),
vec![11, 4].into()
]);
assert_eq!(
result,
vec![
vec![1].into(),
vec![2].into(),
vec![3].into(),
vec![5, 2].into()
]
);
assert_eq!(
stream.next().unwrap().unwrap().1,
vec![vec![12].into(), vec![11, 4].into()]
);
assert!(stream.next().is_none());
}

Expand Down Expand Up @@ -425,10 +428,13 @@ pub mod test {
let ranges4 = stream.next().unwrap().unwrap();

assert_eq!(ranges1.0.id(), 1);
assert_eq!(ranges1.1, vec![
make_key_range(k1.clone(), k2.clone()),
make_key_range(k1.clone(), k_split.clone()),
]);
assert_eq!(
ranges1.1,
vec![
make_key_range(k1.clone(), k2.clone()),
make_key_range(k1.clone(), k_split.clone()),
]
);
assert_eq!(ranges2.0.id(), 2);
assert_eq!(ranges2.1, vec![make_key_range(k_split.clone(), k3.clone())]);
assert_eq!(ranges3.0.id(), 1);
Expand Down
35 changes: 20 additions & 15 deletions src/raw/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,21 +693,26 @@ mod tests {
.into_iter()
.map(|(data, ranges)| (String::from_utf8(data).unwrap(), ranges))
.collect();
assert_eq!(resps, vec![
("1:[Key(05)..Key(0A)]".to_string(), vec![
Key::from(vec![5])..Key::from(vec![10])
]),
(
"2:[Key(0A)..Key(0F), Key(14)..Key(FAFA)]".to_string(),
vec![
Key::from(vec![10])..Key::from(vec![15]),
Key::from(vec![20])..Key::from(vec![250, 250])
]
),
("3:[Key(FAFA)..Key()]".to_string(), vec![
Key::from(vec![250, 250])..Key::from(vec![])
])
]);
assert_eq!(
resps,
vec![
(
"1:[Key(05)..Key(0A)]".to_string(),
vec![Key::from(vec![5])..Key::from(vec![10])]
),
(
"2:[Key(0A)..Key(0F), Key(14)..Key(FAFA)]".to_string(),
vec![
Key::from(vec![10])..Key::from(vec![15]),
Key::from(vec![20])..Key::from(vec![250, 250])
]
),
(
"3:[Key(FAFA)..Key()]".to_string(),
vec![Key::from(vec![250, 250])..Key::from(vec![])]
)
]
);
Ok(())
}
}
33 changes: 17 additions & 16 deletions src/region_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,9 @@ mod test {
async fn cache_is_used() -> Result<()> {
let retry_client = Arc::new(MockRetryClient::default());
let cache = RegionCache::new(retry_client.clone());
retry_client
.regions
.lock()
.await
.insert(1, RegionWithLeader {
retry_client.regions.lock().await.insert(
1,
RegionWithLeader {
region: metapb::Region {
id: 1,
start_key: vec![],
Expand All @@ -337,12 +335,11 @@ mod test {
store_id: 1,
..Default::default()
}),
});
retry_client
.regions
.lock()
.await
.insert(2, RegionWithLeader {
},
);
retry_client.regions.lock().await.insert(
2,
RegionWithLeader {
region: metapb::Region {
id: 2,
start_key: vec![101],
Expand All @@ -357,7 +354,8 @@ mod test {
store_id: 2,
..Default::default()
}),
});
},
);

assert_eq!(retry_client.get_region_count.load(SeqCst), 0);

Expand All @@ -378,10 +376,13 @@ mod test {

// update leader should work
cache
.update_leader(cache.get_region_by_id(2).await?.ver_id(), metapb::Peer {
store_id: 102,
..Default::default()
})
.update_leader(
cache.get_region_by_id(2).await?.ver_id(),
metapb::Peer {
store_id: 102,
..Default::default()
},
)
.await?;
assert_eq!(
cache.get_region_by_id(2).await?.leader.unwrap().store_id,
Expand Down
Loading