use of io.aeron.archive.client.AeronArchive.NULL_POSITION in project Aeron by real-logic.
the class CatalogTest method shouldFixTimestampAndPositionAfterFailureSamePage.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
void shouldFixTimestampAndPositionAfterFailureSamePage() throws Exception {
final long newRecordingId = newRecording();
new File(archiveDir, segmentFileName(newRecordingId, 0)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, SEGMENT_LENGTH)).createNewFile();
new File(archiveDir, segmentFileName(newRecordingId, 2 * SEGMENT_LENGTH)).createNewFile();
final File segmentFile = new File(archiveDir, segmentFileName(newRecordingId, 3 * SEGMENT_LENGTH));
try (FileChannel log = FileChannel.open(segmentFile.toPath(), READ, WRITE, CREATE)) {
final ByteBuffer bb = allocate(HEADER_LENGTH);
final DataHeaderFlyweight flyweight = new DataHeaderFlyweight(bb);
flyweight.frameLength(1024);
log.write(bb);
bb.clear();
flyweight.frameLength(128);
log.write(bb, 1024);
bb.clear();
flyweight.frameLength(0);
log.write(bb, 1024 + 128);
}
try (Catalog catalog = new Catalog(archiveDir, clock)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(NULL_TIMESTAMP, descriptorDecoder.stopTimestamp());
assertEquals(NULL_POSITION, descriptorDecoder.stopPosition());
}));
}
currentTimeMs = 42L;
try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
assertTrue(catalog.forEntry(newRecordingId, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> {
assertEquals(42L, descriptorDecoder.stopTimestamp());
assertEquals(SEGMENT_LENGTH * 3 + 1024L + 128L, descriptorDecoder.stopPosition());
}));
}
}
use of io.aeron.archive.client.AeronArchive.NULL_POSITION 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