A learning implementation of a distributed key-value storage system based on the TinyKV Course
This project is an implementation of the TinyKV course, which builds a key-value storage system with the Raft consensus algorithm. The course is inspired by MIT 6.824 and the TiKV Project.
TinyKV helps you understand how to implement a horizontally scalable, highly available, key-value storage service with distributed transaction support, along with a deeper understanding of TiKV architecture and implementation.
-
Project 1: Standalone KV - ✅ Completed
- Standalone storage engine implementation
- Raw key-value service handlers
-
Project 2: Raft KV - 🚧 In Progress
- Basic Raft algorithm
- Fault-tolerant KV server on top of Raft
- Raft log garbage collection and snapshot support
-
Project 3: Multi-raft KV - 📋 Planned
- Membership change and leadership change
- Conf change and region split on Raft store
- Basic scheduler implementation
-
Project 4: Transaction - 📋 Planned
- Multi-version concurrency control (MVCC) layer
- Transaction handlers implementation
The project consists of four main stages, each building upon the previous one:
Documentation | ✅ Completed
- Implement a standalone storage engine
- Implement raw key-value service handlers
Documentation | 🚧 In Progress
- Implement the basic Raft algorithm
- Build a fault-tolerant KV server on top of Raft
- Add support for Raft log garbage collection and snapshot
Documentation | 📋 Planned
- Implement membership change and leadership change in Raft
- Implement conf change and region split on Raft store
- Implement a basic scheduler
Documentation | 📋 Planned
- Implement the multi-version concurrency control (MVCC) layer
- Implement handlers for
KvGet,KvPrewrite, andKvCommitrequests - Implement handlers for
KvScan,KvCheckTxnStatus,KvBatchRollback, andKvResolveLockrequests
Similar to the architecture of TiDB + TiKV + PD that separates storage and computation, TinyKV focuses on the storage layer of a distributed database system. If you're interested in the SQL layer, check out TinySQL. TinyScheduler acts as the central control of the TinyKV cluster, collecting information from heartbeats and generating scheduling tasks. All instances communicate via gRPC.
├── kv/ # Key-value store implementation
│ ├── server/ # gRPC server and service handlers
│ ├── storage/ # Storage interface and implementations
│ ├── raftstore/ # Raft-based storage engine
│ ├── transaction/ # Transaction layer (MVCC)
│ └── coprocessor/ # Coprocessor for data processing
├── raft/ # Raft consensus algorithm implementation
├── scheduler/ # TinyScheduler for cluster management
│ ├── server/ # Scheduler server and coordinator
│ └── client/ # Scheduler client
├── proto/ # Protocol Buffers definitions
└── log/ # Logging utilities
- Git: Install Git
- Go: Version ≥ 1.13 (Installation Guide)
Build TinyKV from source:
cd go-distributed-system
makeThis builds the tinykv-server and tinyscheduler-server binaries in the bin/ directory.
Run the standalone server:
make
./bin/tinykv-serverRun tests for specific components:
# Test standalone storage
make project1
# Test Raft implementation
make project2
# Test Multi-Raft
make project3
# Test transactions
make project4You can run TinyKV with TinySQL to get a complete distributed database experience:
- Get
tinysql-serverfollowing TinySQL documentation - Place
tinyscheduler-server,tinykv-server, andtinysql-serverbinaries in the same directory - Run the following commands:
mkdir -p data
./tinyscheduler-server
./tinykv-server -path=data
./tinysql-server --store=tikv --path="127.0.0.1:2379"- Connect with MySQL client:
mysql -u root -h 127.0.0.1 -P 4000Check out the reading list for resources on distributed storage systems.
- TiKV Design: Data storage architecture
- PD Design: Scheduling system
- Raft Paper: The Raft Consensus Algorithm
- Raft Visualization: Interactive Raft
This project is based on the TinyKV Course by PingCAP, part of the Talent Plan educational initiative.
See LICENSE file for details.
