TiKV

tikv_logo

TiKV is an open-source, distributed, and transactional key-value database. Unlike traditional NoSQL systems, TiKV provides both classical key-value APIs and transactional APIs with ACID compliance. Built in Rust and powered by Raft, TiKV was originally created by PingCAP to complement TiDB, a distributed HTAP database compatible with the MySQL protocol.

TiKV draws inspiration from several great distributed systems from Google, such as BigTable, Spanner, and Percolator, along with the latest advancements in academia like the Raft consensus algorithm.

Key Features

  • Geo-Replication: TiKV uses Raft and the Placement Driver to support geo-replication.
  • Horizontal Scalability: With PD and well-designed Raft groups, TiKV excels in horizontal scalability, easily scaling to 100+ TBs of data.
  • Consistent Distributed Transactions: Similar to Google's Spanner, TiKV supports externally consistent distributed transactions.
  • Coprocessor Support: Similar to HBase, TiKV implements a coprocessor framework for distributed computing.
  • Integration with TiDB: TiKV and TiDB work together seamlessly to provide a highly scalable database solution with ACID transactions, support for RDBMS, and NoSQL design patterns.

Architecture

TiKV's architecture ensures data consistency and automatic data migration using the following components:

  • Placement Driver (PD): Acts as the cluster manager, periodically checking replication constraints to balance load and data automatically.
  • Store: Uses RocksDB to store data on the local disk.
  • Region: The basic unit of key-value data movement, each Region is replicated to multiple nodes, forming a Raft group.
  • Node: A physical node in the cluster, hosting one or more Stores and many Regions.

Quick Start

Deploy a Playground with TiUP

The quickest way to try out TiKV with TiDB is by using TiUP, a component manager for TiDB. Refer to the step-by-step tutorial.

Deploy a Playground with Binary

TiKV can run separately with PD, which is the minimal deployment required.

  1. Download and extract binaries:
export TIKV_VERSION=v7.5.0
export GOOS=darwin  # only {darwin, linux} are supported
export GOARCH=amd64 # only {amd64, arm64} are supported
curl -O  https://tiup-mirrors.pingcap.com/tikv-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
curl -O  https://tiup-mirrors.pingcap.com/pd-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
tar -xzf tikv-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
tar -xzf pd-$TIKV_VERSION-$GOOS-$GOARCH.tar.gz
  1. Start PD instance:
./pd-server --name=pd --data-dir=/tmp/pd/data --client-urls="http://127.0.0.1:2379" --peer-urls="http://127.0.0.1:2380" --initial-cluster="pd=http://127.0.0.1:2380" --log-file=/tmp/pd/log/pd.log
  1. Start TiKV instance:
./tikv-server --pd-endpoints="127.0.0.1:2379" --addr="127.0.0.1:20160" --data-dir=/tmp/tikv/data --log-file=/tmp/tikv/log/tikv.log
  1. Install TiKV Client (Python) and verify the deployment (requires Python 3.5+):
pip3 install -i https://test.pypi.org/simple/ tikv-client
from tikv_client import RawClient
 
client = RawClient.connect("127.0.0.1:2379")
 
client.put(b'foo', b'bar')
print(client.get(b'foo')) # b'bar'
 
client.put(b'foo', b'baz')
print(client.get(b'foo')) # b'baz'

Documentation

For instructions on deployment, configuration, and maintenance of TiKV, see the TiKV documentation. For a deeper understanding of the concepts and designs behind TiKV, visit Deep Dive TiKV.

Governance

See the Governance document for details.

TiKV Adopters

View the list of TiKV Adopters.

Client Drivers

Security

Security Audit

A third-party security audit was performed by Cure53. See the full report here.

Reporting Security Vulnerabilities

To report a security vulnerability, email the TiKV-security group.

See Security for the process and policy.

Similar Projects