mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: use if statement to handle voteResp
This commit is contained in:
parent
b3de2b3450
commit
88674a623a
12
raft/raft.go
12
raft/raft.go
@ -307,18 +307,12 @@ func (sm *stateMachine) Step(m Message) {
|
||||
case msgApp:
|
||||
handleAppendEntries()
|
||||
case msgVote:
|
||||
switch sm.vote {
|
||||
case m.From:
|
||||
sm.send(Message{To: m.From, Type: msgVoteResp, Index: sm.log.lastIndex()})
|
||||
return
|
||||
case none:
|
||||
if sm.log.isUpToDate(m.Index, m.LogTerm) {
|
||||
if (sm.vote == none || sm.vote == m.From) && sm.log.isUpToDate(m.Index, m.LogTerm) {
|
||||
sm.vote = m.From
|
||||
sm.send(Message{To: m.From, Type: msgVoteResp, Index: sm.log.lastIndex()})
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sm.send(Message{To: m.From, Type: msgVoteResp, Index: -1})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user