use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ClusterOverviewIT method shouldDiscoverNewReadReplicas.
@Test
public void shouldDiscoverNewReadReplicas() throws Exception {
// given
clusterRule.withNumberOfCoreMembers(3);
clusterRule.withNumberOfReadReplicas(3);
Cluster cluster = clusterRule.startCluster();
// when
cluster.addReadReplicaWithId(3).start();
cluster.addReadReplicaWithId(4).start();
Matcher<List<MemberInfo>> expected = allOf(containsAllMemberAddresses(cluster.coreMembers(), cluster.readReplicas()), containsRole(LEADER, 1), containsRole(FOLLOWER, 2), containsRole(READ_REPLICA, 5));
for (int coreServerId = 0; coreServerId < 3; coreServerId++) {
// then
assertEventualOverview(cluster, expected, coreServerId);
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ConvertNonCausalClusteringStoreIT method shouldReplicateTransactionToCoreMembers.
@Test
public void shouldReplicateTransactionToCoreMembers() throws Throwable {
// given
File dbDir = clusterRule.testDirectory().cleanDirectory("classic-db");
int classicNodeCount = 1024;
File classicNeo4jStore = createNeoStore(dbDir, classicNodeCount);
Cluster cluster = this.clusterRule.withRecordFormat(recordFormat).createCluster();
try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
for (CoreClusterMember core : cluster.coreMembers()) {
fileSystem.copyRecursively(classicNeo4jStore, core.storeDir());
}
}
cluster.start();
// when
cluster.coreTx((coreDB, tx) -> {
Node node = coreDB.createNode(label("boo"));
node.setProperty("foobar", "baz_bat");
tx.success();
});
cluster.addReadReplicaWithIdAndRecordFormat(4, recordFormat).start();
// then
for (final CoreClusterMember server : cluster.coreMembers()) {
CoreGraphDatabase db = server.database();
try (Transaction tx = db.beginTx()) {
ThrowingSupplier<Long, Exception> nodeCount = () -> count(db.getAllNodes());
Config config = db.getDependencyResolver().resolveDependency(Config.class);
assertEventually("node to appear on core server " + config.get(raft_advertised_address), nodeCount, greaterThan((long) classicNodeCount), 15, SECONDS);
assertEquals(classicNodeCount + 1, count(db.getAllNodes()));
tx.success();
}
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ServerPoliciesLoadBalancingIT method shouldFallOverBetweenRules.
@Test
public void shouldFallOverBetweenRules() throws Exception {
Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "core" + id + ",core");
Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "replica" + id + ",replica");
String defaultPolicy = "groups(core) -> min(3); groups(replica1,replica2) -> min(2);";
Map<String, String> coreParams = stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true", CausalClusteringSettings.load_balancing_config.name() + ".server_policies.default", defaultPolicy, CausalClusteringSettings.multi_dc_license.name(), "true");
cluster = new Cluster(testDir.directory("cluster"), 5, 5, new HazelcastDiscoveryServiceFactory(), coreParams, instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
cluster.start();
// should use the first rule: only cores for reading
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(5, 1, 4, 0));
cluster.getCoreMemberById(3).shutdown();
// one core reader is gone, but we are still fulfilling min(3)
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(4, 1, 3, 0));
cluster.getCoreMemberById(0).shutdown();
// should now fall over to the second rule: use replica1 and replica2
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 0, 2));
cluster.getReadReplicaById(0).shutdown();
// this does not affect replica1 and replica2
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 0, 2));
cluster.getReadReplicaById(1).shutdown();
// should now fall over to use the last rule: all
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3));
cluster.addCoreMemberWithId(3).start();
// should now go back to first rule
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(4, 1, 3, 0));
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ServerPoliciesLoadBalancingIT method shouldSupportSeveralPolicies.
@Test
public void shouldSupportSeveralPolicies() throws Exception {
Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "core" + id + ",core");
Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> "replica" + id + ",replica");
String defaultPolicySpec = "groups(replica0,replica1)";
String policyOneTwoSpec = "groups(replica1,replica2)";
String policyZeroTwoSpec = "groups(replica0,replica2)";
String policyAllReplicasSpec = "groups(replica); halt()";
String allPolicySpec = "all()";
Map<String, String> coreParams = stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true", CausalClusteringSettings.load_balancing_config.name() + ".server_policies.all", allPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.default", defaultPolicySpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_one_two", policyOneTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_zero_two", policyZeroTwoSpec, CausalClusteringSettings.load_balancing_config.name() + ".server_policies.policy_all_replicas", policyAllReplicasSpec, CausalClusteringSettings.multi_dc_license.name(), "true");
cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), coreParams, instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
cluster.start();
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3), policyContext("all"));
for (CoreClusterMember core : cluster.coreMembers()) {
CoreGraphDatabase db = core.database();
assertThat(getServers(db, policyContext("default")), new SpecificReplicasMatcher(0, 1));
assertThat(getServers(db, policyContext("policy_one_two")), new SpecificReplicasMatcher(1, 2));
assertThat(getServers(db, policyContext("policy_zero_two")), new SpecificReplicasMatcher(0, 2));
assertThat(getServers(db, policyContext("policy_all_replicas")), new SpecificReplicasMatcher(0, 1, 2));
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ServerPoliciesLoadBalancingIT method defaultBehaviourWithAllowReadsOnFollowers.
@Test
public void defaultBehaviourWithAllowReadsOnFollowers() throws Exception {
cluster = new Cluster(testDir.directory("cluster"), 3, 3, new HazelcastDiscoveryServiceFactory(), stringMap(CausalClusteringSettings.cluster_allow_reads_on_followers.name(), "true"), emptyMap(), emptyMap(), emptyMap(), Standard.LATEST_NAME);
cluster.start();
assertGetServersEventuallyMatchesOnAllCores(new CountsMatcher(3, 1, 2, 3));
}
Aggregations