Struct tikv_client::RawClient

source ·
pub struct RawClient<Cod = ApiV1RawCodec, PdC = PdRpcClient<Cod>>where
    Cod: Codec,
    PdC: PdClient<Codec = Cod>,{ /* 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<ApiV1RawCodec, PdRpcClient<ApiV1RawCodec>>

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§

impl<Cod: Codec> Client<Cod, PdRpcClient<Cod>>

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<Cod: Codec, PdC: PdClient<Codec = Cod>> Client<Cod, 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 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 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 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_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 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<u8>, Vec<Range<Key>>)>>

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<Cod, PdC> RefUnwindSafe for Client<Cod, PdC>where PdC: RefUnwindSafe,

§

impl<Cod, PdC> Send for Client<Cod, PdC>

§

impl<Cod, PdC> Sync for Client<Cod, PdC>

§

impl<Cod, PdC> Unpin for Client<Cod, PdC>

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

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

impl<T> Instrument for T

§

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

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

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 Twhere 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> 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 Twhere 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 Twhere 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 Twhere 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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