TiKV is an open source distributed Key-Value database which is based on the design of Google Spanner and HBase, but it is much simpler without dependency on any distributed file system. It's has primary features including Geo-Replication, Horizontal scalability, Consistent distributed transactions, Coprocessor support.
Inspired by Google Spanner, PingCAP started developing TiKV in 2015, and released the first version of TiKV along with TiDB in 2016. Up to April 27, 2018, PingCAP has released TiDB/TiKV 2.0, which has a lot new features and great performance gains compared to 1.0.
TiKV support queries such as simple Key-Value, transactional Key-Value and push-down. But no matter it’s transactional Key-Value or push-down, it will be transformed to simple Key-Value operations in TiKV.
Multi-version Concurrency Control (MVCC)
TiKV has a Timestamp Oracle(TSO) to provide globally unique timestamp. The core transaction model of TiKV is called 2-Phase Commit powered by MVCC. There are two stages within each transaction:
- Create a
startTS timestamp. Select one row as the primary row and others as secondary rows.
- Check whether there are locks on this row or whether there are commits after the
startTS. If conflicts exists, the transaction will be rollback. If not, lock the row.
- Repeat the second step on other rows.
- Write to the
CF_WRITE with current timestamp
- Release all the locks.
TiKV uses RocksDB as it underlying storage layer. Data is stored in RocksDB within each TiKV Store.
TiKV is built on top of RocksDB, where all data in a TiKV node shares two RocksDB instances. One is for data, and the other is for Raft log. There are some major components in TiKV: