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