use of alluxio.grpc.JournalQueryResponse in project alluxio by Alluxio.
the class SnapshotReplicationManager method requestInfo.
private void requestInfo() {
Preconditions.checkState(mDownloadState.get() == DownloadState.REQUEST_INFO);
try {
SingleFileSnapshotInfo latestSnapshot = mStorage.getLatestSnapshot();
SnapshotMetadata snapshotMetadata = latestSnapshot == null ? null : SnapshotMetadata.newBuilder().setSnapshotTerm(latestSnapshot.getTerm()).setSnapshotIndex(latestSnapshot.getIndex()).build();
// build SnapshotInfoRequests
Map<RaftPeerId, CompletableFuture<RaftClientReply>> jobs = mJournalSystem.getQuorumServerInfoList().stream().filter(server -> server.getServerState() == QuorumServerState.AVAILABLE).map(server -> RaftJournalUtils.getPeerId(server.getServerAddress().getHost(), server.getServerAddress().getRpcPort())).filter(peerId -> !peerId.equals(mJournalSystem.getLocalPeerId())).collect(Collectors.toMap(Function.identity(), peerId -> mJournalSystem.sendMessageAsync(peerId, toMessage(JournalQueryRequest.newBuilder().setSnapshotInfoRequest(GetSnapshotInfoRequest.getDefaultInstance()).build()))));
// query all secondary masters for information about their latest snapshot
for (Map.Entry<RaftPeerId, CompletableFuture<RaftClientReply>> job : jobs.entrySet()) {
RaftPeerId peerId = job.getKey();
try {
RaftClientReply reply = job.getValue().get();
if (reply.getException() != null) {
throw reply.getException();
}
JournalQueryResponse response = JournalQueryResponse.parseFrom(reply.getMessage().getContent().asReadOnlyByteBuffer());
if (!response.hasSnapshotInfoResponse()) {
throw new IOException("Invalid response for GetSnapshotInfoRequest " + response);
}
LOG.debug("Received snapshot info from follower {} - {}", peerId, response);
SnapshotMetadata latest = response.getSnapshotInfoResponse().getLatest();
if (snapshotMetadata == null || (latest.getSnapshotTerm() >= snapshotMetadata.getSnapshotTerm()) && latest.getSnapshotIndex() > snapshotMetadata.getSnapshotIndex()) {
mSnapshotCandidates.add(new Pair<>(latest, peerId));
}
} catch (Exception e) {
LOG.warn("Error while requesting snapshot info from {}: {}", peerId, e.toString());
}
}
} catch (Exception e) {
LogUtils.warnWithException(LOG, "Failed to request snapshot info from followers", e);
}
}
use of alluxio.grpc.JournalQueryResponse in project alluxio by Alluxio.
the class SnapshotReplicationManager method handleRequest.
/**
* Handles snapshot requests.
*
* @param queryRequest the query request
* @return the response message, or null if the request is not handled
* @throws IOException if any error occurred while handling the request
*/
public Message handleRequest(JournalQueryRequest queryRequest) throws IOException {
if (queryRequest.hasSnapshotInfoRequest()) {
SnapshotInfo latestSnapshot = mStorage.getLatestSnapshot();
if (latestSnapshot == null) {
LOG.debug("No snapshot to send");
return toMessage(GetSnapshotInfoResponse.getDefaultInstance());
}
JournalQueryResponse response = JournalQueryResponse.newBuilder().setSnapshotInfoResponse(GetSnapshotInfoResponse.newBuilder().setLatest(toSnapshotMetadata(latestSnapshot.getTermIndex()))).build();
LOG.debug("Sent snapshot info response {}", response);
return toMessage(response);
}
if (queryRequest.hasSnapshotRequest()) {
LOG.debug("Start sending snapshot to leader");
sendSnapshotToLeader();
return Message.EMPTY;
}
return null;
}
Aggregations