【注意】最后更新于 January 11, 2022,文中内容可能已过时,请谨慎使用。
TinyKV 是PingCAP公司推出的一套开源分布式KV存储实战课程:https://github.com/tidb-incubator/tinykv,
宗旨实现一个简易的分布式 kv
这课程一共包含了4子项目:
- Project 1需要参与者独立完成一个单机的KV Server
- Project 2需要基于Raft算法实现分布式键值数据库服务端
- Project 3需要在Project 2的基础上支持多个Raft集群
- Project 4需要Project 3的基础上支持分布式事务
难度都是阶梯式的,等价于麻省理工学院有一套MIT 6.824课程

Leader election
make project2aa
测试case1 TestLeaderElectionInOneRoundRPC2AA
1
2
3
4
5
6
7
8
|
// TestLeaderElectionInOneRoundRPC tests all cases that may happen in
// leader election during one round of RequestVote RPC:
// a) it wins the election
// b) it loses the election
// c) it is unclear about the result
// Reference: section 5.2
MessageType_MsgRequestVoteRespon
|
测试case2 -TestFollowerVote2AA
1
2
3
|
TestFollowerVote tests that each follower will vote for at most one
candidate in a given term, on a first-come-first-served basis.
Reference: section 5.2
|
case3 TestLeaderCycle2AA
1
2
3
4
|
testLeaderCycle verifies that each node in a cluster can campaign
and be elected in turn.
This ensures that elections work when not
starting from a clean slate (as they do in TestLeaderElection)
|
参考
[1] https://github.com/chx2502/tinykv
[2] https://github.com/watchpoints/tinykv
[3] https://zhuanlan.zhihu.com/p/410676282