use of alluxio.grpc.JournalQueryRequest 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.JournalQueryRequest in project alluxio by Alluxio.
the class SnapshotReplicationManagerTest method before.
private void before(int numFollowers) throws Exception {
mLeader = Mockito.mock(RaftJournalSystem.class);
Mockito.when(mLeader.isLeader()).thenReturn(true);
Mockito.when(mLeader.getLocalPeerId()).thenReturn(RaftPeerId.getRaftPeerId("leader"));
mLeaderStore = getSimpleStateMachineStorage();
mLeaderSnapshotManager = Mockito.spy(new SnapshotReplicationManager(mLeader, mLeaderStore));
String serverName = InProcessServerBuilder.generateName();
mServer = InProcessServerBuilder.forName(serverName).directExecutor().addService(new RaftJournalServiceHandler(mLeaderSnapshotManager)).build();
mServer.start();
ManagedChannel channel = InProcessChannelBuilder.forName(serverName).directExecutor().build();
RaftJournalServiceGrpc.RaftJournalServiceStub stub = RaftJournalServiceGrpc.newStub(channel);
// mock RaftJournalServiceClient
mClient = Mockito.mock(RaftJournalServiceClient.class);
Mockito.doNothing().when(mClient).close();
// download rpc mock
Mockito.when(mClient.downloadSnapshot(any())).thenAnswer((args) -> {
StreamObserver responseObserver = args.getArgument(0, StreamObserver.class);
return stub.downloadSnapshot(responseObserver);
});
// upload rpc mock
Mockito.when(mClient.uploadSnapshot(any())).thenAnswer((args) -> {
StreamObserver responseObserver = args.getArgument(0, StreamObserver.class);
return stub.uploadSnapshot(responseObserver);
});
Mockito.doReturn(mClient).when(mLeaderSnapshotManager).getJournalServiceClient();
for (int i = 0; i < numFollowers; i++) {
Follower follower = new Follower(mClient);
mFollowers.put(follower.getRaftPeerId(), follower);
}
List<QuorumServerInfo> quorumServerInfos = mFollowers.values().stream().map(follower -> {
return QuorumServerInfo.newBuilder().setServerAddress(NetAddress.newBuilder().setHost(follower.mHost).setRpcPort(follower.mRpcPort)).build();
}).collect(Collectors.toList());
Mockito.when(mLeader.getQuorumServerInfoList()).thenReturn(quorumServerInfos);
Mockito.when(mLeader.sendMessageAsync(any(), any())).thenAnswer((args) -> {
RaftPeerId peerId = args.getArgument(0, RaftPeerId.class);
Message message = args.getArgument(1, Message.class);
JournalQueryRequest queryRequest = JournalQueryRequest.parseFrom(message.getContent().asReadOnlyByteBuffer());
Message response = mFollowers.get(peerId).mSnapshotManager.handleRequest(queryRequest);
RaftClientReply reply = Mockito.mock(RaftClientReply.class);
Mockito.when(reply.getMessage()).thenReturn(response);
return CompletableFuture.completedFuture(reply);
});
}
Aggregations