commit
79745783e9
@ -120,17 +120,22 @@ public class PeerSet {
|
|||||||
peers.put(candidate.ip, candidate);
|
peers.put(candidate.ip, candidate);
|
||||||
|
|
||||||
SortedBag ips = new TreeBag();
|
SortedBag ips = new TreeBag();
|
||||||
|
int maxApproveCount = 0;
|
||||||
|
String maxApprovePeer = null;
|
||||||
for (RaftPeer peer : peers.values()) {
|
for (RaftPeer peer : peers.values()) {
|
||||||
if (StringUtils.isEmpty(peer.voteFor)) {
|
if (StringUtils.isEmpty(peer.voteFor)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ips.add(peer.voteFor);
|
ips.add(peer.voteFor);
|
||||||
|
if (ips.getCount(peer.voteFor) > maxApproveCount) {
|
||||||
|
maxApproveCount = ips.getCount(peer.voteFor);
|
||||||
|
maxApprovePeer = peer.voteFor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String first = (String) ips.last();
|
if (maxApproveCount >= majorityCount()) {
|
||||||
if (ips.getCount(first) >= majorityCount()) {
|
RaftPeer peer = peers.get(maxApprovePeer);
|
||||||
RaftPeer peer = peers.get(first);
|
|
||||||
peer.state = RaftPeer.State.LEADER;
|
peer.state = RaftPeer.State.LEADER;
|
||||||
|
|
||||||
if (!Objects.equals(leader, peer)) {
|
if (!Objects.equals(leader, peer)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user