# Lab2 Raft
## Lab Part 2A
Implement leader election and heartbeats (AppendEntries RPCs with no log entries). The goal for Part 2A is for a single leader to be elected, for
the leader to remain the leader if there are no failures, and for a new leader to take over if the old leader fails or if packets to/from the old leader
are lost. Run go test -run 2A to test your 2A code.
- raft.go
1. Init state is Follower
2. Three goroutines: checkHealthy & election & heartDaemon
3. checkHealthy is for Follower state, it checks whether leader is active
4. If leader inactive, then switch to Candidate, start election goroutine
5. RequestVotes in election routine.
6. Handle RequestVotes: if Candidate, switchToFollower; if Follower, check if
had voted or same term; if Leader, check if stale leader.
7. heartbeat routine: send heartbeat periodly, if recv bigger term, switchToFollower.
## Lab Part 2B
Implement the leader and follower code to append new log entries. This will involve implementing Start(), completing the AppendEntries RPC
structs, sending them, fleshing out the AppendEntry RPC handler, and advancing the commitIndex at the leader. Your first goal should be to pass the
TestBasicAgree() test (in test_test.go). Once you have that working, you should get all the 2B tests to pass (go test -run 2B).
- raft.go
1. If recv AppendEntries with multiple new Entries, say 3 entries, and PrevLogIndex is 10, what if rf.log[PrevLogIndex + 0].Term == Entries[0].Term,
But rf.log[PrevLogIndex + 1].Term != Entries[1].Term, is it possible?
2. A call to Start() at the leader starts the process of adding a new operation to the log; the leader sends the new operation to the other servers in AppendEntries RPCs.
sends on the applyCh in a goroutine.
3. Pay attention that log index is 1-based in thesis.
目前2C的unreliable figure 8测试,约有1%的几率超时
通过比对正常日志和超时日志,正常日志中,投票被拒绝的记录约67个,异常日志中,该记录有160个:
[me 0] RequestVoteReply from 2, term 123, grant false, votes 2
上面是异常的最后一条记录,term达到了123;而正常记录中,最大term只有80;
基本可以断定是没有pre-vote机制导致的,有空加上测试。目前平均100-200次失败一次
理论上pre vote之后,失败率可以降为0
但有个疑点是,并没有"bigger heartbeat reply term",也就是leader发送心跳,却收到失败回复,因为有更大的term在follower中。
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
分布式系统课程实验-内含源码和说明书.zip (69个子文件)
.DS_Store 6KB
Makefile 2KB
src
shardkv
test_test.go 18KB
common.go 1KB
config.go 9KB
server.go 11KB
client.go 5KB
mapreduce
lab1 22KB
test_test.go 5KB
schedule.go 2KB
master_rpc.go 2KB
common.go 1KB
common_rpc.go 2KB
master.go 5KB
worker.go 4KB
common_map.go 3KB
common_reduce.go 3KB
master_splitmerge.go 1KB
shardmaster
test_test.go 8KB
common.go 2KB
config.go 8KB
server.go 12KB
client.go 5KB
linearizability
models.go 1KB
model.go 1KB
bitset.go 1KB
linearizability.go 6KB
labgob
test_test.go 3KB
labgob.go 4KB
labrpc
test_test.go 10KB
labrpc.go 13KB
raft
test_test.go 19KB
util.go 234B
raft.go 43KB
agreement-despite-follower-disconnection.log 21KB
config.go 12KB
persister.go 1KB
lab2 11KB
README.md 2KB
kvraft
snapshot_hints 6KB
test_test.go 20KB
common.go 896B
config.go 10KB
server.go 9KB
lab3 9KB
client.go 4KB
faq 26KB
main
pg-huckleberry_finn.txt 580KB
pg-tom_sawyer.txt 403KB
pg-sherlock_holmes.txt 568KB
test-mr.sh 491B
mr-challenge.txt 2KB
test-ii.sh 468B
pg-being_ernest.txt 136KB
lockd.go 657B
viewd.go 283B
diskvd.go 2KB
mr-testout.txt 99B
pg-frankenstein.txt 431KB
pbc.go 875B
pbd.go 300B
ii.go 2KB
wc.go 2KB
pg-grimm.txt 528KB
test-wc.sh 326B
pg-metamorphosis.txt 136KB
pg-dorian_gray.txt 443KB
lockc.go 500B
README.md 633B
共 69 条
- 1
资源评论
小码蚁.
- 粉丝: 2532
- 资源: 4146
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功