Search in sources :

Example 26 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 27 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class RecordingWriter method checkErrorType.

private void checkErrorType(final IOException ex, final int writeLength) {
    final String msg = ex.getMessage();
    boolean isLowStorageSpace = false;
    IOException suppressed = null;
    try {
        isLowStorageSpace = (!Strings.isEmpty(msg) && msg.contains("No space left on device")) || ctx.archiveFileStore().getUsableSpace() < writeLength;
    } catch (final IOException ex2) {
        suppressed = ex2;
    }
    final int errorCode = isLowStorageSpace ? ArchiveException.STORAGE_SPACE : ArchiveException.GENERIC;
    final ArchiveException error = new ArchiveException("java.io.IOException - " + msg, ex, errorCode);
    if (null != suppressed) {
        error.addSuppressed(suppressed);
    }
    throw error;
}
Also used : IOException(java.io.IOException) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 28 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class Catalog method refreshAndFixDescriptor.

private void refreshAndFixDescriptor(final RecordingDescriptorHeaderDecoder headerDecoder, final RecordingDescriptorEncoder encoder, final RecordingDescriptorDecoder decoder, final Checksum checksum, final UnsafeBuffer buffer) {
    final long recordingId = decoder.recordingId();
    if (VALID == headerDecoder.state() && NULL_POSITION == decoder.stopPosition()) {
        final String[] segmentFiles = listSegmentFiles(archiveDir, recordingId);
        final String maxSegmentFile = findSegmentFileWithHighestPosition(segmentFiles);
        encoder.stopPosition(computeStopPosition(archiveDir, maxSegmentFile, decoder.startPosition(), decoder.termBufferLength(), decoder.segmentFileLength(), checksum, buffer, (segmentFile) -> {
            throw new ArchiveException("Found potentially incomplete last fragment straddling page boundary in file: " + segmentFile.getAbsolutePath() + "\nRun `ArchiveTool verify` for corrective action!");
        }));
        encoder.stopTimestamp(epochClock.time());
    }
}
Also used : AsciiEncoding.parseLongAscii(org.agrona.AsciiEncoding.parseLongAscii) RECORDING_SEGMENT_SUFFIX(io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX) IntConsumer(java.util.function.IntConsumer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) ByteBuffer(java.nio.ByteBuffer) FILE_IO_MAX_LENGTH_DEFAULT(io.aeron.archive.Archive.Configuration.FILE_IO_MAX_LENGTH_DEFAULT) BitUtil(org.agrona.BitUtil) org.agrona(org.agrona) READ_WRITE(java.nio.channels.FileChannel.MapMode.READ_WRITE) io.aeron.archive.codecs(io.aeron.archive.codecs) NULL_POSITION(io.aeron.archive.client.AeronArchive.NULL_POSITION) READ_ONLY(java.nio.channels.FileChannel.MapMode.READ_ONLY) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) HEADER_LENGTH(io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH) Aeron(io.aeron.Aeron) Predicate(java.util.function.Predicate) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Math.min(java.lang.Math.min) Checksum(io.aeron.archive.checksum.Checksum) File(java.io.File) NULL_TIMESTAMP(io.aeron.archive.client.AeronArchive.NULL_TIMESTAMP) RecordingDescriptorDecoder(io.aeron.archive.codecs.RecordingDescriptorDecoder) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) ByteOrder.nativeOrder(java.nio.ByteOrder.nativeOrder) ArchiveException(io.aeron.archive.client.ArchiveException) EpochClock(org.agrona.concurrent.EpochClock) Math.max(java.lang.Math.max) FileChannel(java.nio.channels.FileChannel) MappedByteBuffer(java.nio.MappedByteBuffer) ArchiveException(io.aeron.archive.client.ArchiveException)

Example 29 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class CatalogTest method shouldThrowArchiveExceptionIfNextRecordingIdIsInvalidWriteableCatalog.

@Test
void shouldThrowArchiveExceptionIfNextRecordingIdIsInvalidWriteableCatalog() throws IOException {
    setNextRecordingId(-1);
    final ArchiveException exception = assertThrows(ArchiveException.class, () -> new Catalog(archiveDir, clock, MIN_CAPACITY, true, null, null));
    assertEquals("ERROR - invalid nextRecordingId: expected value greater or equal to " + (recordingThreeId + 1) + ", was -1", exception.getMessage());
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with ArchiveException

use of io.aeron.archive.client.ArchiveException in project Aeron by real-logic.

the class CatalogTest method shouldThrowArchiveExceptionIfNextRecordingIdIsSmallerThanTheActualLastRecordInTheCatalog.

@Test
void shouldThrowArchiveExceptionIfNextRecordingIdIsSmallerThanTheActualLastRecordInTheCatalog() throws IOException {
    setNextRecordingId(recordingTwoId);
    final ArchiveException exception = assertThrows(ArchiveException.class, () -> new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer));
    assertEquals("ERROR - invalid nextRecordingId: expected value greater or equal to " + (recordingThreeId + 1) + ", was " + recordingTwoId, exception.getMessage());
}
Also used : ArchiveException(io.aeron.archive.client.ArchiveException) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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