Search in sources :

Example 11 with Archive

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

the class ClusteredMediaDriver method launch.

/**
 * Launch a new {@link ClusteredMediaDriver} with provided contexts.
 *
 * @param driverCtx          for configuring the {@link MediaDriver}.
 * @param archiveCtx         for configuring the {@link Archive}.
 * @param consensusModuleCtx for the configuration of the {@link ConsensusModule}.
 * @return a new {@link ClusteredMediaDriver} with the provided contexts.
 */
public static ClusteredMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx, final ConsensusModule.Context consensusModuleCtx) {
    MediaDriver driver = null;
    Archive archive = null;
    ConsensusModule consensusModule = null;
    try {
        driver = MediaDriver.launch(driverCtx);
        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.mediaDriverAgentInvoker(driver.sharedAgentInvoker()).aeronDirectoryName(driver.aeronDirectoryName()).errorHandler(errorHandler).errorCounter(errorCounter));
        consensusModule = ConsensusModule.launch(consensusModuleCtx.aeronDirectoryName(driverCtx.aeronDirectoryName()));
        return new ClusteredMediaDriver(driver, archive, consensusModule);
    } catch (final Exception ex) {
        CloseHelper.quietCloseAll(consensusModule, 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 12 with Archive

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

the class MultiModuleSharedDriverTest method shouldSupportTwoSingleNodeClusters.

@Test
@InterruptAfter(20)
@SuppressWarnings({ "try", "methodlength" })
public void shouldSupportTwoSingleNodeClusters() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)).dirDeleteOnShutdown(false).dirDeleteOnStart(true);
    final Archive.Context archiveCtx = new Archive.Context().threadingMode(ArchiveThreadingMode.SHARED).archiveDir(new File(SystemUtil.tmpDirName(), "archive")).recordingEventsEnabled(false).deleteArchiveOnStart(true);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) {
        final ConsensusModule.Context moduleCtx0 = new ConsensusModule.Context().clusterId(0).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-0")).logChannel("aeron:ipc?term-length=64k").logStreamId(100).serviceStreamId(104).consensusModuleStreamId(105).ingressChannel("aeron:udp?endpoint=localhost:9020").replicationChannel("aeron:udp?endpoint=localhost:0");
        final ClusteredServiceContainer.Context containerCtx0 = new ClusteredServiceContainer.Context().clusterId(moduleCtx0.clusterId()).clusteredService(new EchoService()).clusterDir(moduleCtx0.clusterDir()).serviceStreamId(moduleCtx0.serviceStreamId()).consensusModuleStreamId(moduleCtx0.consensusModuleStreamId());
        final ConsensusModule.Context moduleCtx1 = new ConsensusModule.Context().clusterId(1).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-1")).logChannel("aeron:ipc?term-length=64k").logStreamId(200).serviceStreamId(204).consensusModuleStreamId(205).ingressChannel("aeron:udp?endpoint=localhost:9021").replicationChannel("aeron:udp?endpoint=localhost:0");
        final ClusteredServiceContainer.Context containerCtx1 = new ClusteredServiceContainer.Context().clusteredService(new EchoService()).clusterDir(moduleCtx1.clusterDir()).serviceStreamId(moduleCtx1.serviceStreamId()).consensusModuleStreamId(moduleCtx1.consensusModuleStreamId()).clusterId(moduleCtx1.clusterId());
        ConsensusModule consensusModule0 = null;
        ClusteredServiceContainer container0 = null;
        ConsensusModule consensusModule1 = null;
        ClusteredServiceContainer container1 = null;
        AeronCluster client0 = null;
        AeronCluster client1 = null;
        try {
            consensusModule0 = ConsensusModule.launch(moduleCtx0);
            consensusModule1 = ConsensusModule.launch(moduleCtx1);
            container0 = ClusteredServiceContainer.launch(containerCtx0);
            container1 = ClusteredServiceContainer.launch(containerCtx1);
            final MutableReference<String> egress = new MutableReference<>();
            final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
            client0 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx0.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
            client1 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx1.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
            echoMessage(client0, "Message 0", egress);
            echoMessage(client1, "Message 1", egress);
        } finally {
            systemTestWatcher.dataCollector().add(moduleCtx0.clusterDir());
            systemTestWatcher.dataCollector().add(moduleCtx1.clusterDir());
            CloseHelper.closeAll(client0, client1, consensusModule0, consensusModule1, container0, container1);
        }
    } finally {
        systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
        systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
    }
}
Also used : CommonContext(io.aeron.CommonContext) AeronCluster(io.aeron.cluster.client.AeronCluster) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) io.aeron.test(io.aeron.test) SystemUtil(org.agrona.SystemUtil) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) MutableReference(org.agrona.collections.MutableReference) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) CommonContext(io.aeron.CommonContext) File(java.io.File) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) TestCluster(io.aeron.test.cluster.TestCluster) DirectBuffer(org.agrona.DirectBuffer) Archive(io.aeron.archive.Archive) AeronCluster(io.aeron.cluster.client.AeronCluster) MutableReference(org.agrona.collections.MutableReference) EgressListener(io.aeron.cluster.client.EgressListener) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) File(java.io.File) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) Test(org.junit.jupiter.api.Test)

Example 13 with Archive

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

the class ClusterTest method before.

@Before
public void before() {
    final String aeronDirName = CommonContext.getAeronDirectoryName();
    for (int i = 0; i < MEMBER_COUNT; i++) {
        echoServices[i] = new EchoService(latch);
        final String baseDirName = aeronDirName + "-" + i;
        final AeronArchive.Context archiveCtx = new AeronArchive.Context().controlRequestChannel(memberSpecificPort(ARCHIVE_CONTROL_REQUEST_CHANNEL, i)).controlRequestStreamId(100 + i).controlResponseChannel(memberSpecificPort(ARCHIVE_CONTROL_RESPONSE_CHANNEL, i)).controlResponseStreamId(110 + i).aeronDirectoryName(baseDirName);
        drivers[i] = ClusteredMediaDriver.launch(new MediaDriver.Context().aeronDirectoryName(baseDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).errorHandler(Throwable::printStackTrace).dirDeleteOnStart(true), new Archive.Context().maxCatalogEntries(MAX_CATALOG_ENTRIES).aeronDirectoryName(baseDirName).archiveDir(new File(baseDirName, "archive")).controlChannel(archiveCtx.controlRequestChannel()).controlStreamId(archiveCtx.controlRequestStreamId()).localControlChannel("aeron:ipc?term-length=64k").localControlStreamId(archiveCtx.controlRequestStreamId()).threadingMode(ArchiveThreadingMode.SHARED).deleteArchiveOnStart(true), new ConsensusModule.Context().clusterMemberId(i).clusterMembers(CLUSTER_MEMBERS).appointedLeaderId(0).aeronDirectoryName(baseDirName).clusterDir(new File(baseDirName, "consensus-module")).ingressChannel("aeron:udp?term-length=64k").logChannel(memberSpecificPort(LOG_CHANNEL, i)).archiveContext(archiveCtx.clone()).deleteDirOnStart(true));
        containers[i] = ClusteredServiceContainer.launch(new ClusteredServiceContainer.Context().aeronDirectoryName(baseDirName).archiveContext(archiveCtx.clone()).clusteredServiceDir(new File(baseDirName, "service")).clusteredService(echoServices[i]).errorHandler(Throwable::printStackTrace).deleteDirOnStart(true));
    }
    client = AeronCluster.connect(new AeronCluster.Context().aeronDirectoryName(aeronDirName + "-0").ingressChannel("aeron:udp").clusterMemberEndpoints("localhost:20110", "localhost:20111", "localhost:20112").lock(new NoOpLock()));
}
Also used : CommonContext(io.aeron.CommonContext) NoOpLock(org.agrona.concurrent.NoOpLock) AeronArchive(io.aeron.archive.client.AeronArchive) Archive(io.aeron.archive.Archive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) AeronArchive(io.aeron.archive.client.AeronArchive) File(java.io.File)

Example 14 with Archive

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

the class ClusterLoggingAgentTest method testClusterEventsLogging.

private void testClusterEventsLogging(final String enabledEvents, final EnumSet<ClusterEventCode> expectedEvents) {
    before(enabledEvents, expectedEvents);
    final Context mediaDriverCtx = new Context().errorHandler(Tests::onError).dirDeleteOnStart(true).threadingMode(ThreadingMode.SHARED);
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().controlRequestChannel("aeron:ipc?term-length=64k").controlRequestStreamId(AeronArchive.Configuration.localControlStreamId()).controlResponseChannel("aeron:ipc?term-length=64k").controlResponseStreamId(AeronArchive.Configuration.localControlStreamId() + 1).controlResponseStreamId(101);
    final Archive.Context archiveCtx = new Archive.Context().errorHandler(Tests::onError).archiveDir(new File(testDir, "archive")).deleteArchiveOnStart(true).recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    final ConsensusModule.Context consensusModuleCtx = new ConsensusModule.Context().errorHandler(ClusterTests.errorHandler(0)).clusterDir(new File(testDir, "consensus-module")).archiveContext(aeronArchiveContext.clone()).clusterMemberId(0).clusterMembers("0,localhost:20110,localhost:20220,localhost:20330,localhost:20440,localhost:8010").logChannel("aeron:udp?term-length=256k|control-mode=manual|control=localhost:20550").ingressChannel("aeron:udp?term-length=64k").replicationChannel("aeron:udp?endpoint=localhost:0");
    final ClusteredService clusteredService = mock(ClusteredService.class);
    final ClusteredServiceContainer.Context clusteredServiceCtx = new ClusteredServiceContainer.Context().errorHandler(ClusterTests.errorHandler(0)).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(testDir, "service")).clusteredService(clusteredService);
    clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverCtx, archiveCtx, consensusModuleCtx);
    container = ClusteredServiceContainer.launch(clusteredServiceCtx);
    Tests.await(WAIT_LIST::isEmpty);
    final Counter state = clusteredMediaDriver.consensusModule().context().electionStateCounter();
    final Supplier<String> message = () -> ElectionState.get(state).toString();
    while (ElectionState.CLOSED != ElectionState.get(state)) {
        Tests.sleep(1, message);
    }
}
Also used : Context(io.aeron.driver.MediaDriver.Context) AeronArchive(io.aeron.archive.client.AeronArchive) Archive(io.aeron.archive.Archive) ClusteredService(io.aeron.cluster.service.ClusteredService) AeronArchive(io.aeron.archive.client.AeronArchive) ClusterTests(io.aeron.test.cluster.ClusterTests) Tests(io.aeron.test.Tests) Counter(io.aeron.Counter) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 15 with Archive

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

the class MultiModuleSharedDriverTest method shouldSupportTwoSingleNodeClusters.

@Test
@InterruptAfter(20)
@SuppressWarnings({ "try", "methodlength" })
public void shouldSupportTwoSingleNodeClusters() {
    final MediaDriver.Context driverCtx = new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).nameResolver(new RedirectingNameResolver(TestCluster.DEFAULT_NODE_MAPPINGS)).dirDeleteOnShutdown(false).dirDeleteOnStart(true);
    final Archive.Context archiveCtx = new Archive.Context().threadingMode(ArchiveThreadingMode.SHARED).archiveDir(new File(SystemUtil.tmpDirName(), "archive")).recordingEventsEnabled(false).deleteArchiveOnStart(true);
    try (ArchivingMediaDriver ignore = ArchivingMediaDriver.launch(driverCtx, archiveCtx)) {
        final ConsensusModule.Context moduleCtx0 = new ConsensusModule.Context().clusterId(0).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-0")).logChannel("aeron:ipc?term-length=64k").logStreamId(100).serviceStreamId(104).consensusModuleStreamId(105).ingressChannel("aeron:udp?endpoint=localhost:9020").replicationChannel("aeron:udp?endpoint=localhost:0");
        final ClusteredServiceContainer.Context containerCtx0 = new ClusteredServiceContainer.Context().clusterId(moduleCtx0.clusterId()).clusteredService(new EchoService()).clusterDir(moduleCtx0.clusterDir()).serviceStreamId(moduleCtx0.serviceStreamId()).consensusModuleStreamId(moduleCtx0.consensusModuleStreamId());
        final ConsensusModule.Context moduleCtx1 = new ConsensusModule.Context().clusterId(1).deleteDirOnStart(true).clusterDir(new File(SystemUtil.tmpDirName(), "cluster-0-1")).logChannel("aeron:ipc?term-length=64k").logStreamId(200).serviceStreamId(204).consensusModuleStreamId(205).ingressChannel("aeron:udp?endpoint=localhost:9021").replicationChannel("aeron:udp?endpoint=localhost:0");
        final ClusteredServiceContainer.Context containerCtx1 = new ClusteredServiceContainer.Context().clusteredService(new EchoService()).clusterDir(moduleCtx1.clusterDir()).serviceStreamId(moduleCtx1.serviceStreamId()).consensusModuleStreamId(moduleCtx1.consensusModuleStreamId()).clusterId(moduleCtx1.clusterId());
        ConsensusModule consensusModule0 = null;
        ClusteredServiceContainer container0 = null;
        ConsensusModule consensusModule1 = null;
        ClusteredServiceContainer container1 = null;
        AeronCluster client0 = null;
        AeronCluster client1 = null;
        try {
            consensusModule0 = ConsensusModule.launch(moduleCtx0);
            consensusModule1 = ConsensusModule.launch(moduleCtx1);
            container0 = ClusteredServiceContainer.launch(containerCtx0);
            container1 = ClusteredServiceContainer.launch(containerCtx1);
            final MutableReference<String> egress = new MutableReference<>();
            final EgressListener egressListener = (clusterSessionId, timestamp, buffer, offset, length, header) -> egress.set(buffer.getStringWithoutLengthAscii(offset, length));
            client0 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx0.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
            client1 = AeronCluster.connect(new AeronCluster.Context().egressListener(egressListener).ingressChannel(moduleCtx1.ingressChannel()).egressChannel("aeron:udp?endpoint=localhost:0"));
            echoMessage(client0, "Message 0", egress);
            echoMessage(client1, "Message 1", egress);
        } finally {
            systemTestWatcher.dataCollector().add(moduleCtx0.clusterDir());
            systemTestWatcher.dataCollector().add(moduleCtx1.clusterDir());
            CloseHelper.closeAll(client0, client1, consensusModule0, consensusModule1, container0, container1);
        }
    } finally {
        systemTestWatcher.dataCollector().add(driverCtx.aeronDirectory());
        systemTestWatcher.dataCollector().add(archiveCtx.archiveDir());
    }
}
Also used : CommonContext(io.aeron.CommonContext) AeronCluster(io.aeron.cluster.client.AeronCluster) StubClusteredService(io.aeron.test.cluster.StubClusteredService) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) io.aeron.test(io.aeron.test) SystemUtil(org.agrona.SystemUtil) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) MutableReference(org.agrona.collections.MutableReference) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArchiveThreadingMode(io.aeron.archive.ArchiveThreadingMode) CloseHelper(org.agrona.CloseHelper) MediaDriver(io.aeron.driver.MediaDriver) Archive(io.aeron.archive.Archive) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) CommonContext(io.aeron.CommonContext) File(java.io.File) Test(org.junit.jupiter.api.Test) EgressListener(io.aeron.cluster.client.EgressListener) Header(io.aeron.logbuffer.Header) ClientSession(io.aeron.cluster.service.ClientSession) ThreadingMode(io.aeron.driver.ThreadingMode) TestCluster(io.aeron.test.cluster.TestCluster) DirectBuffer(org.agrona.DirectBuffer) Archive(io.aeron.archive.Archive) AeronCluster(io.aeron.cluster.client.AeronCluster) MutableReference(org.agrona.collections.MutableReference) EgressListener(io.aeron.cluster.client.EgressListener) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) MediaDriver(io.aeron.driver.MediaDriver) RedirectingNameResolver(io.aeron.test.driver.RedirectingNameResolver) File(java.io.File) ArchivingMediaDriver(io.aeron.archive.ArchivingMediaDriver) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer) Test(org.junit.jupiter.api.Test)

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