Search in sources :

Example 51 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class CatalogTest method stopPositionShouldUpdateChecksum.

@Test
void stopPositionShouldUpdateChecksum() {
    final Checksum checksum = crc32();
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, checksum, segmentFileBuffer)) {
        assertChecksum(catalog, recordingTwoId, 0);
        catalog.stopPosition(recordingTwoId, 7777);
        assertChecksum(catalog, recordingTwoId, -1985007076);
    }
}
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)

Example 52 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class CatalogTest method before.

@BeforeEach
void before() {
    try (Catalog catalog = new Catalog(archiveDir, null, 0, CAPACITY, clock, null, segmentFileBuffer)) {
        recordingOneId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 6, 1, "channelG", "channelG?tag=f", "sourceA");
        recordingTwoId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 7, 2, "channelH", "channelH?tag=f", "sourceV");
        recordingThreeId = catalog.addNewRecording(0L, 0L, 0, SEGMENT_LENGTH, TERM_LENGTH, MTU_LENGTH, 8, 3, "channelThatIsVeryLongAndShouldNotBeTruncated", "channelThatIsVeryLongAndShouldNotBeTruncated?tag=f", "source can also be a very very very long String and it will not be truncated even " + "if gets very very long");
    }
}
Also used : Catalog(io.aeron.archive.Catalog) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 53 with Catalog

use of io.aeron.archive.Catalog 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);
    }
}
Also used : CACHE_LINE_LENGTH(org.agrona.BitUtil.CACHE_LINE_LENGTH) MigrationUtils.fullVersionString(io.aeron.archive.MigrationUtils.fullVersionString) NATIVE_BYTE_ORDER(org.agrona.BufferUtil.NATIVE_BYTE_ORDER) 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) org.agrona(org.agrona) Collectors.toMap(java.util.stream.Collectors.toMap) Path(java.nio.file.Path) HDR_TYPE_PAD(io.aeron.protocol.HeaderFlyweight.HDR_TYPE_PAD) NULL_POSITION(io.aeron.archive.client.AeronArchive.NULL_POSITION) LogBufferDescriptor.positionBitsToShift(io.aeron.logbuffer.LogBufferDescriptor.positionBitsToShift) HEADER_LENGTH(io.aeron.protocol.DataHeaderFlyweight.HEADER_LENGTH) VERIFY_ALL_SEGMENT_FILES(io.aeron.archive.ArchiveTool.VerifyOption.VERIFY_ALL_SEGMENT_FILES) StandardOpenOption(java.nio.file.StandardOpenOption) Math.min(java.lang.Math.min) INVALID(io.aeron.archive.codecs.RecordingState.INVALID) VALID(io.aeron.archive.codecs.RecordingState.VALID) Stream(java.util.stream.Stream) LITTLE_ENDIAN(java.nio.ByteOrder.LITTLE_ENDIAN) EpochClock(org.agrona.concurrent.EpochClock) DataHeaderFlyweight(io.aeron.protocol.DataHeaderFlyweight) ReplaySession.isInvalidHeader(io.aeron.archive.ReplaySession.isInvalidHeader) java.util(java.util) Checksums.newInstance(io.aeron.archive.checksum.Checksums.newInstance) Catalog(io.aeron.archive.Catalog) HeaderFlyweight(io.aeron.protocol.HeaderFlyweight) Configuration(io.aeron.driver.Configuration) READ_WRITE(java.nio.channels.FileChannel.MapMode.READ_WRITE) io.aeron.archive.codecs(io.aeron.archive.codecs) MutableInteger(org.agrona.collections.MutableInteger) PrintStream(java.io.PrintStream) FrameDescriptor(io.aeron.logbuffer.FrameDescriptor) Collections.emptySet(java.util.Collections.emptySet) Files(java.nio.file.Files) SESSION_ID_FIELD_OFFSET(io.aeron.protocol.DataHeaderFlyweight.SESSION_ID_FIELD_OFFSET) AeronArchive.segmentFileBasePosition(io.aeron.archive.client.AeronArchive.segmentFileBasePosition) IOException(java.io.IOException) CommonContext(io.aeron.CommonContext) Checksum(io.aeron.archive.checksum.Checksum) AeronException(io.aeron.exceptions.AeronException) File(java.io.File) INSTANCE(org.agrona.concurrent.SystemEpochClock.INSTANCE) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) APPLY_CHECKSUM(io.aeron.archive.ArchiveTool.VerifyOption.APPLY_CHECKSUM) CncFileDescriptor(io.aeron.CncFileDescriptor) MarkFileHeaderDecoder(io.aeron.archive.codecs.mark.MarkFileHeaderDecoder) HDR_TYPE_DATA(io.aeron.protocol.HeaderFlyweight.HDR_TYPE_DATA) FileChannel(java.nio.channels.FileChannel) BitUtil.align(org.agrona.BitUtil.align) CATALOG_FILE_NAME(io.aeron.archive.Archive.Configuration.CATALOG_FILE_NAME) MappedByteBuffer(java.nio.MappedByteBuffer) LogBufferDescriptor.computeTermIdFromPosition(io.aeron.logbuffer.LogBufferDescriptor.computeTermIdFromPosition) EpochClock(org.agrona.concurrent.EpochClock) Catalog(io.aeron.archive.Catalog) IOException(java.io.IOException) AeronException(io.aeron.exceptions.AeronException) IntConsumer(java.util.function.IntConsumer)

Example 54 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class ArchiveTool method verify.

static boolean verify(final PrintStream out, final File archiveDir, final Set<VerifyOption> options, final Checksum checksum, final EpochClock epochClock, final ActionConfirmation<File> truncateOnPageStraddle) {
    try (Catalog catalog = openCatalogReadWrite(archiveDir, epochClock, MIN_CAPACITY, checksum, null)) {
        final MutableInteger errorCount = new MutableInteger();
        catalog.forEach(createVerifyEntryProcessor(out, archiveDir, options, catalog, checksum, epochClock, errorCount, truncateOnPageStraddle));
        return errorCount.get() == 0;
    }
}
Also used : MutableInteger(org.agrona.collections.MutableInteger) Catalog(io.aeron.archive.Catalog)

Example 55 with Catalog

use of io.aeron.archive.Catalog in project aeron by real-logic.

the class ArchiveTool method describe.

/**
 * Describe the metadata for entries in the {@link Catalog}.
 *
 * @param out        to which the entries will be printed.
 * @param archiveDir containing the {@link Catalog}.
 */
public static void describe(final PrintStream out, final File archiveDir) {
    try (Catalog catalog = openCatalogReadOnly(archiveDir, INSTANCE);
        ArchiveMarkFile markFile = openMarkFile(archiveDir, out::println)) {
        printMarkInformation(markFile, out);
        out.println("Catalog capacity in bytes: " + catalog.capacity());
        catalog.forEach((recordingDescriptorOffset, he, hd, e, d) -> out.println(d));
    }
}
Also used : Catalog(io.aeron.archive.Catalog)

Aggregations

Catalog (io.aeron.archive.Catalog)98 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)78 Test (org.junit.jupiter.api.Test)52 File (java.io.File)44 Checksum (io.aeron.archive.checksum.Checksum)40 ByteBuffer (java.nio.ByteBuffer)36 FileChannel (java.nio.channels.FileChannel)36 DataHeaderFlyweight (io.aeron.protocol.DataHeaderFlyweight)34 IOException (java.io.IOException)34 INVALID (io.aeron.archive.codecs.RecordingState.INVALID)30 VALID (io.aeron.archive.codecs.RecordingState.VALID)30 EpochClock (org.agrona.concurrent.EpochClock)30 Archive.segmentFileName (io.aeron.archive.Archive.segmentFileName)26 Checksums.crc32 (io.aeron.archive.checksum.Checksums.crc32)26 ByteBuffer.allocate (java.nio.ByteBuffer.allocate)26 IoUtil (org.agrona.IoUtil)26 Assertions (org.junit.jupiter.api.Assertions)26 Arguments (org.junit.jupiter.params.provider.Arguments)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)26 Path (java.nio.file.Path)24