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