mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: add log.maybeAppend
This commit is contained in:
parent
b70be19653
commit
bee9d8bea5
@ -19,9 +19,10 @@ func newLog() *log {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *log) maybeAppend(index, logTerm int, ents ...Entry) bool {
|
||||
func (l *log) maybeAppend(index, logTerm, commit int, ents ...Entry) bool {
|
||||
if l.matchTerm(index, logTerm) {
|
||||
l.append(index, ents...)
|
||||
l.commit = commit
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
@ -263,9 +263,7 @@ func (sm *stateMachine) Step(m Message) {
|
||||
}
|
||||
|
||||
handleAppendEntries := func() {
|
||||
if sm.log.matchTerm(m.Index, m.LogTerm) {
|
||||
sm.log.commit = m.Commit
|
||||
sm.log.append(m.Index, m.Entries...)
|
||||
if sm.log.maybeAppend(m.Index, m.LogTerm, m.Commit, m.Entries...) {
|
||||
sm.send(Message{To: m.From, Type: msgAppResp, Index: sm.log.lastIndex()})
|
||||
} else {
|
||||
sm.send(Message{To: m.From, Type: msgAppResp, Index: -1})
|
||||
|
Loading…
x
Reference in New Issue
Block a user