# TiKV Server

+ Persistent data
+ Distributed transaction support
+ Strong consistency and high availability of replicas
+ Multi-Version Concurrency Control (MVCC)
+ Coprocessor (expression push down)

```
ID                Role    Host        Ports        OS/Arch       Status   Data Dir               Deploy Dir
--                ----    ----        -----        -------       ------   --------               ----------
...
10.0.0.131:20160  tikv    10.0.0.131  20160/20180  linux/x86_64  Up       /tidb-data/tikv-20160  /tidb-deploy/tikv-20160
...
```

![smart](TiKV_aa_002_20220506.png)

------------------------------------------------------------
The important features of TiKV include the following:

Persistent data
- TiKV chose the RocksDB engine based on the LSM-tree data structure as the data persistence storage engine, while the RocksDB engine uses mechanisms such as write-ahead logging (WAL) to ensure that the data persistence.

Distributed transaction support
- In the 2-phase commit process of the TiDB based on the Percolator transaction model, the lock storage space is allocated separately on each TiKV, called CF Lock (column family), so that a decentralized 2-phase commit is realized in conjunction with the global TSO timing of TiDB server and PD. In addition, TiDB also supports two locking modes: optimistic locking and pessimistic locking, and after TiDB v5.0, the asynchronous commit feature of the second stage of the 2-phase commit is implemented. In the OLTP scenario, the write delay had been greatly reduced.

Strong consistency and high availability of multiple replicas
- The TiKV cluster adopts the Multi-Raft mechanism to achieve strong consistency and high availability of multiple replicas. At the same time, the Regions stored in TiKV are automatically split and merged to achieve dynamic scaling. Finally, PD node can flexibly schedules TiKV Regions, tries best to avoid common issues of distributed databases such as hotspot problems.

`MVCC`
- MVCC (Multiple Version Concurrency Control) is essential for database high concurrent reads and writes requirements. It is the basis for implementing features such as concurrency control, isolation level (SI), distributed transactions, and fast data recover. TiKV MVCC is implemented is by adding a version number after the TiKV Key, and when the historical version data existed a certain period of time, it is cleaned up by the TiDB server for Garbage Collection (GC).

Coprocessor (expression push down)
- The Coprocessor feature enables TiKV to perform data filtering, partial aggregation, etc. on the local node, so that SQL calculation can be pushed down to distributed storage nodes for execution. This mechanism not only reduces network interaction costs, but also makes full use of resources (CPU, cache, and memory), and also makes full use of distributed storage nodes for parallel processing.