Struct tikv_client::transaction::client::Client[][src]

pub struct Client {
    pd: Arc<PdRpcClient>,
}

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

A Transaction provides a SQL-like interface. It begins with a begin_optimistic or begin_pessimistic request and ends with a rollback or commit request. If a Transaction is dropped before it’s rolled back or committed, it is automatically rolled back.

Transaction supports optimistic and pessimistic modes, for mroe deatils, check our SIG-transaction.

Besides transaction, the client provides some utility methods:

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

Fields

pd: Arc<PdRpcClient>

Implementations

impl Client[src]

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

Creates a transactional Client.

It’s important to include more than one PD endpoint (include all, if possible!) This helps avoid having a single point of failure.

Examples

use tikv_client::{Config, TransactionClient};
use futures::prelude::*;
let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();

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

Creates a transactional Client.

It’s important to include more than one PD endpoint (include all, if possible!) This helps avoid having a single point of failure.

Examples

use tikv_client::{Config, TransactionClient};
use futures::prelude::*;
let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();

pub async fn begin_optimistic(&self) -> Result<Transaction>[src]

Creates a new Transaction in optimistic mode.

Using the transaction you can issue commands like get or put.

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

For details, check our SIG-transaction.

Examples

use tikv_client::{Config, TransactionClient};
use futures::prelude::*;
let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();
let mut transaction = client.begin_optimistic().await.unwrap();
// ... Issue some commands.
let commit = transaction.commit();
let result = commit.await.unwrap();

pub async fn begin_pessimistic(&self) -> Result<Transaction>[src]

Creates a new Transaction in pessimistic mode.

Write operations will lock the data until commit, thus commit requests should not suffer from write conflict. For details, check our SIG-transaction.

Examples

use tikv_client::{Config, TransactionClient};
use futures::prelude::*;
let client = TransactionClient::new(vec!["192.168.0.100"]).await.unwrap();
let mut transaction = client.begin_pessimistic().await.unwrap();
// ... Issue some commands.
let commit = transaction.commit();
let result = commit.await.unwrap();

pub async fn begin_with_options(
    &self,
    options: TransactionOptions
) -> Result<Transaction>
[src]

Creates a new customized Transaction.

Examples

use tikv_client::{Config, TransactionClient, TransactionOptions};
use futures::prelude::*;
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.
let commit = transaction.commit();
let result = commit.await.unwrap();

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

Creates a new Snapshot at the given Timestamp.

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

Retrieves the current Timestamp.

Examples

use tikv_client::{Config, TransactionClient};
use futures::prelude::*;
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>[src]

Cleans MVCC records whose timestamp is lower than the given timestamp in TiKV.

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

It is done by:

  1. resolve all locks with ts <= safepoint
  2. update safepoint to PD

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

fn new_transaction(
    &self,
    timestamp: Timestamp,
    options: TransactionOptions
) -> Transaction
[src]

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]

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

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

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

impl<T> Instrument for T[src]

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

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.

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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]