Skip to content

Commit 5b91ab9

Browse files
committed
Polish docs of clients and config
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent 79d0d56 commit 5b91ab9

File tree

4 files changed

+121
-90
lines changed

4 files changed

+121
-90
lines changed

src/config.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,11 @@
33
use serde_derive::{Deserialize, Serialize};
44
use std::{path::PathBuf, time::Duration};
55

6-
/// The configuration for either a `raw::Client` or a `transaction::Client`.
6+
/// The configuration for either a [`RawClient`](crate::RawClient) or a
7+
/// [`TransactionClient`](crate::TransactionClient).
78
///
8-
/// Because TiKV is managed by a [PD](https://github.com/pingcap/pd/) cluster, the endpoints for PD
9-
/// must be provided, **not** the TiKV nodes.
10-
///
11-
/// It's important to **include more than one PD endpoint** (include all, if possible!)
12-
/// This helps avoid having a *single point of failure*.
13-
///
14-
/// By default, this client will use an insecure connection over instead of one protected by
15-
/// Transport Layer Security (TLS). Your deployment may have chosen to rely on security measures
16-
/// such as a private network, or a VPN layer to provide secure transmission.
17-
///
18-
/// To use a TLS secured connection, use the `with_security` function to set the required
19-
/// parameters.
20-
///
21-
/// TiKV does not currently offer encrypted storage (or encryption-at-rest).
9+
/// See also [`TransactionOptions`](crate::TransactionOptions) which provides more ways to configure
10+
/// requests.
2211
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
2312
#[serde(default)]
2413
#[serde(rename_all = "kebab-case")]
@@ -43,11 +32,16 @@ impl Default for Config {
4332
}
4433

4534
impl Config {
46-
/// Set the certificate authority, certificate, and key locations for the
47-
/// [`Config`](Config).
35+
/// Set the certificate authority, certificate, and key locations for clients.
4836
///
49-
/// By default, TiKV connections do not utilize transport layer security. Enable it by setting
50-
/// these values.
37+
/// By default, this client will use an insecure connection over instead of one protected by
38+
/// Transport Layer Security (TLS). Your deployment may have chosen to rely on security measures
39+
/// such as a private network, or a VPN layer to provide secure transmission.
40+
///
41+
/// To use a TLS secured connection, use the `with_security` function to set the required
42+
/// parameters.
43+
///
44+
/// TiKV does not currently offer encrypted storage (or encryption-at-rest).
5145
///
5246
/// # Examples
5347
/// ```rust
@@ -66,16 +60,21 @@ impl Config {
6660
self
6761
}
6862

69-
/// Set the timeout for the [`Config`](Config).
63+
/// Set the timeout for clients.
64+
///
65+
/// The timeout is used for all requests when using or connecting to a TiKV cluster (including
66+
/// PD nodes). If the request does not complete within timeout, the request is cancelled and
67+
/// an error returned to the user.
7068
///
69+
/// The default timeout is two seconds.
7170
///
7271
/// # Examples
7372
/// ```rust
7473
/// # use tikv_client::Config;
7574
/// # use std::time::Duration;
76-
/// let config = Config::default().timeout(Duration::from_secs(10));
75+
/// let config = Config::default().with_timeout(Duration::from_secs(10));
7776
/// ```
78-
pub fn timeout(mut self, timeout: Duration) -> Self {
77+
pub fn with_timeout(mut self, timeout: Duration) -> Self {
7978
self.timeout = timeout;
8079
self
8180
}

src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,32 @@
6262
//!
6363
//! Raw mode:
6464
//!
65-
//! ```rust
66-
//! use tikv_client::RawClient;
67-
//!
65+
//! ```rust,no_run
66+
//! # use tikv_client::{RawClient, Result};
67+
//! # use futures::prelude::*;
68+
//! # fn main() -> Result<()> {
69+
//! # futures::executor::block_on(async {
6870
//! let client = RawClient::new(vec!["127.0.0.1:2379"]).await?;
6971
//! client.put("key".to_owned(), "value".to_owned()).await?;
7072
//! let value = client.get("key".to_owned()).await?;
73+
//! # Ok(())
74+
//! # })}
7175
//! ```
7276
//!
7377
//! Transactional mode:
7478
//!
75-
//! ```rust
76-
//! use tikv_client::TransactionClient;
77-
//!
79+
//! ```rust,no_run
80+
//! # use tikv_client::{TransactionClient, Result};
81+
//! # use futures::prelude::*;
82+
//! # fn main() -> Result<()> {
83+
//! # futures::executor::block_on(async {
7884
//! let txn_client = TransactionClient::new(vec!["127.0.0.1:2379"]).await?;
7985
//! let mut txn = txn_client.begin_optimistic().await?;
8086
//! txn.put("key".to_owned(), "value".to_owned()).await?;
8187
//! let value = txn.get("key".to_owned()).await?;
8288
//! txn.commit().await?;
89+
//! # Ok(())
90+
//! # })}
8391
//! ```
8492
8593
#[macro_use]

src/raw/client.rs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const MAX_RAW_KV_SCAN_LIMIT: u32 = 10240;
1919
/// Raw requests don't need a wrapping transaction.
2020
/// Each request is immediately processed once executed.
2121
///
22-
/// The returned results of raw requests are [`Future`](std::future::Future)s that must be awaited to execute.
22+
/// The returned results of raw request methods are [`Future`](std::future::Future)s that must be
23+
/// awaited to execute.
2324
#[derive(Clone)]
2425
pub struct Client {
2526
rpc: Arc<PdRpcClient>,
@@ -29,14 +30,16 @@ pub struct Client {
2930
}
3031

3132
impl Client {
32-
/// Create a raw [`Client`](Client).
33+
/// Create a raw [`Client`] and connect to the TiKV cluster.
3334
///
34-
/// It's important to **include more than one PD endpoint** (include all, if possible!)
35-
/// This helps avoid having a *single point of failure*.
35+
/// Because TiKV is managed by a [PD](https://github.com/pingcap/pd/) cluster, the endpoints for
36+
/// PD must be provided, not the TiKV nodes. It's important to include more than one PD endpoint
37+
/// (include all endpoints, if possible), this helps avoid having a single point of failure.
3638
///
3739
/// # Examples
40+
///
3841
/// ```rust,no_run
39-
/// # use tikv_client::{Config, RawClient};
42+
/// # use tikv_client::RawClient;
4043
/// # use futures::prelude::*;
4144
/// # futures::executor::block_on(async {
4245
/// let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
@@ -46,17 +49,23 @@ impl Client {
4649
Self::new_with_config(pd_endpoints, Config::default()).await
4750
}
4851

49-
/// Create a raw [`Client`](Client).
52+
/// Create a raw [`Client`] with a custom configuration, and connect to the TiKV cluster.
5053
///
51-
/// It's important to **include more than one PD endpoint** (include all, if possible!)
52-
/// This helps avoid having a *single point of failure*.
54+
/// Because TiKV is managed by a [PD](https://github.com/pingcap/pd/) cluster, the endpoints for
55+
/// PD must be provided, not the TiKV nodes. It's important to include more than one PD endpoint
56+
/// (include all endpoints, if possible), this helps avoid having a single point of failure.
5357
///
5458
/// # Examples
59+
///
5560
/// ```rust,no_run
5661
/// # use tikv_client::{Config, RawClient};
5762
/// # use futures::prelude::*;
63+
/// # use std::time::Duration;
5864
/// # futures::executor::block_on(async {
59-
/// let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
65+
/// let client = RawClient::new_with_config(
66+
/// vec!["192.168.0.100"],
67+
/// Config::default().with_timeout(Duration::from_secs(60)),
68+
/// ).await.unwrap();
6069
/// # });
6170
/// ```
6271
pub async fn new_with_config<S: Into<String>>(
@@ -72,22 +81,27 @@ impl Client {
7281
})
7382
}
7483

75-
/// Set the column family of requests.
76-
///
77-
/// This function returns a new `Client`, requests created with it will have the
78-
/// supplied column family constraint. The original `Client` can still be used.
84+
/// Create a new client which is a clone of `self`, but which uses an explicit column family for
85+
/// all requests.
7986
///
80-
/// By default, raw client uses the `Default` column family.
87+
/// This function returns a new `Client`; requests created with the new client will use the
88+
/// supplied column family. The original `Client` can still be used (without the new
89+
/// column family).
8190
///
82-
/// For normal users of the raw API, you don't need to use other column families.
91+
/// By default, raw clients use the `Default` column family.
8392
///
8493
/// # Examples
94+
///
8595
/// ```rust,no_run
8696
/// # use tikv_client::{Config, RawClient, ColumnFamily};
8797
/// # use futures::prelude::*;
8898
/// # use std::convert::TryInto;
8999
/// # futures::executor::block_on(async {
90-
/// let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap().with_cf(ColumnFamily::Write);
100+
/// let client = RawClient::new(vec!["192.168.0.100"])
101+
/// .await
102+
/// .unwrap()
103+
/// .with_cf(ColumnFamily::Write);
104+
/// // Fetch a value at "foo" from the Write CF.
91105
/// let get_request = client.get("foo".to_owned());
92106
/// # });
93107
/// ```
@@ -411,11 +425,11 @@ impl Client {
411425
///
412426
/// Once resolved this request will result in a set of scanners over the given keys.
413427
///
414-
/// **Warning**: This method is experimental. The `each_limit` parameter does not work as expected.
415-
/// It does not limit the number of results returned of each range,
428+
/// **Warning**: This method is experimental.
429+
/// The `each_limit` parameter does not limit the number of results returned of each range,
416430
/// instead it limits the number of results in each region of each range.
417-
/// As a result, you may get **more than** `each_limit` key-value pairs for each range.
418-
/// But you should not miss any entries.
431+
/// As a result, you may get **more than** `each_limit` key-value pairs for each range,
432+
/// but you should not miss any entries.
419433
///
420434
/// # Examples
421435
/// ```rust,no_run

0 commit comments

Comments
 (0)