Search in sources :

Example 1 with DefaultSlaveFactory

use of org.neo4j.kernel.ha.com.master.DefaultSlaveFactory in project neo4j by neo4j.

the class HighAvailabilitySlavesTest method shouldSupportConcurrentConsumptionOfSlaves.

@Test
public void shouldSupportConcurrentConsumptionOfSlaves() throws Exception {
    // Given
    LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
    HighAvailabilitySlaves haSlaves = new HighAvailabilitySlaves(clusterMembersOfSize(1000), mock(Cluster.class), new DefaultSlaveFactory(NullLogProvider.getInstance(), new Monitors(), 42, Suppliers.singleton(logEntryReader)), new HostnamePort(null, 0));
    // When
    ExecutorService executor = Executors.newFixedThreadPool(5);
    for (int i = 0; i < 5; i++) {
        executor.submit(slavesConsumingRunnable(haSlaves));
    }
    executor.shutdown();
    executor.awaitTermination(30, SECONDS);
    // Then
    int slavesCount = 0;
    LifeSupport life = ReflectionUtil.getPrivateField(haSlaves, "life", LifeSupport.class);
    for (Lifecycle lifecycle : life.getLifecycleInstances()) {
        if (lifecycle instanceof Slave) {
            slavesCount++;
        }
    }
    // One instance is master
    assertEquals("Unexpected number of slaves", 1000 - 1, slavesCount);
}
Also used : HostnamePort(org.neo4j.helpers.HostnamePort) Lifecycle(org.neo4j.kernel.lifecycle.Lifecycle) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) Slave(org.neo4j.kernel.ha.com.master.Slave) Monitors(org.neo4j.kernel.monitoring.Monitors) ExecutorService(java.util.concurrent.ExecutorService) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) Test(org.junit.Test)

Example 2 with DefaultSlaveFactory

use of org.neo4j.kernel.ha.com.master.DefaultSlaveFactory in project neo4j by neo4j.

the class HighlyAvailableEditionModule method createCommitProcessFactory.

private CommitProcessFactory createCommitProcessFactory(Dependencies dependencies, LogService logging, Monitors monitors, Config config, LifeSupport paxosLife, ClusterClient clusterClient, ClusterMembers members, JobScheduler jobScheduler, Master master, RequestContextFactory requestContextFactory, ComponentSwitcherContainer componentSwitcherContainer, Supplier<LogEntryReader<ReadableClosablePositionAwareChannel>> logEntryReader) {
    DefaultSlaveFactory slaveFactory = dependencies.satisfyDependency(new DefaultSlaveFactory(logging.getInternalLogProvider(), monitors, config.get(HaSettings.com_chunk_size).intValue(), logEntryReader));
    HostnamePort me = config.get(ClusterSettings.cluster_server);
    Slaves slaves = dependencies.satisfyDependency(paxosLife.add(new HighAvailabilitySlaves(members, clusterClient, slaveFactory, me)));
    TransactionPropagator transactionPropagator = new TransactionPropagator(TransactionPropagator.from(config), logging.getInternalLog(TransactionPropagator.class), slaves, new CommitPusher(jobScheduler));
    paxosLife.add(transactionPropagator);
    DelegateInvocationHandler<TransactionCommitProcess> commitProcessDelegate = new DelegateInvocationHandler<>(TransactionCommitProcess.class);
    CommitProcessSwitcher commitProcessSwitcher = new CommitProcessSwitcher(transactionPropagator, master, commitProcessDelegate, requestContextFactory, lockManager, monitors, dependencies, config.get(GraphDatabaseSettings.release_schema_lock_while_building_constraint));
    componentSwitcherContainer.add(commitProcessSwitcher);
    return new HighlyAvailableCommitProcessFactory(commitProcessDelegate);
}
Also used : TransactionPropagator(org.neo4j.kernel.ha.transaction.TransactionPropagator) CommitPusher(org.neo4j.kernel.ha.transaction.CommitPusher) HostnamePort(org.neo4j.helpers.HostnamePort) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) DefaultSlaveFactory(org.neo4j.kernel.ha.com.master.DefaultSlaveFactory) DelegateInvocationHandler(org.neo4j.kernel.ha.DelegateInvocationHandler) CommitProcessSwitcher(org.neo4j.kernel.ha.cluster.modeswitch.CommitProcessSwitcher) HighAvailabilitySlaves(org.neo4j.kernel.ha.cluster.member.HighAvailabilitySlaves) Slaves(org.neo4j.kernel.ha.com.master.Slaves) HighAvailabilitySlaves(org.neo4j.kernel.ha.cluster.member.HighAvailabilitySlaves)

Aggregations

HostnamePort (org.neo4j.helpers.HostnamePort)2 DefaultSlaveFactory (org.neo4j.kernel.ha.com.master.DefaultSlaveFactory)2 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.Test)1 Cluster (org.neo4j.cluster.protocol.cluster.Cluster)1 DelegateInvocationHandler (org.neo4j.kernel.ha.DelegateInvocationHandler)1 HighAvailabilitySlaves (org.neo4j.kernel.ha.cluster.member.HighAvailabilitySlaves)1 CommitProcessSwitcher (org.neo4j.kernel.ha.cluster.modeswitch.CommitProcessSwitcher)1 Slave (org.neo4j.kernel.ha.com.master.Slave)1 Slaves (org.neo4j.kernel.ha.com.master.Slaves)1 CommitPusher (org.neo4j.kernel.ha.transaction.CommitPusher)1 TransactionPropagator (org.neo4j.kernel.ha.transaction.TransactionPropagator)1 TransactionCommitProcess (org.neo4j.kernel.impl.api.TransactionCommitProcess)1 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)1 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)1 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)1 Lifecycle (org.neo4j.kernel.lifecycle.Lifecycle)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1