mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add log.maybeCommit
This commit is contained in:
@@ -65,6 +65,14 @@ func (l *log) matchTerm(i, term int) bool {
|
||||
return l.ents[i].Term == term
|
||||
}
|
||||
|
||||
func (l *log) maybeCommit(maxIndex, term int) bool {
|
||||
if maxIndex > l.commit && l.term(maxIndex) == term {
|
||||
l.commit = maxIndex
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (l *log) nextEnts() (ents []Entry) {
|
||||
if l.commit > l.applied {
|
||||
ents = l.ents[l.applied+1 : l.commit+1]
|
||||
|
||||
@@ -166,12 +166,7 @@ func (sm *stateMachine) maybeCommit() bool {
|
||||
sort.Sort(sort.Reverse(sort.IntSlice(mis)))
|
||||
mci := mis[sm.q()-1]
|
||||
|
||||
if mci > sm.log.commit && sm.log.term(mci) == sm.term {
|
||||
sm.log.commit = mci
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return sm.log.maybeCommit(mci, sm.term)
|
||||
}
|
||||
|
||||
// nextEnts returns the appliable entries and updates the applied index
|
||||
|
||||
Reference in New Issue
Block a user