Search in sources :

Example 1 with MinMulticastFlowControlSupplier

use of io.aeron.driver.MinMulticastFlowControlSupplier in project Aeron by real-logic.

the class MinFlowControlSystemTest method shouldRemoveDeadTaggedReceiverWithMinMulticastFlowControlStrategy.

@Test
@InterruptAfter(10)
void shouldRemoveDeadTaggedReceiverWithMinMulticastFlowControlStrategy() {
    final int numMessagesToSend = NUM_MESSAGES_PER_TERM * 3;
    int numMessagesLeftToSend = numMessagesToSend;
    int numFragmentsReadFromA = 0, numFragmentsReadFromB = 0;
    driverBContext.imageLivenessTimeoutNs(TimeUnit.MILLISECONDS.toNanos(500));
    driverAContext.multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
    launch();
    subscriptionA = clientA.addSubscription(MULTICAST_URI, STREAM_ID);
    subscriptionB = clientB.addSubscription(MULTICAST_URI, STREAM_ID);
    publication = clientA.addPublication(MULTICAST_URI, STREAM_ID);
    while (!subscriptionA.isConnected() || !subscriptionB.isConnected() || !publication.isConnected()) {
        Tests.yield();
    }
    boolean isBClosed = false;
    while (numFragmentsReadFromA < numMessagesToSend) {
        if (numMessagesLeftToSend > 0) {
            if (publication.offer(buffer, 0, buffer.capacity()) >= 0L) {
                numMessagesLeftToSend--;
            }
        }
        // A keeps up
        numFragmentsReadFromA += subscriptionA.poll(fragmentHandlerA, 10);
        // B receives up to 1/8 of the messages, then stops
        if (numFragmentsReadFromB < (numMessagesToSend / 8)) {
            numFragmentsReadFromB += subscriptionB.poll(fragmentHandlerB, 10);
        } else if (!isBClosed) {
            subscriptionB.close();
            isBClosed = true;
        }
    }
    verify(fragmentHandlerA, times(numMessagesToSend)).onFragment(any(DirectBuffer.class), anyInt(), eq(MESSAGE_LENGTH), any(Header.class));
}
Also used : DirectBuffer(org.agrona.DirectBuffer) Header(io.aeron.logbuffer.Header) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with MinMulticastFlowControlSupplier

use of io.aeron.driver.MinMulticastFlowControlSupplier in project aeron by real-logic.

the class ClusterConfig method create.

/**
 * Create a new ClusterConfig. This call allows for 2 separate lists of hostnames, so that there can be 'external'
 * addresses for ingress requests and 'internal' addresses that will handle all the cluster replication and
 * control traffic.
 *
 * @param nodeId                id for this node.
 * @param ingressHostnames      list of hostnames that will receive ingress request traffic.
 * @param clusterHostnames      list of hostnames that will receive cluster traffic.
 * @param portBase              base port to derive remaining ports from.
 * @param clusteredService      instance of the clustered service that will run with this configuration.
 * @param additionalServices    instances of additional clustered services that will run with this configuration.
 * @return                      configuration that wraps all aeron service configuration.
 */
public static ClusterConfig create(final int nodeId, final List<String> ingressHostnames, final List<String> clusterHostnames, final int portBase, final ClusteredService clusteredService, final ClusteredService... additionalServices) {
    if (nodeId >= ingressHostnames.size()) {
        throw new IllegalArgumentException("nodeId=" + nodeId + " >= ingressHostnames.size()=" + ingressHostnames.size());
    }
    final String clusterMembers = clusterMembers(ingressHostnames, clusterHostnames, portBase);
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
    final File baseDir = new File(System.getProperty("user.dir"), "aeron-cluster-" + nodeId);
    final String hostname = clusterHostnames.get(nodeId);
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
    final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
    final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, ARCHIVE_SUB_DIR)).controlChannel(udpChannel(nodeId, hostname, portBase, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlRequestStreamId(archiveContext.localControlStreamId()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().clusterMemberId(nodeId).clusterMembers(clusterMembers).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).archiveContext(aeronArchiveContext.clone()).serviceCount(1 + additionalServices.length).replicationChannel("aeron:udp?endpoint=" + hostname + ":0");
    final List<ClusteredServiceContainer.Context> serviceContexts = new ArrayList<>();
    final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(clusteredService).serviceId(0);
    serviceContexts.add(clusteredServiceContext);
    for (int i = 0; i < additionalServices.length; i++) {
        final ClusteredServiceContainer.Context additionalServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(additionalServices[i]).serviceId(i + 1);
        serviceContexts.add(additionalServiceContext);
    }
    return new ClusterConfig(mediaDriverContext, archiveContext, aeronArchiveContext, consensusModuleContext, serviceContexts);
}
Also used : CommonContext(io.aeron.CommonContext) Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) ArrayList(java.util.ArrayList) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 3 with MinMulticastFlowControlSupplier

use of io.aeron.driver.MinMulticastFlowControlSupplier 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 4 with MinMulticastFlowControlSupplier

use of io.aeron.driver.MinMulticastFlowControlSupplier 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 5 with MinMulticastFlowControlSupplier

use of io.aeron.driver.MinMulticastFlowControlSupplier in project Aeron by real-logic.

the class ClusterConfig method create.

/**
 * Create a new ClusterConfig. This call allows for 2 separate lists of hostnames, so that there can be 'external'
 * addresses for ingress requests and 'internal' addresses that will handle all the cluster replication and
 * control traffic.
 *
 * @param nodeId                id for this node.
 * @param ingressHostnames      list of hostnames that will receive ingress request traffic.
 * @param clusterHostnames      list of hostnames that will receive cluster traffic.
 * @param portBase              base port to derive remaining ports from.
 * @param clusteredService      instance of the clustered service that will run with this configuration.
 * @param additionalServices    instances of additional clustered services that will run with this configuration.
 * @return                      configuration that wraps all aeron service configuration.
 */
public static ClusterConfig create(final int nodeId, final List<String> ingressHostnames, final List<String> clusterHostnames, final int portBase, final ClusteredService clusteredService, final ClusteredService... additionalServices) {
    if (nodeId >= ingressHostnames.size()) {
        throw new IllegalArgumentException("nodeId=" + nodeId + " >= ingressHostnames.size()=" + ingressHostnames.size());
    }
    final String clusterMembers = clusterMembers(ingressHostnames, clusterHostnames, portBase);
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
    final File baseDir = new File(System.getProperty("user.dir"), "aeron-cluster-" + nodeId);
    final String hostname = clusterHostnames.get(nodeId);
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier());
    final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
    final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, ARCHIVE_SUB_DIR)).controlChannel(udpChannel(nodeId, hostname, portBase, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlRequestStreamId(archiveContext.localControlStreamId()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().clusterMemberId(nodeId).clusterMembers(clusterMembers).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).archiveContext(aeronArchiveContext.clone()).serviceCount(1 + additionalServices.length).replicationChannel("aeron:udp?endpoint=" + hostname + ":0");
    final List<ClusteredServiceContainer.Context> serviceContexts = new ArrayList<>();
    final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(clusteredService).serviceId(0);
    serviceContexts.add(clusteredServiceContext);
    for (int i = 0; i < additionalServices.length; i++) {
        final ClusteredServiceContainer.Context additionalServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(aeronDirName).archiveContext(aeronArchiveContext.clone()).clusterDir(new File(baseDir, CLUSTER_SUB_DIR)).clusteredService(additionalServices[i]).serviceId(i + 1);
        serviceContexts.add(additionalServiceContext);
    }
    return new ClusterConfig(mediaDriverContext, archiveContext, aeronArchiveContext, consensusModuleContext, serviceContexts);
}
Also used : CommonContext(io.aeron.CommonContext) Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) ArrayList(java.util.ArrayList) AeronArchive(io.aeron.archive.client.AeronArchive) MediaDriver(io.aeron.driver.MediaDriver) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Aggregations

MinMulticastFlowControlSupplier (io.aeron.driver.MinMulticastFlowControlSupplier)7 CommonContext (io.aeron.CommonContext)5 Archive (io.aeron.archive.Archive)5 AeronArchive (io.aeron.archive.client.AeronArchive)5 File (java.io.File)5 ConsensusModule (io.aeron.cluster.ConsensusModule)4 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)4 MediaDriver (io.aeron.driver.MediaDriver)4 ClusteredMediaDriver (io.aeron.cluster.ClusteredMediaDriver)2 Header (io.aeron.logbuffer.Header)2 ArrayList (java.util.ArrayList)2 DirectBuffer (org.agrona.DirectBuffer)2 ShutdownSignalBarrier (org.agrona.concurrent.ShutdownSignalBarrier)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 NoOpLock (org.agrona.concurrent.NoOpLock)1