Lab3A 实现上层的statemachine
type KVServer struct {
mu sync.Mutex
me int
rf *raft.Raft
applyCh chan raft.ApplyMsg
dead int32 // set by Kill()
GetWaitChan map[int]chan raft.ApplyMsg
AppendPutWaitChan map[int]chan raft.ApplyMsg
LastRequestIndex map[int]int // clerkIndex requestIndex 记录clerk提交情况
maxraftstate int // snapshot if log grows this big
// Your definitions here.
stateMap map[string]string // 状态机 基于log生成
}
关键点
<1>如何保证不重复
我设置了一个map LastRequestIndex 记录每一clerk的最后一条Request的Index
遇到的问题
-
Test speed 太慢了
实现问题,我本来时再ticker里面做apply,拆分出来,用一个gorutine去跑
-
奇怪的重复apply
经过排查,发现ClerkIndex的随机数设置的太小,出现了碰撞
Lab3B with snapshots功能
选择保存的变量
- stateMap
- lastRequestIndex
遇到的问题
死锁问题与并发问题
在我最初的实现中,raft层中Snapshot没有上锁,没有问题,但在实验3中出现了大量的并发问题.
选择上锁后又出现死锁问题,把测试时间调小,等待超时后看gorutine都停在哪里.
分析后,选择在 applyChan<-applyMsg 时 不持有raft的锁
Lab4A The Shard controller
测试非常简单,把之前的代码copy之后改改就好了
最大的问题是没有明白四个操作都在干什么.
-
ShardCtrler有多个config,最新的cofig是最后一个
-
type Config struct { Num int // config number 第几个cofig Shards [