rafthttp: fix panic on receiving empty ents

2.0 rc may send empty ents. Fix it for backward compatibility.
release-2.0
Yicheng Qin 2015-02-20 14:58:51 -08:00
parent 0ea2173a7e
commit ca390560f9
2 changed files with 6 additions and 1 deletions

View File

@ -54,7 +54,9 @@ func (er *entryReader) readEntries() ([]raftpb.Entry, error) {
}
er.ents.Add()
}
er.lastIndex.Set(int64(ents[l-1].Index))
if l > 0 {
er.lastIndex.Set(int64(ents[l-1].Index))
}
return ents, nil
}

View File

@ -295,6 +295,9 @@ func (s *streamReader) handle(r io.Reader) {
}
return
}
if len(ents) == 0 {
continue
}
// The commit index field in appendEntry message is not recovered.
// The follower updates its commit index through heartbeat.
msg := raftpb.Message{