Search in sources :

Example 1 with ClusterConfiguration

use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.

the class ObservedClusterMembersTest method clusterConfiguration.

private ClusterConfiguration clusterConfiguration(URI... uris) {
    LogProvider logProvider = FormattedLogProvider.toOutputStream(System.out);
    ClusterConfiguration toReturn = new ClusterConfiguration("neo4j.ha", logProvider, asList(uris));
    toReturn.joined(clusterId1, clusterUri1);
    toReturn.joined(clusterId2, clusterUri2);
    if (uris.length == 3) {
        toReturn.joined(clusterId3, clusterUri3);
    }
    return toReturn;
}
Also used : LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) FormattedLogProvider(org.neo4j.logging.FormattedLogProvider) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration)

Example 2 with ClusterConfiguration

use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.

the class ClusterTopologyChangesIT method failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster.

@Test
public void failedInstanceShouldReceiveCorrectCoordinatorIdUponRejoiningCluster() throws Throwable {
    // Given
    HighlyAvailableGraphDatabase initialMaster = cluster.getMaster();
    // When
    cluster.shutdown(initialMaster);
    cluster.await(masterAvailable(initialMaster));
    cluster.await(masterSeesSlavesAsAvailable(1));
    // create node on new master to ensure that it has the greatest tx id
    createNodeOn(cluster.getMaster());
    cluster.sync();
    LifeSupport life = new LifeSupport();
    ClusterClientModule clusterClient = newClusterClient(life, new InstanceId(1));
    cleanup.add(life);
    final AtomicReference<InstanceId> coordinatorIdWhenReJoined = new AtomicReference<>();
    final CountDownLatch latch = new CountDownLatch(1);
    clusterClient.clusterClient.addClusterListener(new ClusterListener.Adapter() {

        @Override
        public void enteredCluster(ClusterConfiguration clusterConfiguration) {
            coordinatorIdWhenReJoined.set(clusterConfiguration.getElected(COORDINATOR));
            latch.countDown();
        }
    });
    life.start();
    // Then
    assertTrue(latch.await(20, SECONDS));
    assertEquals(new InstanceId(2), coordinatorIdWhenReJoined.get());
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterClientModule(org.neo4j.cluster.client.ClusterClientModule) Test(org.junit.Test)

Example 3 with ClusterConfiguration

use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.

the class MultiPaxosServerFactory method newProtocolServer.

@Override
public ProtocolServer newProtocolServer(InstanceId me, TimeoutStrategy timeoutStrategy, MessageSource input, MessageSender output, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider, Executor stateMachineExecutor, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, Config config) {
    DelayedDirectExecutor executor = new DelayedDirectExecutor(logging);
    // Create state machines
    Timeouts timeouts = new Timeouts(timeoutStrategy);
    final MultiPaxosContext context = new MultiPaxosContext(me, Iterables.iterable(new ElectionRole(ClusterConfiguration.COORDINATOR)), new ClusterConfiguration(initialConfig.getName(), logging, initialConfig.getMemberURIs()), executor, logging, objectInputStreamFactory, objectOutputStreamFactory, acceptorInstanceStore, timeouts, electionCredentialsProvider, config);
    SnapshotContext snapshotContext = new SnapshotContext(context.getClusterContext(), context.getLearnerContext());
    return newProtocolServer(me, input, output, stateMachineExecutor, executor, timeouts, context, snapshotContext);
}
Also used : Timeouts(org.neo4j.cluster.timeout.Timeouts) MultiPaxosContext(org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ElectionRole(org.neo4j.cluster.protocol.election.ElectionRole) SnapshotContext(org.neo4j.cluster.protocol.snapshot.SnapshotContext)

Example 4 with ClusterConfiguration

use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.

the class ClusterJoin method joinByConfig.

private void joinByConfig() throws TimeoutException {
    List<HostnamePort> hosts = config.getInitialHosts();
    cluster.addClusterListener(new UnknownJoiningMemberWarning(hosts));
    if (hosts == null || hosts.size() == 0) {
        userLog.info("No cluster hosts specified. Creating cluster %s", config.getClusterName());
        cluster.create(config.getClusterName());
    } else {
        URI[] memberURIs = hosts.stream().map(member -> URI.create("cluster://" + resolvePortOnlyHost(member))).toArray(URI[]::new);
        while (true) {
            userLog.info("Attempting to join cluster of %s", hosts.toString());
            Future<ClusterConfiguration> clusterConfig = cluster.join(this.config.getClusterName(), memberURIs);
            try {
                ClusterConfiguration clusterConf = config.getClusterJoinTimeout() > 0 ? clusterConfig.get(config.getClusterJoinTimeout(), TimeUnit.MILLISECONDS) : clusterConfig.get();
                userLog.info("Joined cluster: %s", clusterConf);
                return;
            } catch (InterruptedException e) {
                userLog.warn("Could not join cluster, interrupted. Retrying...");
            } catch (ExecutionException e) {
                messagesLog.debug("Could not join cluster " + this.config.getClusterName());
                if (e.getCause() instanceof IllegalStateException) {
                    throw (IllegalStateException) e.getCause();
                }
                if (config.isAllowedToCreateCluster()) {
                    // Failed to join cluster, create new one
                    userLog.info("Could not join cluster of %s", hosts.toString());
                    userLog.info("Creating new cluster with name [%s]...", config.getClusterName());
                    cluster.create(config.getClusterName());
                    break;
                }
                userLog.warn("Could not join cluster, timed out. Retrying...");
            }
        }
    }
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) ProtocolServer(org.neo4j.cluster.ProtocolServer) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) Log(org.neo4j.logging.Log) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) Semaphore(java.util.concurrent.Semaphore) TimeoutException(java.util.concurrent.TimeoutException) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) LogService(org.neo4j.kernel.impl.logging.LogService) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Future(java.util.concurrent.Future) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) HostnamePort(org.neo4j.helpers.HostnamePort) URI(java.net.URI) HostnamePort(org.neo4j.helpers.HostnamePort) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI)

Example 5 with ClusterConfiguration

use of org.neo4j.cluster.protocol.cluster.ClusterConfiguration in project neo4j by neo4j.

the class ClusterContextImpl method created.

// Implementation
@Override
public void created(String name) {
    commonState.setConfiguration(new ClusterConfiguration(name, logProvider, Collections.singleton(commonState.boundAt())));
    joined();
}
Also used : ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration)

Aggregations

ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)42 InstanceId (org.neo4j.cluster.InstanceId)33 Test (org.junit.Test)29 Timeouts (org.neo4j.cluster.timeout.Timeouts)20 URI (java.net.URI)18 ClusterContext (org.neo4j.cluster.protocol.cluster.ClusterContext)18 Config (org.neo4j.kernel.configuration.Config)17 Executor (java.util.concurrent.Executor)16 MultiPaxosContext (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.context.MultiPaxosContext)16 ObjectInputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory)15 ObjectOutputStreamFactory (org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory)15 AcceptorInstanceStore (org.neo4j.cluster.protocol.atomicbroadcast.multipaxos.AcceptorInstanceStore)13 HeartbeatContext (org.neo4j.cluster.protocol.heartbeat.HeartbeatContext)13 Message (org.neo4j.cluster.com.message.Message)10 MessageHolder (org.neo4j.cluster.com.message.MessageHolder)10 DelayedDirectExecutor (org.neo4j.cluster.DelayedDirectExecutor)8 HashMap (java.util.HashMap)7 ElectionRole (org.neo4j.cluster.protocol.election.ElectionRole)7 ElectionCredentialsProvider (org.neo4j.cluster.protocol.election.ElectionCredentialsProvider)6 LinkedList (java.util.LinkedList)5