Search in sources :

Example 1 with AddQuorumServerRequest

use of alluxio.grpc.AddQuorumServerRequest in project alluxio by Alluxio.

the class JournalStateMachine method query.

@Override
public CompletableFuture<Message> query(Message request) {
    CompletableFuture<Message> future = new CompletableFuture<>();
    try {
        JournalQueryRequest queryRequest = JournalQueryRequest.parseFrom(request.getContent().asReadOnlyByteBuffer());
        LOG.debug("Received query request: {}", queryRequest);
        // give snapshot manager a chance to handle snapshot related requests
        Message reply = mSnapshotManager.handleRequest(queryRequest);
        if (reply != null) {
            future.complete(reply);
            return future;
        }
        // other type of requests.
        if (queryRequest.hasAddQuorumServerRequest()) {
            AddQuorumServerRequest addRequest = queryRequest.getAddQuorumServerRequest();
            return CompletableFuture.supplyAsync(() -> {
                try {
                    mJournalSystem.addQuorumServer(addRequest.getServerAddress());
                } catch (IOException e) {
                    throw new CompletionException(e);
                }
                return Message.EMPTY;
            });
        }
    } catch (Exception e) {
        LOG.error("failed processing request {}", request, e);
        future.completeExceptionally(e);
        return future;
    }
    return super.query(request);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Message(org.apache.ratis.protocol.Message) CompletionException(java.util.concurrent.CompletionException) AddQuorumServerRequest(alluxio.grpc.AddQuorumServerRequest) JournalQueryRequest(alluxio.grpc.JournalQueryRequest) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) FileNotFoundException(java.io.FileNotFoundException) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException)

Example 2 with AddQuorumServerRequest

use of alluxio.grpc.AddQuorumServerRequest in project alluxio by Alluxio.

the class RaftJournalSystem method joinQuorum.

private void joinQuorum() {
    InetSocketAddress localAddress = mConf.getLocalAddress();
    // Send a request to join the quorum.
    // If the server is already part of the quorum, this operation is a noop.
    AddQuorumServerRequest request = AddQuorumServerRequest.newBuilder().setServerAddress(NetAddress.newBuilder().setHost(localAddress.getHostString()).setRpcPort(localAddress.getPort())).build();
    RaftClient client = createClient();
    client.async().sendReadOnly(Message.valueOf(UnsafeByteOperations.unsafeWrap(JournalQueryRequest.newBuilder().setAddQuorumServerRequest(request).build().toByteArray()))).whenComplete((reply, t) -> {
        if (t != null) {
            LogUtils.warnWithException(LOG, "Exception occurred while joining quorum", t);
        }
        if (reply != null && reply.getException() != null) {
            LogUtils.warnWithException(LOG, "Received an error while joining quorum", reply.getException());
        }
        try {
            client.close();
        } catch (IOException e) {
            LogUtils.warnWithException(LOG, "Exception occurred closing raft client", e);
        }
    });
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AddQuorumServerRequest(alluxio.grpc.AddQuorumServerRequest) IOException(java.io.IOException) RaftClient(org.apache.ratis.client.RaftClient)

Aggregations

AddQuorumServerRequest (alluxio.grpc.AddQuorumServerRequest)2 IOException (java.io.IOException)2 UnavailableException (alluxio.exception.status.UnavailableException)1 JournalQueryRequest (alluxio.grpc.JournalQueryRequest)1 FileNotFoundException (java.io.FileNotFoundException)1 InetSocketAddress (java.net.InetSocketAddress)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 RaftClient (org.apache.ratis.client.RaftClient)1 Message (org.apache.ratis.protocol.Message)1