Browse Source

etcdserver: check and select committed entries to apply

Yicheng Qin 11 years ago
parent
commit
dfaa7290c4
1 changed files with 12 additions and 1 deletions
  1. 12 1
      etcdserver/server.go

+ 12 - 1
etcdserver/server.go

@@ -360,7 +360,18 @@ func (s *EtcdServer) run() {
 			// care to apply entries in a single goroutine, and not
 			// care to apply entries in a single goroutine, and not
 			// race them.
 			// race them.
 			if len(rd.CommittedEntries) != 0 {
 			if len(rd.CommittedEntries) != 0 {
-				appliedi = s.apply(rd.CommittedEntries)
+				firsti := rd.CommittedEntries[0].Index
+				if appliedi == 0 {
+					appliedi = firsti - 1
+				}
+				if firsti > appliedi+1 {
+					log.Panicf("etcdserver: first index of committed entry[%d] should <= appliedi[%d] + 1", firsti, appliedi)
+				}
+				var ents []raftpb.Entry
+				if appliedi+1-firsti < uint64(len(rd.CommittedEntries)) {
+					ents = rd.CommittedEntries[appliedi+1-firsti:]
+				}
+				appliedi = s.apply(ents)
 			}
 			}
 
 
 			s.node.Advance()
 			s.node.Advance()