Search in sources :

Example 1 with UploadSnapshotPResponse

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

the class SnapshotReplicationManager method sendSnapshotToLeader.

/**
 * Sends a snapshot to the leader.
 *
 * @throws IOException if error occurs while initializing the data stream
 */
public void sendSnapshotToLeader() throws IOException {
    if (mJournalSystem.isLeader()) {
        throw new IllegalStateException("Server is no longer a follower");
    }
    LOG.debug("Checking latest snapshot to send");
    SnapshotInfo snapshot = mStorage.getLatestSnapshot();
    if (snapshot == null) {
        throw new NotFoundException("No snapshot available");
    }
    StreamObserver<UploadSnapshotPResponse> responseObserver = SnapshotUploader.forFollower(mStorage, snapshot);
    try (RaftJournalServiceClient client = getJournalServiceClient()) {
        LOG.info("Sending stream request to {} for snapshot {}", client.getAddress(), snapshot.getTermIndex());
        StreamObserver<UploadSnapshotPRequest> requestObserver = client.uploadSnapshot(responseObserver);
        requestObserver.onNext(UploadSnapshotPRequest.newBuilder().setData(SnapshotData.newBuilder().setSnapshotTerm(snapshot.getTerm()).setSnapshotIndex(snapshot.getIndex()).setOffset(0)).build());
    }
}
Also used : SnapshotInfo(org.apache.ratis.statemachine.SnapshotInfo) SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(alluxio.exception.status.NotFoundException) UploadSnapshotPRequest(alluxio.grpc.UploadSnapshotPRequest) UploadSnapshotPResponse(alluxio.grpc.UploadSnapshotPResponse)

Example 2 with UploadSnapshotPResponse

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

the class SnapshotReplicationManagerTest method downloadFailure.

/**
 * Simulates a {@link SnapshotDownloader} error.
 */
@Test
public void downloadFailure() throws Exception {
    before(2);
    List<Follower> followers = new ArrayList<>(mFollowers.values());
    Follower firstFollower = followers.get(0);
    Follower secondFollower = followers.get(1);
    // create default 0, 1 snapshot
    createSnapshotFile(firstFollower.mStore);
    // preferable to the default 0, 1 snapshot
    createSnapshotFile(secondFollower.mStore, 0, 2);
    // make sure to error out when requesting the better snapshot from secondFollower
    Mockito.doAnswer(mock -> {
        SingleFileSnapshotInfo snapshot = secondFollower.mStore.getLatestSnapshot();
        StreamObserver<UploadSnapshotPResponse> responseObserver = SnapshotUploader.forFollower(secondFollower.mStore, snapshot);
        StreamObserver<UploadSnapshotPRequest> requestObserver = mClient.uploadSnapshot(responseObserver);
        requestObserver.onError(new IOException("failed snapshot upload"));
        return null;
    }).when(secondFollower.mSnapshotManager).sendSnapshotToLeader();
    mLeaderSnapshotManager.maybeCopySnapshotFromFollower();
    CommonUtils.waitFor("leader snapshot to complete", () -> mLeaderSnapshotManager.maybeCopySnapshotFromFollower() != -1, mWaitOptions);
    // verify that the leader still requests and gets second best snapshot
    validateSnapshotFile(mLeaderStore);
}
Also used : SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) ArrayList(java.util.ArrayList) UploadSnapshotPRequest(alluxio.grpc.UploadSnapshotPRequest) IOException(java.io.IOException) UploadSnapshotPResponse(alluxio.grpc.UploadSnapshotPResponse) Test(org.junit.Test)

Example 3 with UploadSnapshotPResponse

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

the class SnapshotReplicationManagerTest method uploadFailure.

/**
 * Simulates a {@link SnapshotUploader} error.
 */
@Test
public void uploadFailure() throws Exception {
    before(2);
    List<Follower> followers = new ArrayList<>(mFollowers.values());
    Follower firstFollower = followers.get(0);
    Follower secondFollower = followers.get(1);
    // create default 0, 1 snapshot
    createSnapshotFile(firstFollower.mStore);
    // preferable to the default 0, 1 snapshot
    createSnapshotFile(secondFollower.mStore, 0, 2);
    // make sure to error out when requesting the better snapshot from secondFollower
    Mockito.doAnswer(mock -> {
        SingleFileSnapshotInfo snapshot = secondFollower.mStore.getLatestSnapshot();
        StreamObserver<UploadSnapshotPResponse> responseObserver = SnapshotUploader.forFollower(secondFollower.mStore, snapshot);
        StreamObserver<UploadSnapshotPRequest> requestObserver = mClient.uploadSnapshot(responseObserver);
        responseObserver.onError(new StatusRuntimeException(Status.UNAVAILABLE));
        requestObserver.onNext(UploadSnapshotPRequest.newBuilder().setData(SnapshotData.newBuilder().setSnapshotTerm(snapshot.getTerm()).setSnapshotIndex(snapshot.getIndex()).setOffset(0)).build());
        return null;
    }).when(secondFollower.mSnapshotManager).sendSnapshotToLeader();
    mLeaderSnapshotManager.maybeCopySnapshotFromFollower();
    CommonUtils.waitFor("leader snapshot to complete", () -> mLeaderSnapshotManager.maybeCopySnapshotFromFollower() != -1, mWaitOptions);
    // verify that the leader still requests and gets second best snapshot
    validateSnapshotFile(mLeaderStore);
}
Also used : SingleFileSnapshotInfo(org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo) ArrayList(java.util.ArrayList) StatusRuntimeException(io.grpc.StatusRuntimeException) UploadSnapshotPRequest(alluxio.grpc.UploadSnapshotPRequest) UploadSnapshotPResponse(alluxio.grpc.UploadSnapshotPResponse) Test(org.junit.Test)

Aggregations

UploadSnapshotPRequest (alluxio.grpc.UploadSnapshotPRequest)3 UploadSnapshotPResponse (alluxio.grpc.UploadSnapshotPResponse)3 SingleFileSnapshotInfo (org.apache.ratis.statemachine.impl.SingleFileSnapshotInfo)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 NotFoundException (alluxio.exception.status.NotFoundException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 SnapshotInfo (org.apache.ratis.statemachine.SnapshotInfo)1