Skip to content

Commit a89599e

Browse files
committed
Tidy up lib.rs
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 995fe61 commit a89599e

File tree

8 files changed

+36
-72
lines changed

8 files changed

+36
-72
lines changed

src/lib.rs

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,37 @@
11
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
// Long and nested future chains can quickly result in large generic types.
4-
#![type_length_limit = "16777216"]
5-
#![allow(clippy::redundant_closure)]
6-
#![allow(clippy::type_complexity)]
7-
#![allow(incomplete_features)]
8-
9-
//! This crate provides a clean, ready to use client for [TiKV](https://github.com/tikv/tikv), a
10-
//! distributed transactional Key-Value database written in Rust.
3+
//! This crate provides an easy-to-use client for [TiKV](https://github.com/tikv/tikv), a
4+
//! distributed, transactional key-value database written in Rust.
115
//!
12-
//! With this crate you can easily connect to any TiKV deployment, interact with it, and mutate the
13-
//! data it contains.
6+
//! This crate lets you connect to a TiKV cluster and use either a transactional or raw (simple
7+
//! get/put style without transactional consistency guarantees) API to access and update your data.
148
//!
159
//! ## Choosing an API
1610
//!
1711
//! This crate offers both [**raw**](raw/index.html) and
1812
//! [**transactional**](transaction/index.html) APIs. You should choose just one for your system.
1913
//!
20-
//! The *consequence* of supporting transactions is increased overhead of coordination with the
21-
//! placement driver for timestamp acquisition. This is approximately 1 RTT.
14+
//! The consequence of supporting transactions is increased overhead of coordination with the
15+
//! placement driver and TiKV, and additional code complexity.
2216
//!
2317
//! *While it is possible to use both APIs at the same time, doing so is unsafe and unsupported.*
2418
//!
25-
//! Choose the one that suites your needs as described below, then add the import statement to your
26-
//! file where you need to use the library.
27-
//!
2819
//! ### Transactional
2920
//!
30-
//! The [transactional](transaction/index.html) API supports **transactions** via Multi-Version
31-
//! Concurrency Control (MVCC).
21+
//! The [transactional](transaction/index.html) API supports **transactions** via multi-version
22+
//! concurrency control (MVCC).
3223
//!
33-
//! **Best when you mostly do** complex sets of actions, actions which may require a rollback,
34-
//! operations affecting multiple keys or values, or operations that depend on strong ordering.
24+
//! Best when you mostly do complex sets of actions, actions which may require a rollback,
25+
//! operations affecting multiple keys or values, or operations that depend on strong consistency.
3526
//!
36-
//! ```rust
37-
//! use tikv_client::*;
38-
//! ```
3927
//!
4028
//! ### Raw
4129
//!
42-
//! The [raw](raw/index.html) API has **reduced coordination overhead**, but lacks any
30+
//! The [raw](raw/index.html) API has reduced coordination overhead, but lacks any
4331
//! transactional abilities.
4432
//!
45-
//! **Best when you mostly do** single row changes, and have very limited cross-row (eg. foreign
46-
//! key) requirements. You will not be able to use transactions with this API.
47-
//!
48-
//! ```rust
49-
//! use tikv_client::*;
50-
//! ```
51-
//!
52-
//! ## Connect
53-
//!
54-
//! Regardless of which API you choose, you'll need to connect your client
55-
//! ([raw](raw::Client), [transactional](transaction::Client)).
56-
//!
57-
//! ```rust,no_run
58-
//! # use tikv_client::*;
59-
//! # use futures::prelude::*;
60-
//!
61-
//! # futures::executor::block_on(async {
62-
//! // Configure endpoints and optional TLS.
63-
//! let config = Config::default().with_security("root.ca", "internal.cert", "internal.key");
64-
//!
65-
//! // Get a transactional client.
66-
//! let client = TransactionClient::new_with_config(
67-
//! vec![
68-
//! // A list of PD endpoints.
69-
//! "192.168.0.100:2379",
70-
//! "192.168.0.101:2379",
71-
//! ], config).await.unwrap();
72-
//! # });
73-
//! ```
74-
//!
75-
//! At this point, you should seek the documentation in the related API modules.
33+
//! Best when you mostly do single value changes, and have very limited cross-value
34+
//! requirements. You will not be able to use transactions with this API.
7635
7736
#[macro_use]
7837
mod request;
@@ -117,6 +76,4 @@ pub use crate::transaction::{
11776
#[doc(inline)]
11877
pub use config::Config;
11978
#[doc(inline)]
120-
pub use region::{Region, RegionId, RegionVerId, StoreId};
121-
#[doc(inline)]
12279
pub use tikv_client_common::{security::SecurityManager, Error, Result};

src/pd/client.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// Copyright 2018 TiKV Project Authors. Licensed under Apache-2.0.
22

33
use crate::{
4-
compat::stream_fn, kv::codec, pd::RetryClient, store::Store, BoundRange, Config, Key, Region,
5-
RegionId, Result, SecurityManager, Timestamp,
4+
compat::stream_fn,
5+
kv::codec,
6+
pd::RetryClient,
7+
region::{Region, RegionId},
8+
store::Store,
9+
BoundRange, Config, Key, Result, SecurityManager, Timestamp,
610
};
711
use async_trait::async_trait;
812
use futures::{prelude::*, stream::BoxStream};

src/pd/retry.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
//! A utility module for managing and retrying PD requests.
44
5-
use crate::{stats::pd_stats, Error, Region, RegionId, Result, SecurityManager, StoreId};
5+
use crate::{
6+
region::{Region, RegionId, StoreId},
7+
stats::pd_stats,
8+
Error, Result, SecurityManager,
9+
};
610
use async_trait::async_trait;
711
use futures_timer::Delay;
812
use grpcio::Environment;

src/store.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

3-
use crate::{pd::PdClient, BoundRange, Key, Region, Result};
3+
use crate::{pd::PdClient, region::Region, BoundRange, Key, Result};
44
use derive_new::new;
55
use futures::{prelude::*, stream::BoxStream};
66
use std::{
@@ -48,6 +48,7 @@ where
4848
.boxed()
4949
}
5050

51+
#[allow(clippy::type_complexity)]
5152
pub fn store_stream_for_range<PdC: PdClient>(
5253
range: (Vec<u8>, Vec<u8>),
5354
pd_client: Arc<PdC>,
@@ -67,16 +68,16 @@ pub fn store_stream_for_range<PdC: PdClient>(
6768
}
6869

6970
pub fn store_stream_for_range_by_start_key<PdC: PdClient>(
70-
start_key: Vec<u8>,
71+
start_key: Key,
7172
pd_client: Arc<PdC>,
7273
) -> BoxStream<'static, Result<(Vec<u8>, Store)>> {
73-
let bnd_range = BoundRange::range_from(start_key.clone().into());
74+
let bnd_range = BoundRange::range_from(start_key.clone());
7475
pd_client
7576
.stores_for_range(bnd_range)
7677
.map_ok(move |store| {
7778
let region_range = store.region.range();
7879
(
79-
range_intersection(region_range, (start_key.clone().into(), vec![].into()))
80+
range_intersection(region_range, (start_key.clone(), vec![].into()))
8081
.0
8182
.into(),
8283
store,

src/transaction/buffer.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ impl Buffer {
7575
let (cached_results, undetermined_keys) = {
7676
// Partition the keys into those we have buffered and those we have to
7777
// get from the store.
78-
let (undetermined_keys, cached_results): (
79-
Vec<(Key, MutationValue)>,
80-
Vec<(Key, MutationValue)>,
81-
) = keys
78+
let (undetermined_keys, cached_results): (Vec<_>, Vec<_>) = keys
8279
.map(|key| {
8380
let value = self
8481
.entry_map

src/transaction/lock.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
use crate::{
44
backoff::{Backoff, DEFAULT_REGION_BACKOFF, OPTIMISTIC_BACKOFF},
55
pd::PdClient,
6+
region::RegionVerId,
67
request::Plan,
78
timestamp::TimestampExt,
89
transaction::requests,
9-
Error, RegionVerId, Result,
10+
Error, Result,
1011
};
1112
use std::{
1213
collections::{HashMap, HashSet},

src/transaction/requests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,11 @@ impl KvRequest for kvrpcpb::CommitRequest {
278278
shardable_keys!(kvrpcpb::CommitRequest);
279279

280280
pub fn new_batch_rollback_request(
281-
keys: Vec<Key>,
281+
keys: Vec<Vec<u8>>,
282282
start_version: u64,
283283
) -> kvrpcpb::BatchRollbackRequest {
284284
let mut req = kvrpcpb::BatchRollbackRequest::default();
285-
req.set_keys(keys.into_iter().map(Into::into).collect());
285+
req.set_keys(keys);
286286
req.set_start_version(start_version);
287287

288288
req
@@ -429,7 +429,7 @@ impl Shardable for kvrpcpb::ScanLockRequest {
429429
&self,
430430
pd_client: &Arc<impl PdClient>,
431431
) -> BoxStream<'static, Result<(Self::Shard, Store)>> {
432-
store_stream_for_range_by_start_key(self.start_key.clone(), pd_client.clone())
432+
store_stream_for_range_by_start_key(self.start_key.clone().into(), pd_client.clone())
433433
}
434434

435435
fn apply_shard(&mut self, shard: Self::Shard, store: &Store) -> Result<()> {

src/transaction/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ impl<PdC: PdClient> Committer<PdC> {
10351035
r.min_commit_ts
10361036
})
10371037
.max()
1038-
.map(|ts| Timestamp::from_version(ts));
1038+
.map(Timestamp::from_version);
10391039

10401040
Ok(min_commit_ts)
10411041
}

0 commit comments

Comments
 (0)