Search in sources :

Example 11 with RaftPeer

use of org.apache.ratis.protocol.RaftPeer in project alluxio by Alluxio.

the class RaftJournalSystem method addQuorumServer.

/**
 * Adds a server to the quorum.
 *
 * @param serverNetAddress the address of the server
 * @throws IOException if error occurred while performing the operation
 */
public synchronized void addQuorumServer(NetAddress serverNetAddress) throws IOException {
    InetSocketAddress serverAddress = InetSocketAddress.createUnresolved(serverNetAddress.getHost(), serverNetAddress.getRpcPort());
    RaftPeerId peerId = RaftJournalUtils.getPeerId(serverAddress);
    Collection<RaftPeer> peers = mServer.getGroups().iterator().next().getPeers();
    if (peers.stream().anyMatch((peer) -> peer.getId().equals(peerId))) {
        return;
    }
    RaftPeer newPeer = RaftPeer.newBuilder().setId(peerId).setAddress(serverAddress).build();
    List<RaftPeer> newPeers = new ArrayList<>(peers);
    newPeers.add(newPeer);
    RaftClientReply reply = mServer.setConfiguration(new SetConfigurationRequest(mRawClientId, mPeerId, RAFT_GROUP_ID, nextCallId(), newPeers));
    if (reply.getException() != null) {
        throw reply.getException();
    }
}
Also used : RaftClientReply(org.apache.ratis.protocol.RaftClientReply) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftPeer(org.apache.ratis.protocol.RaftPeer) SetConfigurationRequest(org.apache.ratis.protocol.SetConfigurationRequest)

Aggregations

RaftPeer (org.apache.ratis.protocol.RaftPeer)11 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)8 RaftClient (org.apache.ratis.client.RaftClient)7 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)6 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 ArrayList (java.util.ArrayList)4 RaftGroup (org.apache.ratis.protocol.RaftGroup)3 BaseTest (org.apache.ratis.BaseTest)2 MiniRaftCluster (org.apache.ratis.MiniRaftCluster)2 RaftProperties (org.apache.ratis.conf.RaftProperties)2 RaftClientRequest (org.apache.ratis.protocol.RaftClientRequest)2 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)2 Test (org.junit.Test)2 Constants (alluxio.Constants)1 PropertyKey (alluxio.conf.PropertyKey)1 ServerConfiguration (alluxio.conf.ServerConfiguration)1 ExceptionMessage (alluxio.exception.ExceptionMessage)1 CancelledException (alluxio.exception.status.CancelledException)1 UnavailableException (alluxio.exception.status.UnavailableException)1