[英]Who initiates Leader Election
Who initiates the leader election in a peer to peer network with no leader?. 谁在没有领导者的对等网络中发起领导者选举? Here is some code that i implemented when receiving messages.
这是我在接收消息时实现的一些代码。
if (message.startsWith(ELECTION)) {
int recievedID = Integer.parseInt(ripMessage(ELECTION, message));
if (processID > recievedID) {
sendToAll(ELECTION + processID);
} else if (processID < recievedID) {
sendToAll(ACKNOWLEDGE);
}
} else if (message.startsWith(ACKNOWLEDGE)) {
ackRecv++;
if (connections.size() == ackRecv) {
connection.sendMessage(LEADER + processID);
this.isLeader = true;
this.leaderID = processID;
ackRecv = 0;
}
} else if (message.startsWith(LEADER)) {
int recievedID = Integer.parseInt(ripMessage(LEADER, message));
this.leaderID = recievedID;
this.isLeader = false;
}
Check out Paxos consensus algorithm . 查看Paxos共识算法 。 The algorithm itself likely overkill for P2P cases... still may be useful as list of issues you need to address.
对于P2P情况,该算法本身可能会造成过大杀伤力。
Super short version - most of participants (quorum) must agree on election message {leader, version} with highest version. 超级简短版本-大多数参与者(法定人数)必须就最高版本的选举消息{leader,version}达成一致。 Multiple rounds may be necessary if multiple elections started at about the same time.
如果大约在同一时间开始多次选举,则可能需要进行多轮投票。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.