Explorar o código

etcdserver: check and select committed entries to apply

Yicheng Qin %!s(int64=11) %!d(string=hai) anos
pai
achega
dfaa7290c4
Modificáronse 1 ficheiros con 12 adicións e 1 borrados
  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
 			// race them.
 			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()