Compare commits

..

No commits in common. "b8701b4aa7c06086c1e91cd8887bee9f5d487534" and "713e10d22341fa25a4e031d4aa04ca28b1af33ba" have entirely different histories.

1 changed files with 16 additions and 9 deletions

View File

@ -200,7 +200,9 @@ class TinyRaft extends EventEmitter
this.votes[msg.leader] = this.votes[msg.leader] || [];
this.votes[msg.leader].push(from);
const n = this.votes[msg.leader].length;
if (n == 1 + (0 | this.nodes.length/2) && msg.leader == this.nodeId)
if (n == 1 + (0 | this.nodes.length/2))
{
if (msg.leader == this.nodeId)
{
this.leader = msg.leader;
this.state = LEADER;
@ -213,6 +215,11 @@ class TinyRaft extends EventEmitter
}
this.emit('change', { state: this.state, term: this.term, leader: this.nodeId, followers: this.votes[this.nodeId] });
}
else
{
this._nextTerm(0);
}
}
else if (n > this.nodes.length/2 && this.state == LEADER && msg.leader == this.nodeId)
{
this.followers = this.votes[this.nodeId];