raft: candidate should become leader directly if it is a one node cluster

release-2.0
Xiang Li 2014-05-28 11:55:07 -07:00 committed by Yicheng Qin
parent 0cdd1b58a4
commit 2066ff5acb
1 changed files with 4 additions and 1 deletions

View File

@ -204,7 +204,6 @@ func (sm *stateMachine) becomeCandidate() {
sm.term++
sm.vote = sm.addr
sm.state = stateCandidate
sm.poll(sm.addr, true)
}
func (sm *stateMachine) becomeLeader() {
@ -228,6 +227,10 @@ func (sm *stateMachine) Step(m Message) {
switch m.Type {
case msgHup:
sm.becomeCandidate()
if sm.q() == sm.poll(sm.addr, true) {
sm.becomeLeader()
return
}
for i := 0; i < sm.k; i++ {
if i == sm.addr {
continue