// append to storage so raft starts at the right place in log // 用wal回放 rc.raftStorage.Append(ents)
return w }
1 2 3 4 5 6 7
funcNewMemoryStorage() *MemoryStorage { return &MemoryStorage{ // When starting from scratch populate the list with a dummy entry at term zero. // 在用snap和wal恢复数据前 会初始化一个Storage 在初始化的时候就保证了ents不空 避免了新系统没有历史数据还要判空的场景 ents: make([]pb.Entry, 1), } }