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