use of org.agrona.concurrent.EpochClock 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 org.agrona.concurrent.EpochClock in project Aeron by real-logic.
the class ArchiveTool method migrate.
/**
* Migrate previous archive {@link org.agrona.MarkFile}, {@link Catalog}, and recordings from previous version
* to the latest version.
*
* @param out output stream to print results and errors to.
* @param archiveDir that contains MarkFile, Catalog and recordings.
*/
public static void migrate(final PrintStream out, final File archiveDir) {
final EpochClock epochClock = INSTANCE;
try {
final int markFileVersion;
final IntConsumer noVersionCheck = (version) -> {
};
try (ArchiveMarkFile markFile = openMarkFileReadWrite(archiveDir, epochClock);
Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, null, noVersionCheck)) {
markFileVersion = markFile.decoder().version();
out.println("MarkFile version=" + fullVersionString(markFileVersion));
out.println("Catalog version=" + fullVersionString(catalog.version()));
out.println("Latest version=" + fullVersionString(ArchiveMarkFile.SEMANTIC_VERSION));
}
final List<ArchiveMigrationStep> steps = ArchiveMigrationPlanner.createPlan(markFileVersion);
for (final ArchiveMigrationStep step : steps) {
try (ArchiveMarkFile markFile = openMarkFileReadWrite(archiveDir, epochClock);
Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, null, noVersionCheck)) {
out.println("Migration step " + step.toString());
step.migrate(out, markFile, catalog, archiveDir);
}
}
} catch (final Exception ex) {
ex.printStackTrace(out);
}
}
use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.
the class ArchiveToolTests method verifyChecksum.
@Test
void verifyChecksum() {
final Checksum checksum = crc32();
try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, checksum, null)) {
assertRecording(catalog, validRecording51, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> catalog.updateChecksum(recordingDescriptorOffset));
assertRecording(catalog, validRecording6, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> catalog.updateChecksum(recordingDescriptorOffset));
}
assertFalse(verify(out, archiveDir, of(APPLY_CHECKSUM), checksum, epochClock, (file) -> true));
try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
assertRecording(catalog, validRecording0, INVALID, 0, 0, NULL_POSITION, 15, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording1, INVALID, 0, 1024, NULL_POSITION, 16, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording2, INVALID, 0, TERM_LENGTH * 3 + 96, NULL_POSITION, 17, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording3, INVALID, 0, 7 * TERM_LENGTH + 96, 7 * TERM_LENGTH + 128, 18, NULL_TIMESTAMP, 7, 13, "ch2", "src2");
assertRecording(catalog, validRecording4, INVALID, 0, 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, validRecording52, INVALID, 0, 0, NULL_POSITION, 21, NULL_TIMESTAMP, 0, 52, "ch2", "src2");
assertRecording(catalog, validRecording53, INVALID, 0, 0, NULL_POSITION, 22, NULL_TIMESTAMP, 0, 53, "ch2", "src2");
assertRecording(catalog, validRecording6, VALID, -175549265, 352, 960, 23, 100, 0, 6, "ch2", "src2");
}
Mockito.verify(out, times(24)).println(any(String.class));
}
use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.
the class ArchiveToolTests method verifyRecordingValidRecordingPerformCRC.
@Test
void verifyRecordingValidRecordingPerformCRC() {
final Checksum checksum = crc32();
try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, checksum, null)) {
assertRecording(catalog, validRecording6, (recordingDescriptorOffset, headerEncoder, headerDecoder, descriptorEncoder, descriptorDecoder) -> catalog.updateChecksum(recordingDescriptorOffset));
}
assertTrue(verifyRecording(out, archiveDir, validRecording6, of(APPLY_CHECKSUM), checksum, epochClock, (file) -> false));
try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
assertRecording(catalog, validRecording6, VALID, -175549265, 352, 960, 23, 100, 0, 6, "ch2", "src2");
}
}
use of org.agrona.concurrent.EpochClock in project Aeron by real-logic.
the class ArchiveToolTests method compactDeletesRecordingsInStateInvalidAndDeletesTheCorrespondingSegmentFiles.
@Test
void compactDeletesRecordingsInStateInvalidAndDeletesTheCorrespondingSegmentFiles() {
// Mark recording as INVALID without invoking `invalidateRecording` operation
verifyRecording(out, archiveDir, validRecording3, allOf(VerifyOption.class), crc32(), epochClock, (file) -> false);
try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, null, null)) {
assertRecordingState(catalog, validRecording3, INVALID);
assertTrue(catalog.invalidateRecording(validRecording6));
assertRecordingState(catalog, validRecording6, INVALID);
}
final List<String> segmentFiles = new ArrayList<>();
addAll(segmentFiles, listSegmentFiles(archiveDir, validRecording3));
addAll(segmentFiles, listSegmentFiles(archiveDir, validRecording6));
assertTrue(segmentFiles.stream().allMatch(file -> new File(archiveDir, file).exists()), "Non-existing segment files");
compact(out, archiveDir, epochClock);
try (Catalog catalog = openCatalogReadOnly(archiveDir, epochClock)) {
assertNoRecording(catalog, validRecording3);
assertNoRecording(catalog, validRecording6);
assertEquals(22, catalog.entryCount());
assertRecording(catalog, validRecording0, VALID, 0, 0, NULL_POSITION, 15, NULL_TIMESTAMP, 0, 2, "ch2", "src2");
assertRecording(catalog, validRecording51, VALID, 0, 0, 64 + PAGE_SIZE, 20, 777, 0, 20, "ch2", "src2");
}
assertTrue(segmentFiles.stream().noneMatch(file -> new File(archiveDir, file).exists()), "Segment files not deleted");
Mockito.verify(out).println("Compaction result: deleted 2 records and reclaimed 384 bytes");
}
Aggregations