Search in sources :

Example 46 with Cluster

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);
    }
}
Also used : Cluster(org.neo4j.causalclustering.discovery.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Test(org.junit.Test)

Example 47 with Cluster

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();
        }
    }
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Config(org.neo4j.kernel.configuration.Config) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 48 with Cluster

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));
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) HashMap(java.util.HashMap) IntFunction(java.util.function.IntFunction) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 49 with Cluster

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));
    }
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) HashMap(java.util.HashMap) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) IntFunction(java.util.function.IntFunction) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Test(org.junit.Test)

Example 50 with Cluster

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));
}
Also used : HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Aggregations

Cluster (org.neo4j.causalclustering.discovery.Cluster)52 Test (org.junit.Test)51 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)21 File (java.io.File)14 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)13 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)13 Node (org.neo4j.graphdb.Node)12 Rule (org.junit.Rule)11 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)11 IOException (java.io.IOException)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)10 Transaction (org.neo4j.graphdb.Transaction)10 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)10 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)10 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)9 Map (java.util.Map)8 TimeUnit (java.util.concurrent.TimeUnit)8 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)8 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 UnsatisfiedDependencyException (org.neo4j.kernel.impl.util.UnsatisfiedDependencyException)8