From 7e06d856512db398765f339a98b0a85cb38d506b Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Mon, 8 Dec 2014 15:54:52 -0800 Subject: [PATCH] etcdserver: apply entries when it is not empty Or it updates appliedi wrongly. --- etcdserver/server.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/etcdserver/server.go b/etcdserver/server.go index 9269bfbce..46736c7e1 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -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 {