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");
}
}
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));
}
}
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);
}
}
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());
}
}
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());
}
});
}
}
Aggregations