Search in sources :

Example 6 with ArchiveException

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);
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) ArchiveException(io.aeron.archive.client.ArchiveException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) IOException(java.io.IOException) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 7 with ArchiveException

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());
    }
}
Also used : Context(io.aeron.archive.Archive.Context) Image(io.aeron.Image) ArchiveException(io.aeron.archive.client.ArchiveException) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) Test(org.junit.jupiter.api.Test)

Example 8 with ArchiveException

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);
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) File(java.io.File)

Example 9 with ArchiveException

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);
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) ByteBuffer(java.nio.ByteBuffer)

Example 10 with ArchiveException

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;
}
Also used : ClusterEvent(io.aeron.cluster.client.ClusterEvent) RecordingSignalPoller(io.aeron.archive.client.RecordingSignalPoller) ArchiveException(io.aeron.archive.client.ArchiveException)

Aggregations

ArchiveException (io.aeron.archive.client.ArchiveException)48 Test (org.junit.jupiter.api.Test)26 File (java.io.File)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 InterruptAfter (io.aeron.test.InterruptAfter)12 Catalog (io.aeron.archive.Catalog)10 IOException (java.io.IOException)10 CountersReader (org.agrona.concurrent.status.CountersReader)10 ByteBuffer (java.nio.ByteBuffer)8 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)8 Context (io.aeron.archive.Archive.Context)6 Checksum (io.aeron.archive.checksum.Checksum)6 AeronArchive (io.aeron.archive.client.AeronArchive)6 MappedByteBuffer (java.nio.MappedByteBuffer)6 Aeron (io.aeron.Aeron)4 CommonContext (io.aeron.CommonContext)4 MediaDriver (io.aeron.driver.MediaDriver)4 FrameDescriptor (io.aeron.logbuffer.FrameDescriptor)4 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)4 Authenticator (io.aeron.security.Authenticator)4