Browse Source

etcdserver: apply entries when it is not empty

Or it updates appliedi wrongly.
Yicheng Qin 11 years ago
parent
commit
7e06d85651
1 changed files with 7 additions and 4 deletions
  1. 7 4
      etcdserver/server.go

+ 7 - 4
etcdserver/server.go

@@ -455,8 +455,10 @@ func (s *EtcdServer) run() {
 				if appliedi+1-firsti < uint64(len(rd.CommittedEntries)) {
 				if appliedi+1-firsti < uint64(len(rd.CommittedEntries)) {
 					ents = rd.CommittedEntries[appliedi+1-firsti:]
 					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
 	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) {
 func (s *EtcdServer) apply(es []raftpb.Entry) (uint64, bool) {
 	var applied uint64
 	var applied uint64
 	for i := range es {
 	for i := range es {