简体   繁体   English

谁发起领导人选举

[英]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;
    }

Normally in a peer-to-peer system, there would be no leader. 通常,在对等系统中,没有领导者。

In such cases leader election does not make sense. 在这种情况下,领导人选举是没有意义的。

There are various peer-to-peer algorithms - for example Chord . 有多种对等算法-例如Chord

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM