Search in sources :

Example 21 with Checksum

use of io.aeron.archive.checksum.Checksum in project Aeron by real-logic.

the class ArchiveToolTests method checksumAllSegmentFile.

@Test
void checksumAllSegmentFile() {
    checksum(out, archiveDir, true, crc32(), epochClock);
    assertFalse(verify(out, archiveDir, allOf(VerifyOption.class), crc32(), epochClock, (file) -> false));
    try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
        assertRecording(catalog, validRecording0, VALID, 356725588, 0, TERM_LENGTH + 64, 15, 100, 0, 2, "ch2", "src2");
        assertRecording(catalog, validRecording1, VALID, -1571032591, 1024, 1024, 16, 200, 0, 2, "ch2", "src2");
        assertRecording(catalog, validRecording2, VALID, 114203747, TERM_LENGTH * 3 + 96, TERM_LENGTH * 3 + 96, 17, 300, 0, 2, "ch2", "src2");
        assertRecording(catalog, validRecording3, VALID, 963969455, 7 * TERM_LENGTH + 96, 11 * TERM_LENGTH + 320, 18, 400, 7, 13, "ch2", "src2");
        assertRecording(catalog, validRecording4, INVALID, 162247708, 21 * TERM_LENGTH + (TERM_LENGTH - 64), 22 * TERM_LENGTH + 992, 19, 1, -25, 7, "ch2", "src2");
        assertRecording(catalog, validRecording51, VALID, -940881948, 0, 64 + PAGE_SIZE, 20, 777, 0, 20, "ch2", "src2");
        assertRecording(catalog, validRecording6, VALID, -175549265, 352, 960, 23, 700, 0, 6, "ch2", "src2");
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) FRAME_ALIGNMENT(io.aeron.logbuffer.FrameDescriptor.FRAME_ALIGNMENT) RECORDING_SEGMENT_SUFFIX(io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX) Catalog(io.aeron.archive.Catalog) IoUtil(org.agrona.IoUtil) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) READ(java.nio.file.StandardOpenOption.READ) ByteBuffer.allocate(java.nio.ByteBuffer.allocate) Files.createTempDirectory(java.nio.file.Files.createTempDirectory) EnumSet.allOf(java.util.EnumSet.allOf) AeronArchive(io.aeron.archive.client.AeronArchive) Path(java.nio.file.Path) WRITE(java.nio.file.StandardOpenOption.WRITE) MethodSource(org.junit.jupiter.params.provider.MethodSource) PrintStream(java.io.PrintStream) MutableBoolean(org.agrona.collections.MutableBoolean) LogBufferDescriptor.positionBitsToShift(io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift) ArchiveTool(io.aeron.archive.ArchiveTool) Collections.emptySet(java.util.Collections.emptySet) VERIFY_ALL_SEGMENT_FILES(io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Checksum(io.aeron.archive.checksum.Checksum) Arguments(org.junit.jupiter.params.provider.Arguments) File(java.io.File) Mockito(org.mockito.Mockito) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Collections.addAll(java.util.Collections.addAll) org.junit.jupiter.api(org.junit.jupiter.api) Executable(org.junit.jupiter.api.function.Executable) APPLY_CHECKSUM(io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM) EnumSet.of(java.util.EnumSet.of) Assertions(org.junit.jupiter.api.Assertions) RecordingState(io.aeron.archive.codecs.RecordingState) EpochClock(org.agrona.concurrent.EpochClock) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) Checksums.crc32(io.aeron.archive.checksum.Checksums.crc32) Archive.segmentFileName(io.aeron.archive.Archive.segmentFileName) FileChannel(java.nio.channels.FileChannel) Files.deleteIfExists(java.nio.file.Files.deleteIfExists) LogBufferDescriptor.computeTermIdFromPosition(io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition) Catalog(io.aeron.archive.Catalog) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with Checksum

use of io.aeron.archive.checksum.Checksum 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)

Example 23 with Checksum

use of io.aeron.archive.checksum.Checksum in project Aeron by real-logic.

the class Catalog method updateChecksum.

void updateChecksum(final int recordingDescriptorOffset) {
    final Checksum checksum = this.checksum;
    if (null != checksum) {
        final UnsafeBuffer headerBuffer = this.headerAccessBuffer;
        final int recordingLength = headerBuffer.getInt(recordingDescriptorOffset + RecordingDescriptorHeaderEncoder.lengthEncodingOffset(), BYTE_ORDER);
        final int checksumValue = checksum.compute(catalogByteBufferAddress, DESCRIPTOR_HEADER_LENGTH + recordingDescriptorOffset, recordingLength);
        headerBuffer.putInt(recordingDescriptorOffset + RecordingDescriptorHeaderEncoder.checksumEncodingOffset(), checksumValue, BYTE_ORDER);
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer)

Example 24 with Checksum

use of io.aeron.archive.checksum.Checksum 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 25 with Checksum

use of io.aeron.archive.checksum.Checksum in project Aeron by real-logic.

the class CatalogTest method shouldComputeChecksumOfTheRecordingDescriptorUponAddingToTheCatalog.

@Test
void shouldComputeChecksumOfTheRecordingDescriptorUponAddingToTheCatalog() {
    final Checksum checksum = crc32();
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, checksum, segmentFileBuffer)) {
        final long recordingId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 6, 1, "channelNew", "channelNew?tag=X", "sourceX");
        final long recordingId2 = catalog.addNewRecording(1, 100, 2, 222, 111, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 16, 12, "channelNew2", "channelNew?tag=X2", "sourceX2");
        catalog.forEach((recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
            if (recordingId == descriptorDecoder.recordingId()) {
                assertEquals(1691549102, headerDecoder.checksum());
            } else if (recordingId2 == descriptorDecoder.recordingId()) {
                assertEquals(1452384985, headerDecoder.checksum());
            } else {
                assertEquals(0, headerDecoder.checksum());
            }
        });
    }
}
Also used : Checksum(io.aeron.archive.checksum.Checksum) Catalog(io.aeron.archive.Catalog) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Checksum (io.aeron.archive.checksum.Checksum)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Catalog (io.aeron.archive.Catalog)22 AeronArchive (io.aeron.archive.client.AeronArchive)16 Test (org.junit.jupiter.api.Test)16 INVALID (io.aeron.archive.codecs.RecordingState.INVALID)14 VALID (io.aeron.archive.codecs.RecordingState.VALID)14 File (java.io.File)14 IOException (java.io.IOException)14 ByteBuffer (java.nio.ByteBuffer)14 FileChannel (java.nio.channels.FileChannel)14 EpochClock (org.agrona.concurrent.EpochClock)14 RECORDING_SEGMENT_SUFFIX (io.aeron.archive.Archive.Configuration.RECORDING_SEGMENT_SUFFIX)12 APPLY_CHECKSUM (io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM)12 VERIFY_ALL_SEGMENT_FILES (io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES)12 LogBufferDescriptor.computeTermIdFromPosition (io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition)12 LogBufferDescriptor.positionBitsToShift (io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift)12 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)12 PrintStream (java.io.PrintStream)12 Path (java.nio.file.Path)12