Skip to content

Commit

Permalink
etcdserver: apply() sets consistIndex for any entry type
Browse files Browse the repository at this point in the history
previously, apply() doesn't set consistIndex for EntryConfChange type.
this causes a misalignment between consistIndex and applied index
where EntryConfChange entry results setting applied index but not consistIndex.

suppose that addMember() is called and leader reflects that change.
1. applied index and consistIndex is now misaligned.
2. a new follower node joined.
3. leader sends the snapshot to follower
	where the applied index is the snapshot metadata index.
4. follower node saves the snapshot and database(includes consistIndex) from leader.
5. restarting follower loads snapshot and database.
6. follower checks snapshot metadata index(same as applied index) and database consistIndex,
	finds them don't match, and then panic.

FIXES etcd-io#7834
  • Loading branch information
fanminshi committed May 2, 2017
1 parent fdf445b commit 5ee35f4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,8 @@ func (s *EtcdServer) apply(es []raftpb.Entry, confState *raftpb.ConfState) (appl
atomic.StoreUint64(&s.r.term, e.Term)
appliedt = e.Term
appliedi = e.Index
// set the consistent index of current executing entry
s.consistIndex.setConsistentIndex(appliedi)
}
return appliedt, appliedi, shouldStop
}
Expand All @@ -1292,8 +1294,6 @@ func (s *EtcdServer) apply(es []raftpb.Entry, confState *raftpb.ConfState) (appl
func (s *EtcdServer) applyEntryNormal(e *raftpb.Entry) {
shouldApplyV3 := false
if e.Index > s.consistIndex.ConsistentIndex() {
// set the consistent index of current executing entry
s.consistIndex.setConsistentIndex(e.Index)
shouldApplyV3 = true
}
defer s.setAppliedIndex(e.Index)
Expand Down

0 comments on commit 5ee35f4

Please sign in to comment.