applyEntries方法的主要作用是接收待应用的 Raft 日志条目,并按顺序将其应用到系统中;确保条目的索引连续,避免丢失或重复应用条目。
一、函数完整代码
func (s *EtcdServer) applyEntries(ep *etcdProgress, apply *apply) {
if len(apply.entries) == 0 {
return
}
firsti := apply.entries[0].Index
if firsti > ep.appliedi+1 {
lg := s.Logger()
lg.Panic(
"unexpected committed entry index",
zap.Uint64("current-applied-index", ep.appliedi),
zap.Uint64("first-committed-entry-index