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;
}
}
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());
}
}
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()));
}
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);
}
}
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());
}
}
Aggregations