Search in sources :

Example 1 with JournalQueryResponse

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);
    }
}
Also used : TermIndex(org.apache.ratis.server.protocol.TermIndex) PriorityQueue(java.util.PriorityQueue) LoggerFactory(org.slf4j.LoggerFactory) LogUtils(alluxio.util.LogUtils) GetSnapshotInfoResponse(alluxio.grpc.GetSnapshotInfoResponse) StreamObserver(io.grpc.stub.StreamObserver) JournalQueryRequest(alluxio.grpc.JournalQueryRequest) MetricKey(alluxio.metrics.MetricKey) Map(java.util.Map) Status(io.grpc.Status) ClientContext(alluxio.ClientContext) SnapshotInfo(org.apache.ratis.statemachine.SnapshotInfo) SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) UnsafeByteOperations(org.apache.ratis.thirdparty.com.google.protobuf.UnsafeByteOperations) ServerConfiguration(alluxio.conf.ServerConfiguration) JournalQueryResponse(alluxio.grpc.JournalQueryResponse) CompletionException(java.util.concurrent.CompletionException) SimpleStateMachineStorage(org.apache.ratis.statemachine.impl.SimpleStateMachineStorage) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) Timer(com.codahale.metrics.Timer) FileInfo(org.apache.ratis.server.storage.FileInfo) SnapshotData(alluxio.grpc.SnapshotData) MD5FileUtil(org.apache.ratis.util.MD5FileUtil) GetSnapshotInfoRequest(alluxio.grpc.GetSnapshotInfoRequest) UploadSnapshotPResponse(alluxio.grpc.UploadSnapshotPResponse) RaftLog(org.apache.ratis.server.raftlog.RaftLog) DownloadSnapshotPRequest(alluxio.grpc.DownloadSnapshotPRequest) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Message(org.apache.ratis.protocol.Message) GetSnapshotRequest(alluxio.grpc.GetSnapshotRequest) QuorumServerState(alluxio.grpc.QuorumServerState) SnapshotMetadata(alluxio.grpc.SnapshotMetadata) ClientIpAddressInjector(alluxio.security.authentication.ClientIpAddressInjector) AbortedException(alluxio.exception.status.AbortedException) MetricsSystem(alluxio.metrics.MetricsSystem) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) DownloadSnapshotPResponse(alluxio.grpc.DownloadSnapshotPResponse) Logger(org.slf4j.Logger) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) IOException(java.io.IOException) Pair(alluxio.collections.Pair) NotFoundException(alluxio.exception.status.NotFoundException) File(java.io.File) MessageLite(com.google.protobuf.MessageLite) UploadSnapshotPRequest(alluxio.grpc.UploadSnapshotPRequest) MasterClientContext(alluxio.master.MasterClientContext) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) JournalQueryResponse(alluxio.grpc.JournalQueryResponse) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) FileNotFoundException(java.io.FileNotFoundException) AbortedException(alluxio.exception.status.AbortedException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) CompletableFuture(java.util.concurrent.CompletableFuture) RaftClientReply(org.apache.ratis.protocol.RaftClientReply) SnapshotMetadata(alluxio.grpc.SnapshotMetadata) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) Map(java.util.Map)

Example 2 with JournalQueryResponse

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;
}
Also used : SnapshotInfo(org.apache.ratis.statemachine.SnapshotInfo) SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) JournalQueryResponse(alluxio.grpc.JournalQueryResponse)

Aggregations

JournalQueryResponse (alluxio.grpc.JournalQueryResponse)2 ClientContext (alluxio.ClientContext)1 Pair (alluxio.collections.Pair)1 ServerConfiguration (alluxio.conf.ServerConfiguration)1 AbortedException (alluxio.exception.status.AbortedException)1 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)1 NotFoundException (alluxio.exception.status.NotFoundException)1 DownloadSnapshotPRequest (alluxio.grpc.DownloadSnapshotPRequest)1 DownloadSnapshotPResponse (alluxio.grpc.DownloadSnapshotPResponse)1 GetSnapshotInfoRequest (alluxio.grpc.GetSnapshotInfoRequest)1 GetSnapshotInfoResponse (alluxio.grpc.GetSnapshotInfoResponse)1 GetSnapshotRequest (alluxio.grpc.GetSnapshotRequest)1 JournalQueryRequest (alluxio.grpc.JournalQueryRequest)1 QuorumServerState (alluxio.grpc.QuorumServerState)1 SnapshotData (alluxio.grpc.SnapshotData)1 SnapshotMetadata (alluxio.grpc.SnapshotMetadata)1 UploadSnapshotPRequest (alluxio.grpc.UploadSnapshotPRequest)1 UploadSnapshotPResponse (alluxio.grpc.UploadSnapshotPResponse)1 MasterClientContext (alluxio.master.MasterClientContext)1 MetricKey (alluxio.metrics.MetricKey)1