Crate tikv_client[][src]

This crate provides a clean, ready to use client for TiKV, a distributed transactional Key-Value database written in Rust.

With this crate you can easily connect to any TiKV deployment, interact with it, and mutate the data it contains.

Choosing an API

This crate offers both raw and transactional APIs. You should choose just one for your system.

The consequence of supporting transactions is increased overhead of coordination with the placement driver for timestamp acquisition. This is approximately 1 RTT.

While it is possible to use both APIs at the same time, doing so is unsafe and unsupported.

Choose the one that suites your needs as described below, then add the import statement to your file where you need to use the library.

Transactional

The transactional API supports transactions via Multi-Version Concurrency Control (MVCC).

Best when you mostly do complex sets of actions, actions which may require a rollback, operations affecting multiple keys or values, or operations that depend on strong ordering.

use tikv_client::*;

Raw

The raw API has reduced coordination overhead, but lacks any transactional abilities.

Best when you mostly do single row changes, and have very limited cross-row (eg. foreign key) requirements. You will not be able to use transactions with this API.

use tikv_client::*;

Connect

Regardless of which API you choose, you’ll need to connect your client (raw, transactional).


// Configure endpoints and optional TLS.
let config = Config::default().with_security("root.ca", "internal.cert", "internal.key");

// Get a transactional client.
let client = TransactionClient::new_with_config(
    vec![
        // A list of PD endpoints.
        "192.168.0.100:2379",
        "192.168.0.101:2379",
    ], config).await.unwrap();

At this point, you should seek the documentation in the related API modules.

Modules

backoff
compat

This module contains utility types and functions for making the transition from futures 0.1 to 1.0 easier.

config
kv
pd
raw

Raw related functionality.

region
request
stats
store
timestamp

A timestamp returned from the timestamp oracle.

transaction

Transactional related functionality.

util

Macros

shardable_keys
shardable_range

Structs

Backoff

When a request is retried, we can backoff for some time to avoid saturating the network.

BoundRange

A struct for expressing ranges. This type is semi-opaque and is not really meant for users to deal with directly. Most functions which operate on ranges will accept any types which implement Into<BoundRange>.

Config

The configuration for either a raw::Client or a transaction::Client.

Key

The key part of a key/value pair.

KvPair

A key/value pair.

RawClient

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

Region

Information about a TiKV region and its leader.

RegionVerId

The ID and version information of a region.

RetryOptions
SecurityManager

Manages the TLS protocol

Snapshot

A read-only transaction which reads at the given timestamp.

Timestamp
Transaction

An undo-able set of actions on the dataset.

TransactionClient

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

TransactionOptions

Options for configuring a transaction.

Enums

CheckLevel
ColumnFamily

A ColumnFamily is an optional parameter for raw::Client requests.

Error

An error originating from the TiKV client or dependencies.

Traits

IntoOwnedRange

A convenience trait for converting ranges of borrowed types into a BoundRange.

TimestampExt

A helper trait to convert a Timestamp to and from an u64.

Functions

new_batch_get_request
new_batch_rollback_request
new_cleanup_request
new_commit_request
new_get_request
new_heart_beat_request
new_pessimistic_lock_request
new_pessimistic_prewrite_request
new_pessimistic_rollback_request
new_prewrite_request
new_raw_batch_delete_request
new_raw_batch_get_request
new_raw_batch_put_request
new_raw_batch_scan_request
new_raw_delete_range_request
new_raw_delete_request
new_raw_get_request
new_raw_put_request
new_raw_scan_request
new_resolve_lock_request
new_scan_lock_request
new_scan_request

Type Definitions

RegionId

The ID of a region

Result

A result holding an Error.

StoreId

The ID of a store

Value

The value part of a key/value pair. An alias for Vec<u8>.