Search in sources :

Example 21 with ArchiveException

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

Example 22 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 23 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)

Example 24 with ArchiveException

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();
    }
}
Also used : Context(io.aeron.archive.Archive.Context) CommonContext(io.aeron.CommonContext) RecordingSubscriptionDescriptorConsumer(io.aeron.archive.client.RecordingSubscriptionDescriptorConsumer) IntConsumer(java.util.function.IntConsumer) LOCAL(io.aeron.archive.codecs.SourceLocation.LOCAL) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ChannelUriStringBuilder(io.aeron.ChannelUriStringBuilder) AeronArchive(io.aeron.archive.client.AeronArchive) DEDICATED(io.aeron.archive.ArchiveThreadingMode.DEDICATED) Publication(io.aeron.Publication) MediaDriver(io.aeron.driver.MediaDriver) ManyToOneConcurrentLinkedQueue(org.agrona.concurrent.ManyToOneConcurrentLinkedQueue) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) InterruptingTestCallback(io.aeron.test.InterruptingTestCallback) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter) CountDownLatch(java.util.concurrent.CountDownLatch) TruncateRecordingRequestDecoder(io.aeron.archive.codecs.TruncateRecordingRequestDecoder) EXCLUDE(org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) DirectBuffer(org.agrona.DirectBuffer) Mockito.mock(org.mockito.Mockito.mock) Tests(io.aeron.test.Tests) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) CountersReader(org.agrona.concurrent.status.CountersReader) EnumSource(org.junit.jupiter.params.provider.EnumSource) ArrayList(java.util.ArrayList) SystemEpochClock(org.agrona.concurrent.SystemEpochClock) Context(io.aeron.archive.Archive.Context) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) ValueSource(org.junit.jupiter.params.provider.ValueSource) RecordingPos(io.aeron.archive.status.RecordingPos) Aeron(io.aeron.Aeron) FileStore(java.nio.file.FileStore) SHARED(io.aeron.archive.ArchiveThreadingMode.SHARED) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) LogBufferDescriptor(io.aeron.logbuffer.LogBufferDescriptor) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MIN_CAPACITY(io.aeron.archive.Catalog.MIN_CAPACITY) ArchiveException(io.aeron.archive.client.ArchiveException) ThreadingMode(io.aeron.driver.ThreadingMode) Assertions(org.junit.jupiter.api.Assertions) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AuthorisationServiceSupplier(io.aeron.security.AuthorisationServiceSupplier) ArchiveException(io.aeron.archive.client.ArchiveException) AeronArchive(io.aeron.archive.client.AeronArchive) Context(io.aeron.archive.Archive.Context) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InterruptAfter(io.aeron.test.InterruptAfter)

Example 25 with ArchiveException

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));
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) ArchiveException(io.aeron.archive.client.ArchiveException) BufferClaim(io.aeron.logbuffer.BufferClaim) Test(org.junit.jupiter.api.Test)

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