use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class Catalog method growCatalog.
void growCatalog(final long maxCatalogCapacity, final int frameLength) {
final long oldCapacity = capacity;
final long recordingOffset = nextRecordingDescriptorOffset;
final long targetCapacity = recordingOffset + frameLength;
if (targetCapacity > maxCatalogCapacity) {
if (maxCatalogCapacity == oldCapacity) {
throw new ArchiveException("catalog is full, max capacity reached: " + maxCatalogCapacity);
} else {
throw new ArchiveException("recording is too big: total recording length is " + frameLength + " bytes," + " available space is " + (maxCatalogCapacity - recordingOffset) + " bytes");
}
}
long newCapacity = oldCapacity;
while (newCapacity < targetCapacity) {
newCapacity = min(newCapacity + (newCapacity >> 1), maxCatalogCapacity);
}
final MappedByteBuffer mappedByteBuffer;
try {
unmapAndCloseChannel();
catalogChannel = FileChannel.open(catalogFile.toPath(), READ, WRITE, SPARSE);
mappedByteBuffer = catalogChannel.map(READ_WRITE, 0, newCapacity);
} catch (final Exception ex) {
close();
LangUtil.rethrowUnchecked(ex);
return;
}
capacity = newCapacity;
initBuffers(mappedByteBuffer);
final UnsafeBuffer catalogHeaderBuffer = new UnsafeBuffer(catalogByteBuffer);
catalogHeaderDecoder.wrap(catalogHeaderBuffer, 0, CatalogHeaderDecoder.BLOCK_LENGTH, CatalogHeaderDecoder.SCHEMA_VERSION);
catalogHeaderEncoder.wrap(catalogHeaderBuffer, 0);
catalogResized(oldCapacity, newCapacity);
}
use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.
the class RecordingWriterTest method onBlockThrowsArchiveExceptionIfCurrentThreadWasInterrupted.
@Test
void onBlockThrowsArchiveExceptionIfCurrentThreadWasInterrupted() throws IOException {
final Image image = mockImage(0L);
final RecordingWriter recordingWriter = new RecordingWriter(1, 0, SEGMENT_LENGTH, image, new Context().archiveDir(archiveDir));
recordingWriter.init();
assertFalse(Thread.interrupted());
try {
Thread.currentThread().interrupt();
final ArchiveException exception = assertThrows(ArchiveException.class, () -> recordingWriter.onBlock(new UnsafeBuffer(allocate(32)), 0, 10, 5, 8));
assertEquals(GENERIC, exception.errorCode());
assertEquals("ERROR - file closed by interrupt, recording aborted", exception.getMessage());
} finally {
assertTrue(Thread.interrupted());
}
}
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 ReplaySession method notHeaderAligned.
static boolean notHeaderAligned(final FileChannel channel, final UnsafeBuffer buffer, final int segmentOffset, final int termOffset, final int termId, final int streamId) throws IOException {
final ByteBuffer byteBuffer = buffer.byteBuffer();
byteBuffer.clear().limit(HEADER_LENGTH);
if (HEADER_LENGTH != channel.read(byteBuffer, segmentOffset)) {
throw new ArchiveException("failed to read fragment header");
}
return isInvalidHeader(buffer, streamId, termId, termOffset);
}
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;
}
Aggregations