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();
}
}
Aggregations