etcdserver: apply entries when it is not empty

Or it updates appliedi wrongly.
This commit is contained in:
Yicheng Qin 2014-12-08 15:54:52 -08:00
parent 6bfa5d409e
commit 7e06d85651

View File

@ -455,8 +455,10 @@ func (s *EtcdServer) run() {
if appliedi+1-firsti < uint64(len(rd.CommittedEntries)) {
ents = rd.CommittedEntries[appliedi+1-firsti:]
}
if appliedi, shouldstop = s.apply(ents); shouldstop {
return
if len(ents) > 0 {
if appliedi, shouldstop = s.apply(ents); shouldstop {
return
}
}
}
@ -693,8 +695,9 @@ func getExpirationTime(r *pb.Request) time.Time {
return t
}
// apply takes an Entry received from Raft (after it has been committed) and
// applies it to the current state of the EtcdServer
// apply takes entries received from Raft (after it has been committed) and
// applies them to the current state of the EtcdServer.
// The given entries should not be empty.
func (s *EtcdServer) apply(es []raftpb.Entry) (uint64, bool) {
var applied uint64
for i := range es {