Skills2026年4月15日·1 分钟阅读

TiKV — Distributed Transactional Key-Value Store on Raft

A CNCF-graduated distributed key-value store written in Rust that powers TiDB. Provides horizontal scaling, strong consistency via Raft, geo-replication, and ACID transactions with Percolator-style MVCC.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
TiKV Guide
先审查命令
npx -y tokrepo@latest install 4772853c-3920-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
TiKV is a Rust-based distributed key-value store that provides ACID transactions and strong consistency via the Raft consensus protocol.
§01

What it is

TiKV is a distributed transactional key-value store written in Rust. It is a CNCF-graduated project that powers TiDB (a distributed SQL database). TiKV provides horizontal scaling, strong consistency via the Raft consensus protocol, geo-replication, and ACID transactions with Percolator-style MVCC.

It targets infrastructure teams building distributed systems that need a reliable storage layer with transactional guarantees. TiKV runs as a standalone key-value store or as the storage engine behind TiDB.

§02

How it saves time or tokens

Building a distributed, strongly consistent storage layer from scratch is a multi-year effort. TiKV provides this as a ready-to-deploy component. The Raft consensus protocol handles leader election and data replication automatically, and the Percolator transaction model provides distributed ACID without manual coordination.

TiKV's RawKV API is simple enough for key-value workloads, while the TxnKV API supports multi-key transactions across shards.

§03

How to use

  1. Install TiUP (PingCAP's cluster manager):
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
  1. Start a local TiKV cluster for testing:
tiup playground --mode tikv-slim
  1. Interact with TiKV using the Rust, Go, Java, or Python client:
from tikv_client import RawClient

client = RawClient.connect(['127.0.0.1:2379'])
client.put(b'key1', b'value1')
value = client.get(b'key1')
print(value)  # b'value1'
§04

Example

// Go client example with transactions
package main

import (
    "context"
    "github.com/tikv/client-go/v2/txnkv"
)

func main() {
    client, _ := txnkv.NewClient([]string{"127.0.0.1:2379"})
    txn, _ := client.Begin()

    txn.Set([]byte("account:alice"), []byte("1000"))
    txn.Set([]byte("account:bob"), []byte("500"))

    err := txn.Commit(context.Background())
    // Both writes are atomic -- either both succeed or neither does
}
§05

Related on TokRepo

§06

Common pitfalls

  • TiKV requires PD (Placement Driver) for cluster coordination. Running TiKV without PD is not supported in production.
  • Raft consensus requires an odd number of replicas (3, 5, 7) for proper leader election. A 2-node cluster cannot tolerate any node failure.
  • The Percolator transaction model adds latency compared to single-node databases. Expect 2-5ms per transaction in a well-configured cluster.

常见问题

What is the relationship between TiKV and TiDB?+

TiDB is a distributed SQL database that uses TiKV as its storage engine. TiKV can also run standalone as a pure key-value store without TiDB. They are separate projects maintained by PingCAP.

What consistency model does TiKV use?+

TiKV provides strong consistency via the Raft consensus protocol. Every write is replicated to a majority of nodes before being acknowledged. Reads can be served from the leader for linearizable consistency or from followers for slightly stale reads.

What programming languages have TiKV clients?+

Official clients are available for Rust, Go, Java, and Python. The Go and Rust clients are the most mature. Community clients exist for other languages.

How does TiKV handle horizontal scaling?+

TiKV automatically splits data into regions (default 96MB each). When a region grows too large, it splits. PD balances regions across TiKV nodes to distribute load evenly.

Is TiKV suitable for time-series data?+

TiKV can store time-series data but is not optimized for it. Dedicated time-series databases like InfluxDB or TimescaleDB provide better compression and query performance for time-series workloads.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产