做公司 网站建设,公司网站建站软件,wordpress 行间距插件,做网站的开发软件目录2c简介2b、2a问题测试时间2c简介
简单的说#xff0c;raft需要将currentTerm、voteFor、entries(当前的所有日志)保存到硬盘进行持久化存储。
保存的方法#xff1a;在变量改变时#xff0c;利用persist()中的gob将变量序列化#xff0c;存储在persister结构体中。raft需要将currentTerm、voteFor、entries(当前的所有日志)保存到硬盘进行持久化存储。
保存的方法在变量改变时利用persist()中的gob将变量序列化存储在persister结构体中。实验不需要真正保存在硬盘上用persister结构体代替。
读取的方法在服务器重启时利用readPersist()读取保存的序列化参数并解码成对应变量输入raft中。
test 2c 报错的主要原因是2b、2a的问题总结下通过c找出的问题。
2b、2a问题
1.在leader更新follower服务器的日志时如果更新成功则修改nextIndex[server]、matchIndex[server]。 修改matchIndex时
rf.nextIndex[i] len(rf.entries) //?即使错了还能回滚
rf.matchIndex[i] len(rf.entries) - 1 //错误
rf.matchIndex[i] rf.nextIndex[i] - 1 //错误
rf.matchIndex[i] args.PrevLogIndex len(args.Entries)有可能在appendEntries()后客户往raft中加入了若干command导致日志长度发生变化。计算matchIndex时使用了错误的日志长度会导致以下提交错误。
2.leader更新follower日志成功时commitIndex应该为大多数比当前commitIndex大的matchIndex中最小的一个而不是每次提交成功后commitIndex 如果存在N commitIndex(本地待提交日志的索引)majority(matchIndex[i]N)(如果参与者大多数的最新日志的索引大于N)并且这些参与者索引为N的日志的任期也等于leader的当前任期:commitIndex N(leader的待提交的日志索引设置为N)(5.2和5.4节)。 简单的说commitIndex应该为matchIndex[]排序后的中位数前提是这个中位数大于当前commitIndex。 一个简单的On算法 //更新commitIndexres : 0minBiggerMatchIndex : 99999999 //比commitIdx大的最小值for i : 0; i len(rf.matchIndex); i {if rf.matchIndex[i] rf.commitIndex {resminBiggerMatchIndex int(math.Min(float64(rf.matchIndex[i]), float64(minBiggerMatchIndex)))}}//TODO 每次RPC只加1太慢了if res len(rf.peers)/2 {rf.commitIndex minBiggerMatchIndex}3.提交时先对entries进行深拷贝可以避免数据竞争。
entriesToApply : append([]Log{}, rf.entries[(rf.lastApplied1):(rf.commitIndex1)]...)测试时间
最后贴个lab2c测试时间
Test (2C): basic persistence ...... Passed -- 3.9 3 76 21621 6
Test (2C): more persistence ... ... Passed -- 17.2 5 928 218116 16
Test (2C): partitioned leader and one follower crash, leader restarts ...... Passed -- 2.1 3 40 11352 4
Test (2C): Figure 8 ...... Passed -- 41.9 5 1369 312992 59
Test (2C): unreliable agreement ...... Passed -- 3.1 5 332 131912 246
Test (2C): Figure 8 (unreliable) ...... Passed -- 38.0 5 11171 21985710 193
Test (2C): churn ...... Passed -- 16.3 5 1596 1588205 667
Test (2C): unreliable churn ...... Passed -- 16.3 5 1800 1136899 419
PASS
ok 6.5840/raft 139.113s