mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Incorporating review comments
Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
@@ -147,9 +147,6 @@ type raft struct {
|
|||||||
c *client
|
c *client
|
||||||
dflag bool
|
dflag bool
|
||||||
|
|
||||||
// last term this node was leader
|
|
||||||
llterm uint64
|
|
||||||
|
|
||||||
// Subjects for votes, updates, replays.
|
// Subjects for votes, updates, replays.
|
||||||
psubj string
|
psubj string
|
||||||
rpsubj string
|
rpsubj string
|
||||||
@@ -2051,7 +2048,6 @@ func (n *raft) runAsCandidate() {
|
|||||||
for len(n.votes) > 0 {
|
for len(n.votes) > 0 {
|
||||||
<-n.votes
|
<-n.votes
|
||||||
}
|
}
|
||||||
lastTermAsLeader := n.llterm
|
|
||||||
n.Unlock()
|
n.Unlock()
|
||||||
|
|
||||||
// Send out our request for votes.
|
// Send out our request for votes.
|
||||||
@@ -2084,7 +2080,6 @@ func (n *raft) runAsCandidate() {
|
|||||||
case <-tikChan:
|
case <-tikChan:
|
||||||
// disable timeout and receipt of more votes
|
// disable timeout and receipt of more votes
|
||||||
voteChan = nil
|
voteChan = nil
|
||||||
tikChan = nil
|
|
||||||
if won {
|
if won {
|
||||||
// we are here if we won the election but some server did not respond
|
// we are here if we won the election but some server did not respond
|
||||||
n.switchToLeader()
|
n.switchToLeader()
|
||||||
@@ -2098,9 +2093,8 @@ func (n *raft) runAsCandidate() {
|
|||||||
votes++
|
votes++
|
||||||
if n.wonElection(votes) {
|
if n.wonElection(votes) {
|
||||||
// This would be ok as we'd be guaranteed to have the latest history.
|
// This would be ok as we'd be guaranteed to have the latest history.
|
||||||
if len(n.peers) == votes || lastTermAsLeader+1 == n.term {
|
if len(n.peers) == votes {
|
||||||
// Become LEADER if we have won and gotten a quorum with everyone or if we have been leader
|
// Become LEADER if we have won and gotten a quorum with everyone
|
||||||
// in the previous round and thus already waited
|
|
||||||
n.switchToLeader()
|
n.switchToLeader()
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@@ -3072,6 +3066,5 @@ func (n *raft) switchToLeader() {
|
|||||||
}
|
}
|
||||||
n.debug("Switching to leader")
|
n.debug("Switching to leader")
|
||||||
n.leader = n.id
|
n.leader = n.id
|
||||||
n.llterm = n.term
|
|
||||||
n.switchState(Leader)
|
n.switchState(Leader)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user