Search in sources :

Example 16 with Archive

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

the class RecordingDescriptorCollectorTest method shouldShouldNotReuseDescriptorIfPoolSizeIsZero.

@Test
void shouldShouldNotReuseDescriptorIfPoolSizeIsZero(@TempDir final Path tempDir) {
    try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
        Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
        createRecordings(aeronArchive, 3);
        final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(0);
        long fromRecordingId = 0;
        int count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc0 = collector.descriptors().get(0);
        fromRecordingId += count;
        count = aeronArchive.listRecordings(fromRecordingId, 1, collector.reset());
        assertEquals(1, count);
        final RecordingDescriptor desc1 = collector.descriptors().get(0);
        assertNotEquals(desc0.recordingId(), desc1.recordingId());
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test)

Example 17 with Archive

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

the class RecordingDescriptorCollectorTest method shouldCollectPagesOfRecordingDescriptors.

@Test
@InterruptAfter(10)
void shouldCollectPagesOfRecordingDescriptors(@TempDir final Path tempDir) {
    try (MediaDriver mediaDriver = MediaDriver.launch(new MediaDriver.Context().dirDeleteOnStart(true));
        Archive ignore = Archive.launch(new Archive.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()).archiveDir(tempDir.resolve("archive").toFile()).deleteArchiveOnStart(true));
        Aeron aeron = Aeron.connect(new Aeron.Context().aeronDirectoryName(mediaDriver.aeronDirectoryName()));
        AeronArchive aeronArchive = AeronArchive.connect(new AeronArchive.Context().aeron(aeron).ownsAeronClient(false))) {
        final int numRecordings = 10;
        createRecordings(aeronArchive, numRecordings);
        final RecordingDescriptorCollector collector = new RecordingDescriptorCollector(3);
        long fromRecordingId = 0;
        int count;
        while (0 < (count = aeronArchive.listRecordings(fromRecordingId, collector.poolSize(), collector.reset()))) {
            final List<RecordingDescriptor> descriptors = collector.descriptors();
            assertThat(count, lessThanOrEqualTo(collector.poolSize()));
            assertThat(descriptors.size(), lessThanOrEqualTo(collector.poolSize()));
            // noinspection OptionalGetWithoutIsPresent
            final long maxRecordingId = descriptors.stream().mapToLong(RecordingDescriptor::recordingId).max().getAsLong();
            fromRecordingId = maxRecordingId + 1;
        }
    }
}
Also used : Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) AeronArchive(io.aeron.archive.client.AeronArchive) Aeron(io.aeron.Aeron) SlowTest(io.aeron.test.SlowTest) Test(org.junit.jupiter.api.Test) InterruptAfter(io.aeron.test.InterruptAfter)

Example 18 with Archive

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

the class BasicAuctionClusteredServiceNode method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
    // <1>
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
    final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
    ",");
    final String hostname = hostnames[nodeId];
    // <3>
    final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
    // <4>
    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    // end::main[]
    // tag::media_driver[]
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).terminationHook(barrier::signal).errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
    // end::media_driver[]
    final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
    // tag::archive[]
    final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    // end::archive[]
    // tag::archive_client[]
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
    // end::archive_client[]
    // tag::consensus_module[]
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
    nodeId).clusterMembers(// <2>
    clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
    new File(baseDir, "cluster")).ingressChannel(// <4>
    "aeron:udp?term-length=64k").logChannel(// <5>
    logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
    logReplicationChannel(hostname)).archiveContext(// <7>
    aeronArchiveContext.clone());
    // end::consensus_module[]
    // tag::clustered_service[]
    final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
    aeronDirName).archiveContext(// <2>
    aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
    new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
    // tag::running[]
    try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
    consensusModuleContext);
        ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
        clusteredServiceContext)) {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
        // <3>
        barrier.await();
        System.out.println("[" + nodeId + "] Exiting");
    }
// end::running[]
}
Also used : CommonContext(io.aeron.CommonContext) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) AeronArchive(io.aeron.archive.client.AeronArchive) ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) MediaDriver(io.aeron.driver.MediaDriver) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 19 with Archive

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

the class ClusterBackupMediaDriver method launch.

/**
 * Launch a new {@link ClusterBackupMediaDriver} with provided contexts.
 *
 * @param driverCtx        for configuring the {@link MediaDriver}.
 * @param archiveCtx       for configuring the {@link Archive}.
 * @param clusterBackupCtx for the configuration of the {@link ClusterBackup}.
 * @return a new {@link ClusterBackupMediaDriver} with the provided contexts.
 */
public static ClusterBackupMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ClusterBackup.Context clusterBackupCtx) {
    MediaDriver driver = null;
    Archive archive = null;
    ClusterBackup clusterBackup = null;
    try {
        driver = MediaDriver.launch(driverCtx.spiesSimulateConnection(true));
        final int errorCounterId = SystemCounterDescriptor.ERRORS.id();
        final AtomicCounter errorCounter = null != archiveCtx.errorCounter() ? archiveCtx.errorCounter() : new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId);
        final ErrorHandler errorHandler = null != archiveCtx.errorHandler() ? archiveCtx.errorHandler() : driverCtx.errorHandler();
        archive = Archive.launch(archiveCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()).mediaDriverAgentInvoker(driver.sharedAgentInvoker()).errorHandler(errorHandler).errorCounter(errorCounter));
        clusterBackup = ClusterBackup.launch(clusterBackupCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
        return new ClusterBackupMediaDriver(driver, archive, clusterBackup);
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(clusterBackup, archive, driver);
        throw ex;
    }
}
Also used : ErrorHandler(org.agrona.ErrorHandler) Archive(io.aeron.archive.Archive) MediaDriver(io.aeron.driver.MediaDriver) AtomicCounter(org.agrona.concurrent.status.AtomicCounter)

Example 20 with Archive

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

the class BasicAuctionClusteredServiceNode method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
    // <1>
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
    final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
    ",");
    final String hostname = hostnames[nodeId];
    // <3>
    final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
    // <4>
    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    // end::main[]
    // tag::media_driver[]
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).terminationHook(barrier::signal).errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
    // end::media_driver[]
    final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
    // tag::archive[]
    final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    // end::archive[]
    // tag::archive_client[]
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
    // end::archive_client[]
    // tag::consensus_module[]
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
    nodeId).clusterMembers(// <2>
    clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
    new File(baseDir, "cluster")).ingressChannel(// <4>
    "aeron:udp?term-length=64k").logChannel(// <5>
    logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
    logReplicationChannel(hostname)).archiveContext(// <7>
    aeronArchiveContext.clone());
    // end::consensus_module[]
    // tag::clustered_service[]
    final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
    aeronDirName).archiveContext(// <2>
    aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
    new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
    // tag::running[]
    try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
    consensusModuleContext);
        ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
        clusteredServiceContext)) {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
        // <3>
        barrier.await();
        System.out.println("[" + nodeId + "] Exiting");
    }
// end::running[]
}
Also used : CommonContext(io.aeron.CommonContext) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) AeronArchive(io.aeron.archive.client.AeronArchive) ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) MediaDriver(io.aeron.driver.MediaDriver) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Aggregations

Archive (io.aeron.archive.Archive)25 MediaDriver (io.aeron.driver.MediaDriver)20 AeronArchive (io.aeron.archive.client.AeronArchive)17 File (java.io.File)13 Test (org.junit.jupiter.api.Test)10 Aeron (io.aeron.Aeron)8 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)8 SlowTest (io.aeron.test.SlowTest)8 CommonContext (io.aeron.CommonContext)7 ArchivingMediaDriver (io.aeron.archive.ArchivingMediaDriver)6 Tests (io.aeron.test.Tests)6 AtomicCounter (org.agrona.concurrent.status.AtomicCounter)6 Counter (io.aeron.Counter)4 ArchiveThreadingMode (io.aeron.archive.ArchiveThreadingMode)4 AeronCluster (io.aeron.cluster.client.AeronCluster)4 EgressListener (io.aeron.cluster.client.EgressListener)4 ClientSession (io.aeron.cluster.service.ClientSession)4 ThreadingMode (io.aeron.driver.ThreadingMode)4 Header (io.aeron.logbuffer.Header)4 InterruptAfter (io.aeron.test.InterruptAfter)4