Struct tikv_client::RawClient

source ·
pub struct RawClient<PdC: PdClient = PdRpcClient> { /* private fields */ }
Expand description

The TiKV raw Client is used to interact with TiKV using raw requests.

Raw requests don’t need a wrapping transaction. Each request is immediately processed once executed.

The returned results of raw request methods are Futures that must be awaited to execute.

Implementations§

source§

impl Client<PdRpcClient>

source

pub async fn new<S: Into<String>>(pd_endpoints: Vec<S>) -> Result<Self>

Create a raw Client and connect to the TiKV cluster.

Because TiKV is managed by a PD cluster, the endpoints for PD must be provided, not the TiKV nodes. It’s important to include more than one PD endpoint (include all endpoints, if possible), this helps avoid having a single point of failure.

§Examples
let client = RawClient::new(vec!["192.168.0.100"]).await.unwrap();
source

pub async fn new_with_config<S: Into<String>>( pd_endpoints: Vec<S>, config: Config, ) -> Result<Self>

Create a raw Client with a custom configuration, and connect to the TiKV cluster.

Because TiKV is managed by a PD cluster, the endpoints for PD must be provided, not the TiKV nodes. It’s important to include more than one PD endpoint (include all endpoints, if possible), this helps avoid having a single point of failure.

§Examples
let client = RawClient::new_with_config(
    vec!["192.168.0.100"],
    Config::default().with_timeout(Duration::from_secs(60)),
)
.await
.unwrap();
source

pub fn with_cf(&self, cf: ColumnFamily) -> Self

Create a new client which is a clone of self, but which uses an explicit column family for all requests.

This function returns a new Client; requests created with the new client will use the supplied column family. The original Client can still be used (without the new column family).

By default, raw clients use the Default column family.

§Examples
let client = RawClient::new(vec!["192.168.0.100"])
    .await
    .unwrap()
    .with_cf(ColumnFamily::Write);
// Fetch a value at "foo" from the Write CF.
let get_request = client.get("foo".to_owned());
source

pub fn with_backoff(&self, backoff: Backoff) -> Self

Set the Backoff strategy for retrying requests. The default strategy is DEFAULT_REGION_BACKOFF. See Backoff for more information.

§Examples
let client = RawClient::new(vec!["192.168.0.100"])
    .await
    .unwrap()
    .with_backoff(DEFAULT_REGION_BACKOFF);
// Fetch a value at "foo" from the Write CF.
let get_request = client.get("foo".to_owned());
source

pub fn with_atomic_for_cas(&self) -> Self

Set to use the atomic mode.

The only reason of using atomic mode is the compare_and_swap operation. To guarantee the atomicity of CAS, write operations like put or delete in atomic mode are more expensive. Some operations are not supported in the mode.

source§

impl<PdC: PdClient> Client<PdC>

source

pub async fn get(&self, key: impl Into<Key>) -> Result<Option<Value>>

Create a new ‘get’ request.

Once resolved this request will result in the fetching of the value associated with the given key.

Retuning Ok(None) indicates the key does not exist in TiKV.

§Examples
let key = "TiKV".to_owned();
let req = client.get(key);
let result: Option<Value> = req.await.unwrap();
source

pub async fn batch_get( &self, keys: impl IntoIterator<Item = impl Into<Key>>, ) -> Result<Vec<KvPair>>

Create a new ‘batch get’ request.

Once resolved this request will result in the fetching of the values associated with the given keys.

Non-existent entries will not appear in the result. The order of the keys is not retained in the result.

§Examples
let keys = vec!["TiKV".to_owned(), "TiDB".to_owned()];
let req = client.batch_get(keys);
let result: Vec<KvPair> = req.await.unwrap();
source

pub async fn get_key_ttl_secs(&self, key: impl Into<Key>) -> Result<Option<u64>>

Create a new ‘get key ttl’ request.

Once resolved this request will result in the fetching of the alive time left for the given key.

Retuning Ok(None) indicates the key does not exist in TiKV.

§Examples
§use tikv_client::{Value, Config, RawClient};
§use futures::prelude::*;
§futures::executor::block_on(async {
§let client = RawClient::new(vec![“192.168.0.100”]).await.unwrap();

let key = “TiKV”.to_owned(); let req = client.get_key_ttl_secs(key); let result: Option = req.await.unwrap();

§});
source

pub async fn put( &self, key: impl Into<Key>, value: impl Into<Value>, ) -> Result<()>

Create a new ‘put’ request.

Once resolved this request will result in the setting of the value associated with the given key.

§Examples
let key = "TiKV".to_owned();
let val = "TiKV".to_owned();
let req = client.put(key, val);
let result: () = req.await.unwrap();
source

pub async fn put_with_ttl( &self, key: impl Into<Key>, value: impl Into<Value>, ttl_secs: u64, ) -> Result<()>

source

pub async fn batch_put( &self, pairs: impl IntoIterator<Item = impl Into<KvPair>>, ) -> Result<()>

Create a new ‘batch put’ request.

Once resolved this request will result in the setting of the values associated with the given keys.

§Examples
let kvpair1 = ("PD".to_owned(), "Go".to_owned());
let kvpair2 = ("TiKV".to_owned(), "Rust".to_owned());
let iterable = vec![kvpair1, kvpair2];
let req = client.batch_put(iterable);
let result: () = req.await.unwrap();
source

pub async fn batch_put_with_ttl( &self, pairs: impl IntoIterator<Item = impl Into<KvPair>>, ttls: impl IntoIterator<Item = u64>, ) -> Result<()>

source

pub async fn delete(&self, key: impl Into<Key>) -> Result<()>

Create a new ‘delete’ request.

Once resolved this request will result in the deletion of the given key.

It does not return an error if the key does not exist in TiKV.

§Examples
let key = "TiKV".to_owned();
let req = client.delete(key);
let result: () = req.await.unwrap();
source

pub async fn batch_delete( &self, keys: impl IntoIterator<Item = impl Into<Key>>, ) -> Result<()>

Create a new ‘batch delete’ request.

Once resolved this request will result in the deletion of the given keys.

It does not return an error if some of the keys do not exist and will delete the others.

§Examples
let keys = vec!["TiKV".to_owned(), "TiDB".to_owned()];
let req = client.batch_delete(keys);
let result: () = req.await.unwrap();
source

pub async fn delete_range(&self, range: impl Into<BoundRange>) -> Result<()>

Create a new ‘delete range’ request.

Once resolved this request will result in the deletion of all keys lying in the given range.

§Examples
let inclusive_range = "TiKV"..="TiDB";
let req = client.delete_range(inclusive_range.into_owned());
let result: () = req.await.unwrap();
source

pub async fn scan( &self, range: impl Into<BoundRange>, limit: u32, ) -> Result<Vec<KvPair>>

Create a new ‘scan’ request.

Once resolved this request will result in a Vec of key-value pairs that lies in the specified range.

If the number of eligible key-value pairs are greater than limit, only the first limit pairs are returned, ordered by the key.

§Examples
let inclusive_range = "TiKV"..="TiDB";
let req = client.scan(inclusive_range.into_owned(), 2);
let result: Vec<KvPair> = req.await.unwrap();
source

pub async fn scan_reverse( &self, range: impl Into<BoundRange>, limit: u32, ) -> Result<Vec<KvPair>>

Create a new ‘scan’ request but scans in “reverse” direction.

Once resolved this request will result in a Vec of key-value pairs that lies in the specified range.

If the number of eligible key-value pairs are greater than limit, only the first limit pairs are returned, ordered by the key.

Reverse Scan queries continuous kv pairs in range [startKey, endKey), from startKey(lowerBound) to endKey(upperBound) in reverse order, up to limit pairs. The returned keys are in reversed lexicographical order. If you want to include the endKey or exclude the startKey, push a ‘\0’ to the key. It doesn’t support Scanning from “”, because locating the last Region is not yet implemented.

§Examples
let inclusive_range = "TiKV"..="TiDB";
let req = client.scan_reverse(inclusive_range.into_owned(), 2);
let result: Vec<KvPair> = req.await.unwrap();
source

pub async fn scan_keys( &self, range: impl Into<BoundRange>, limit: u32, ) -> Result<Vec<Key>>

Create a new ‘scan’ request that only returns the keys.

Once resolved this request will result in a Vec of keys that lies in the specified range.

If the number of eligible keys are greater than limit, only the first limit pairs are returned, ordered by the key.

§Examples
let inclusive_range = "TiKV"..="TiDB";
let req = client.scan_keys(inclusive_range.into_owned(), 2);
let result: Vec<Key> = req.await.unwrap();
source

pub async fn scan_keys_reverse( &self, range: impl Into<BoundRange>, limit: u32, ) -> Result<Vec<Key>>

Create a new ‘scan’ request that only returns the keys in reverse order.

Once resolved this request will result in a Vec of keys that lies in the specified range.

If the number of eligible keys are greater than limit, only the first limit pairs are returned, ordered by the key.

§Examples
let inclusive_range = "TiKV"..="TiDB";
let req = client.scan_keys(inclusive_range.into_owned(), 2);
let result: Vec<Key> = req.await.unwrap();
source

pub async fn batch_scan( &self, ranges: impl IntoIterator<Item = impl Into<BoundRange>>, each_limit: u32, ) -> Result<Vec<KvPair>>

Create a new ‘batch scan’ request.

Once resolved this request will result in a set of scanners over the given keys.

Warning: This method is experimental. The each_limit parameter does not work as expected. It does not limit the number of results returned of each range, instead it limits the number of results in each region of each range. As a result, you may get more than each_limit key-value pairs for each range. But you should not miss any entries.

§Examples
let inclusive_range1 = "TiDB"..="TiKV";
let inclusive_range2 = "TiKV"..="TiSpark";
let iterable = vec![inclusive_range1.into_owned(), inclusive_range2.into_owned()];
let req = client.batch_scan(iterable, 2);
let result = req.await;
source

pub async fn batch_scan_keys( &self, ranges: impl IntoIterator<Item = impl Into<BoundRange>>, each_limit: u32, ) -> Result<Vec<Key>>

Create a new ‘batch scan’ request that only returns the keys.

Once resolved this request will result in a set of scanners over the given keys.

Warning: This method is experimental. The each_limit parameter does not limit the number of results returned of each range, instead it limits the number of results in each region of each range. As a result, you may get more than each_limit key-value pairs for each range, but you should not miss any entries.

§Examples
let inclusive_range1 = "TiDB"..="TiKV";
let inclusive_range2 = "TiKV"..="TiSpark";
let iterable = vec![inclusive_range1.into_owned(), inclusive_range2.into_owned()];
let req = client.batch_scan(iterable, 2);
let result = req.await;
source

pub async fn compare_and_swap( &self, key: impl Into<Key>, previous_value: impl Into<Option<Value>>, new_value: impl Into<Value>, ) -> Result<(Option<Value>, bool)>

Create a new atomic ‘compare and set’ request.

Once resolved this request will result in an atomic `compare and set’ operation for the given key.

If the value retrived is equal to current_value, new_value is written.

§Return Value

A tuple is returned if successful: the previous value and whether the value is swapped

source

pub async fn coprocessor( &self, copr_name: impl Into<String>, copr_version_req: impl Into<String>, ranges: impl IntoIterator<Item = impl Into<BoundRange>>, request_builder: impl Fn(Region, Vec<Range<Key>>) -> Vec<u8> + Send + Sync + 'static, ) -> Result<Vec<(Vec<Range<Key>>, Vec<u8>)>>

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<PdC> Freeze for Client<PdC>

§

impl<PdC> RefUnwindSafe for Client<PdC>
where PdC: RefUnwindSafe,

§

impl<PdC> Send for Client<PdC>

§

impl<PdC> Sync for Client<PdC>

§

impl<PdC> Unpin for Client<PdC>

§

impl<PdC> UnwindSafe for Client<PdC>
where PdC: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more