Struct bb8_tivk::TransactionClient[][src]

pub struct TransactionClient { /* fields omitted */ }
Expand description

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

Transactions support optimistic and pessimistic modes. For more details see the SIG-transaction docs.

Begin a Transaction by calling begin_optimistic or begin_pessimistic. A transaction must be rolled back or committed.

Besides transactions, the client provides some further functionality:

  • gc: trigger a GC process which clears stale data in the cluster.
  • current_timestamp: get the current Timestamp from PD.
  • snapshot: get a Snapshot of the database at a specified timestamp. A Snapshot is a read-only transaction.

The returned results of transactional requests are Futures that must be awaited to execute.

Implementations

impl Client[src]

pub async fn new<S>(pd_endpoints: Vec<S, Global>) -> Result<Client, Error> where
    S: Into<String>, 
[src]

Create a transactional 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 = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();

pub async fn new_with_config<S>(
    pd_endpoints: Vec<S, Global>,
    config: Config
) -> Result<Client, Error> where
    S: Into<String>, 
[src]

Create a transactional 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 = TransactionClient::new_with_config(
    vec!["192.168.0.100"],
    Config::default().with_timeout(Duration::from_secs(60)),
).await.unwrap();

pub async fn begin_optimistic(
    &'_ self
) -> Result<Transaction<PdRpcClient<TikvConnect, Cluster>>, Error>
[src]

Creates a new optimistic Transaction.

Use the transaction to issue requests like get or put.

Write operations do not lock data in TiKV, thus the commit request may fail due to a write conflict.

Examples

let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();
let mut transaction = client.begin_optimistic().await.unwrap();
// ... Issue some commands.
transaction.commit().await.unwrap();

pub async fn begin_pessimistic(
    &'_ self
) -> Result<Transaction<PdRpcClient<TikvConnect, Cluster>>, Error>
[src]

Creates a new pessimistic Transaction.

Write operations will lock the data until committed, thus commit requests should not suffer from write conflicts.

Examples

let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();
let mut transaction = client.begin_pessimistic().await.unwrap();
// ... Issue some commands.
transaction.commit().await.unwrap();

pub async fn begin_with_options(
    &'_ self,
    options: TransactionOptions
) -> Result<Transaction<PdRpcClient<TikvConnect, Cluster>>, Error>
[src]

Create a new customized Transaction.

Examples

let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();
let mut transaction = client
    .begin_with_options(TransactionOptions::default().use_async_commit())
    .await
    .unwrap();
// ... Issue some commands.
transaction.commit().await.unwrap();

pub fn snapshot(
    &self,
    timestamp: Timestamp,
    options: TransactionOptions
) -> Snapshot
[src]

Create a new Snapshot at the given Timestamp.

pub async fn current_timestamp(&'_ self) -> Result<Timestamp, Error>[src]

Retrieve the current [Timestamp].

Examples

let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();
let timestamp = client.current_timestamp().await.unwrap();

pub async fn gc(&'_ self, safepoint: Timestamp) -> Result<bool, Error>[src]

Request garbage collection (GC) of the TiKV cluster.

GC deletes MVCC records whose timestamp is lower than the given safepoint.

For each key, the last mutation record (unless it’s a deletion) before safepoint is retained.

GC is performed by:

  1. resolving all locks with timestamp <= safepoint
  2. updating PD’s known safepoint

This is a simplified version of GC in TiDB. We skip the second step “delete ranges” which is an optimization for TiDB.

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

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

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

fn in_current_span(self) -> Instrumented<Self>[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

pub fn vzip(self) -> V