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 CatalogTest method extendRecordingShouldUpdateChecksum.
@Test
void extendRecordingShouldUpdateChecksum() {
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");
assertChecksum(catalog, recordingId, 1691549102);
catalog.extendRecording(recordingId, 555, 13, 31);
assertChecksum(catalog, recordingId, -1694749833);
}
}
use of io.aeron.archive.checksum.Checksum in project aeron by real-logic.
the class ReplaySession method replay.
private int replay() throws IOException {
if (!publication.isConnected()) {
state(State.INACTIVE);
return 0;
}
if (replayPosition >= stopPosition && null != limitPosition && noNewData(replayPosition, stopPosition)) {
return 0;
}
if (termOffset == termLength) {
nextTerm();
}
int workCount = 0;
final int bytesRead = readRecording(stopPosition - replayPosition);
if (bytesRead > 0) {
int batchOffset = 0;
int paddingFrameLength = 0;
final int sessionId = publication.sessionId();
final int streamId = publication.streamId();
final long remaining = replayLimit - replayPosition;
final Checksum checksum = this.checksum;
final UnsafeBuffer replayBuffer = this.replayBuffer;
while (batchOffset < bytesRead && batchOffset < remaining) {
final int frameLength = frameLength(replayBuffer, batchOffset);
if (frameLength <= 0) {
raiseError(frameLength, bytesRead, batchOffset, remaining);
}
final int frameType = frameType(replayBuffer, batchOffset);
final int alignedLength = align(frameLength, FRAME_ALIGNMENT);
if (HDR_TYPE_DATA == frameType) {
if (batchOffset + alignedLength > bytesRead) {
break;
}
if (null != checksum) {
verifyChecksum(checksum, batchOffset, alignedLength);
}
replayBuffer.putInt(batchOffset + SESSION_ID_FIELD_OFFSET, sessionId, LITTLE_ENDIAN);
replayBuffer.putInt(batchOffset + STREAM_ID_FIELD_OFFSET, streamId, LITTLE_ENDIAN);
batchOffset += alignedLength;
} else if (HDR_TYPE_PAD == frameType) {
paddingFrameLength = frameLength;
break;
}
}
if (batchOffset > 0) {
final long position = publication.offerBlock(replayBuffer, 0, batchOffset);
if (hasPublicationAdvanced(position, batchOffset)) {
workCount++;
} else {
paddingFrameLength = 0;
}
}
if (paddingFrameLength > 0) {
final long position = publication.appendPadding(paddingFrameLength - HEADER_LENGTH);
if (hasPublicationAdvanced(position, align(paddingFrameLength, FRAME_ALIGNMENT))) {
workCount++;
}
}
}
return workCount;
}
use of io.aeron.archive.checksum.Checksum in project aeron by real-logic.
the class ArchiveTool method createVerifyEntryProcessor.
private static CatalogEntryProcessor createVerifyEntryProcessor(final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Catalog catalog, final Checksum checksum, final EpochClock epochClock, final MutableInteger errorCount, final ActionConfirmation<File> truncateOnPageStraddle) {
final ByteBuffer buffer = BufferUtil.allocateDirectAligned(FILE_IO_MAX_LENGTH_DEFAULT, CACHE_LINE_LENGTH);
buffer.order(LITTLE_ENDIAN);
final DataHeaderFlyweight headerFlyweight = new DataHeaderFlyweight(buffer);
return (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> verifyRecording(out, archiveDir, options, catalog, checksum, epochClock, errorCount, truncateOnPageStraddle, headerFlyweight, recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder);
}
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());
}
}
Aggregations