Search in sources :

Example 1 with SetConfigurationRequest

use of org.apache.ratis.protocol.SetConfigurationRequest in project incubator-ratis by apache.

the class GrpcAdminProtocolService method setConfiguration.

@Override
public void setConfiguration(SetConfigurationRequestProto proto, StreamObserver<RaftClientReplyProto> responseObserver) {
    final SetConfigurationRequest request = ClientProtoUtils.toSetConfigurationRequest(proto);
    GrpcUtil.asyncCall(responseObserver, () -> protocol.setConfigurationAsync(request), ClientProtoUtils::toRaftClientReplyProto);
}
Also used : ClientProtoUtils(org.apache.ratis.client.impl.ClientProtoUtils) SetConfigurationRequest(org.apache.ratis.protocol.SetConfigurationRequest)

Example 2 with SetConfigurationRequest

use of org.apache.ratis.protocol.SetConfigurationRequest in project incubator-ratis by apache.

the class AdminImpl method setConfiguration.

@Override
public RaftClientReply setConfiguration(List<RaftPeer> peersInNewConf, List<RaftPeer> listenersInNewConf) throws IOException {
    Objects.requireNonNull(peersInNewConf, "peersInNewConf == null");
    final long callId = CallId.getAndIncrement();
    // also refresh the rpc proxies for these peers
    client.getClientRpc().addRaftPeers(peersInNewConf);
    return client.io().sendRequestWithRetry(() -> new SetConfigurationRequest(client.getId(), client.getLeaderId(), client.getGroupId(), callId, peersInNewConf, listenersInNewConf));
}
Also used : SetConfigurationRequest(org.apache.ratis.protocol.SetConfigurationRequest)

Example 3 with SetConfigurationRequest

use of org.apache.ratis.protocol.SetConfigurationRequest in project incubator-ratis by apache.

the class RaftReconfigurationBaseTest method runTestReconfTimeout.

void runTestReconfTimeout(CLUSTER cluster) throws Exception {
    final RaftPeerId leaderId = RaftTestUtil.waitForLeader(cluster).getId();
    try (final RaftClient client = cluster.createClient(leaderId)) {
        PeerChanges c1 = cluster.addNewPeers(2, false);
        LOG.info("Start changing the configuration: {}", asList(c1.allPeersInNewConf));
        Assert.assertFalse(((RaftConfigurationImpl) cluster.getLeader().getRaftConf()).isTransitional());
        final RaftClientRpc sender = client.getClientRpc();
        final SetConfigurationRequest request = cluster.newSetConfigurationRequest(client.getId(), leaderId, c1.allPeersInNewConf);
        try {
            sender.sendRequest(request);
            Assert.fail("did not get expected exception");
        } catch (IOException e) {
            Assert.assertTrue("Got exception " + e, e instanceof ReconfigurationTimeoutException);
        }
        // the two new peers have not started yet, the bootstrapping must timeout
        LOG.info(cluster.printServers());
        // state so that we still get timeout instead of in-progress exception
        try {
            sender.sendRequest(request);
            Assert.fail("did not get expected exception");
        } catch (IOException e) {
            Assert.assertTrue("Got exception " + e, e instanceof ReconfigurationTimeoutException);
        }
        // start the two new peers
        LOG.info("Start new peers");
        for (RaftPeer np : c1.newPeers) {
            cluster.restartServer(np.getId(), false);
        }
        Assert.assertTrue(client.admin().setConfiguration(c1.allPeersInNewConf).isSuccess());
    }
}
Also used : ReconfigurationTimeoutException(org.apache.ratis.protocol.exceptions.ReconfigurationTimeoutException) PeerChanges(org.apache.ratis.server.impl.MiniRaftCluster.PeerChanges) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) IOException(java.io.IOException) RaftPeer(org.apache.ratis.protocol.RaftPeer) SetConfigurationRequest(org.apache.ratis.protocol.SetConfigurationRequest) RaftClient(org.apache.ratis.client.RaftClient) RaftClientRpc(org.apache.ratis.client.RaftClientRpc)

Example 4 with SetConfigurationRequest

use of org.apache.ratis.protocol.SetConfigurationRequest 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

SetConfigurationRequest (org.apache.ratis.protocol.SetConfigurationRequest)4 RaftPeer (org.apache.ratis.protocol.RaftPeer)2 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 RaftClient (org.apache.ratis.client.RaftClient)1 RaftClientRpc (org.apache.ratis.client.RaftClientRpc)1 ClientProtoUtils (org.apache.ratis.client.impl.ClientProtoUtils)1 RaftClientReply (org.apache.ratis.protocol.RaftClientReply)1 ReconfigurationTimeoutException (org.apache.ratis.protocol.exceptions.ReconfigurationTimeoutException)1 PeerChanges (org.apache.ratis.server.impl.MiniRaftCluster.PeerChanges)1