use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class RecordingWriter method onFileRollOver.
private void onFileRollOver() {
CloseHelper.close(recordingFileChannel);
segmentOffset = 0;
segmentBasePosition += segmentLength;
final File file = new File(archiveDir, Archive.segmentFileName(recordingId, segmentBasePosition));
if (file.exists()) {
throw new ArchiveException("segment file already exists: " + file);
}
openRecordingSegmentFile(file);
}
use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class ReplaySession method openRecordingSegment.
private void openRecordingSegment() throws IOException {
if (null == segmentFile) {
final String segmentFileName = segmentFileName(recordingId, segmentFileBasePosition);
segmentFile = new File(archiveDir, segmentFileName);
if (!segmentFile.exists()) {
final String msg = "recording segment not found " + segmentFileName;
onError(msg);
throw new ArchiveException(msg);
}
}
fileChannel = FileChannel.open(segmentFile.toPath(), FILE_OPTIONS);
}
use of io.aeron.archive.client.ArchiveException in project aeron by real-logic.
the class ConsensusModuleAgent method pollArchiveEvents.
int pollArchiveEvents() {
int workCount = 0;
if (null != archive) {
final RecordingSignalPoller poller = this.recordingSignalPoller;
workCount += poller.poll();
if (poller.isPollComplete()) {
final int templateId = poller.templateId();
if (ControlResponseDecoder.TEMPLATE_ID == templateId && poller.code() == ControlResponseCode.ERROR) {
for (final ClusterMember member : activeMembers) {
if (member.catchupReplayCorrelationId() == poller.correlationId()) {
member.catchupReplaySessionId(NULL_VALUE);
member.catchupReplayCorrelationId(NULL_VALUE);
ctx.countedErrorHandler().onError(new ClusterEvent("catchup replay failed - " + poller.errorMessage()));
return workCount;
}
}
final ArchiveException ex = new ArchiveException(poller.errorMessage(), (int) poller.relevantId(), poller.correlationId());
if (ex.errorCode() == ArchiveException.STORAGE_SPACE) {
ctx.countedErrorHandler().onError(ex);
unexpectedTermination();
}
if (null != election) {
election.handleError(clusterClock.timeNanos(), ex);
}
} else if (RecordingSignalEventDecoder.TEMPLATE_ID == templateId) {
final long recordingId = poller.recordingId();
final long position = poller.recordingPosition();
final RecordingSignal signal = poller.recordingSignal();
if (RecordingSignal.STOP == signal && recordingId == logRecordingId) {
this.logRecordedPosition = position;
}
if (null != election) {
election.onRecordingSignal(poller.correlationId(), recordingId, position, signal);
}
if (null != dynamicJoin) {
dynamicJoin.onRecordingSignal(poller.correlationId(), recordingId, position, signal);
}
}
} else if (0 == workCount && !poller.subscription().isConnected()) {
ctx.countedErrorHandler().onError(new ClusterEvent("local archive is not connected"));
unexpectedTermination();
}
}
return workCount;
}
use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class ArchiveTest method shouldErrorWhenUnauthorised.
@Test
@InterruptAfter(10)
public void shouldErrorWhenUnauthorised() {
final MediaDriver.Context driverCtx = new MediaDriver.Context().dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
final AuthorisationServiceSupplier authorisationServiceSupplier = () -> (protocolId, actionId, type, encodedPrincipal) -> {
return actionId != TruncateRecordingRequestDecoder.TEMPLATE_ID;
};
final Archive.Context archiveCtx = new Archive.Context().deleteArchiveOnStart(true).authorisationServiceSupplier(authorisationServiceSupplier).threadingMode(SHARED);
try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx);
AeronArchive archive = AeronArchive.connect()) {
try {
archive.truncateRecording(0, 0);
} catch (final ArchiveException ex) {
assertEquals(ArchiveException.UNAUTHORISED_ACTION, ex.errorCode());
return;
}
fail("Expected exception");
} finally {
archiveCtx.deleteDirectory();
driverCtx.deleteDirectory();
}
}
use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class ReplaySessionTest method shouldThrowArchiveExceptionIfCrcFails.
@Test
public void shouldThrowArchiveExceptionIfCrcFails() {
final long length = 4 * FRAME_LENGTH;
final long correlationId = 1L;
final Checksum checksum = crc32();
try (ReplaySession replaySession = replaySession(RECORDING_POSITION + 2 * FRAME_LENGTH, length, correlationId, mockReplayPub, mockControlSession, null, checksum)) {
when(mockReplayPub.isClosed()).thenReturn(false);
when(mockReplayPub.isConnected()).thenReturn(false);
replaySession.doWork();
assertEquals(ReplaySession.State.INIT, replaySession.state());
when(mockReplayPub.isConnected()).thenReturn(true);
final ArchiveException exception = assertThrows(ArchiveException.class, replaySession::doWork);
assertEquals(ArchiveException.GENERIC, exception.errorCode());
assertThat(exception.getMessage(), Matchers.startsWith("ERROR - CRC checksum mismatch at offset=0"));
verify(mockReplayPub, never()).tryClaim(anyInt(), any(BufferClaim.class));
}
}
Aggregations