Search in sources :

Example 11 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class ReadReplicaHierarchicalCatchupIT method shouldCatchupThroughHierarchy.

@Test
public void shouldCatchupThroughHierarchy() throws Throwable {
    clusterRule = clusterRule.withInstanceReadReplicaParam(CausalClusteringSettings.server_groups, id -> serverGroups.get(id)).withInstanceCoreParam(CausalClusteringSettings.server_groups, id -> serverGroups.get(id));
    // given
    Cluster cluster = clusterRule.startCluster();
    int numberOfNodesToCreate = 100;
    cluster.coreTx((db, tx) -> {
        db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
        tx.success();
    });
    // 0, 1, 2 are core instances
    createLabelledNodesWithProperty(cluster, numberOfNodesToCreate, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
    // 3, 4 are other DCs
    ReadReplica east3 = cluster.addReadReplicaWithId(3);
    east3.start();
    ReadReplica west4 = cluster.addReadReplicaWithId(4);
    west4.start();
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
    for (CoreClusterMember coreClusterMember : cluster.coreMembers()) {
        coreClusterMember.stopCatchupServer();
    }
    // 5, 6 are other DCs
    ReadReplica east5 = cluster.addReadReplicaWithId(5);
    east5.setUpstreamDatabaseSelectionStrategy("connect-within-data-center");
    east5.start();
    ReadReplica west6 = cluster.addReadReplicaWithId(6);
    west6.setUpstreamDatabaseSelectionStrategy("connect-within-data-center");
    west6.start();
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
}
Also used : Iterables.count(org.neo4j.helpers.collection.Iterables.count) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) Test(org.junit.Test) HashMap(java.util.HashMap) UUID(java.util.UUID) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Label.label(org.neo4j.graphdb.Label.label) Pair(org.neo4j.helpers.collection.Pair) DataCreator.createLabelledNodesWithProperty(org.neo4j.causalclustering.helpers.DataCreator.createLabelledNodesWithProperty) Cluster(org.neo4j.causalclustering.discovery.Cluster) Rule(org.junit.Rule) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Before(org.junit.Before) ReadReplicaToReadReplicaCatchupIT.checkDataHasReplicatedToReadReplicas(org.neo4j.causalclustering.scenarios.ReadReplicaToReadReplicaCatchupIT.checkDataHasReplicatedToReadReplicas) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 12 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class ReadReplicaReplicationIT method shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning.

@Test
public void shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning() throws Exception {
    // given
    Map<String, String> params = stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "keep_none", GraphDatabaseSettings.logical_log_rotation_threshold.name(), "1M", GraphDatabaseSettings.check_point_interval_time.name(), "100ms");
    Cluster cluster = clusterRule.withSharedCoreParams(params).startCluster();
    cluster.coreTx((db, tx) -> {
        createData(db, 10);
        tx.success();
    });
    awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
    ReadReplica readReplica = cluster.getReadReplicaById(0);
    long highestReadReplicaLogVersion = physicalLogFiles(readReplica).getHighestLogVersion();
    readReplica.shutdown();
    CoreClusterMember core;
    do {
        core = cluster.coreTx((db, tx) -> {
            createData(db, 1_000);
            tx.success();
        });
    } while (physicalLogFiles(core).getLowestLogVersion() <= highestReadReplicaLogVersion);
    readReplica.start();
    awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
    // when
    cluster.coreTx((db, tx) -> {
        createData(db, 10);
        tx.success();
    });
    // then
    assertEventually("The read replica has the same data as the core members", () -> DbRepresentation.of(readReplica.database()), equalTo(DbRepresentation.of(cluster.awaitLeader().database())), 10, TimeUnit.SECONDS);
}
Also used : ResourceIterator(org.neo4j.graphdb.ResourceIterator) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) Log(org.neo4j.logging.Log) CausalClusteringSettings(org.neo4j.causalclustering.core.CausalClusteringSettings) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) ThrowingSupplier(org.neo4j.function.ThrowingSupplier) HighLimit(org.neo4j.kernel.impl.store.format.highlimit.HighLimit) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) Transaction(org.neo4j.graphdb.Transaction) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) PageCache(org.neo4j.io.pagecache.PageCache) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) Set(java.util.Set) BinaryOperator(java.util.function.BinaryOperator) UnsatisfiedDependencyException(org.neo4j.kernel.impl.util.UnsatisfiedDependencyException) Cluster(org.neo4j.causalclustering.discovery.Cluster) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) CoreGraphDatabase(org.neo4j.causalclustering.core.CoreGraphDatabase) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) TransactionIdTracker(org.neo4j.kernel.api.txtracking.TransactionIdTracker) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Predicates.awaitEx(org.neo4j.function.Predicates.awaitEx) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) Role(org.neo4j.causalclustering.core.consensus.roles.Role) ClusterMember(org.neo4j.causalclustering.discovery.ClusterMember) Label(org.neo4j.graphdb.Label) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) Iterables.count(org.neo4j.helpers.collection.Iterables.count) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) MINUTES(java.util.concurrent.TimeUnit.MINUTES) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) Duration.ofSeconds(java.time.Duration.ofSeconds) Function(java.util.function.Function) Node(org.neo4j.graphdb.Node) HashSet(java.util.HashSet) CatchupPollingProcess(org.neo4j.causalclustering.catchup.tx.CatchupPollingProcess) LifecycleException(org.neo4j.kernel.lifecycle.LifecycleException) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TIME(org.neo4j.kernel.impl.store.MetaDataStore.Position.TIME) BiConsumer(java.util.function.BiConsumer) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) FileNames(org.neo4j.causalclustering.core.consensus.log.segmented.FileNames) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles) FileCopyMonitor(org.neo4j.causalclustering.catchup.tx.FileCopyMonitor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) SampleData.createData(org.neo4j.causalclustering.scenarios.SampleData.createData) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DbRepresentation(org.neo4j.test.DbRepresentation) Clock(java.time.Clock) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 13 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class ServerGroupsIT method shouldUpdateGroupsOnStart.

@Test
public void shouldUpdateGroupsOnStart() throws Exception {
    AtomicReference<String> suffix = new AtomicReference<>("before");
    List<List<String>> expected;
    Map<String, IntFunction<String>> instanceCoreParams = new HashMap<>();
    instanceCoreParams.put(CausalClusteringSettings.server_groups.name(), (id) -> String.join(", ", makeCoreGroups(suffix.get(), id)));
    Map<String, IntFunction<String>> instanceReplicaParams = new HashMap<>();
    instanceReplicaParams.put(CausalClusteringSettings.server_groups.name(), (id) -> String.join(", ", makeReplicaGroups(suffix.get(), id)));
    int nServers = 3;
    cluster = new Cluster(testDir.directory("cluster"), nServers, nServers, new HazelcastDiscoveryServiceFactory(), emptyMap(), instanceCoreParams, emptyMap(), instanceReplicaParams, Standard.LATEST_NAME);
    // when
    cluster.start();
    // then
    expected = new ArrayList<>();
    for (CoreClusterMember core : cluster.coreMembers()) {
        expected.add(makeCoreGroups(suffix.get(), core.serverId()));
        expected.add(makeReplicaGroups(suffix.get(), core.serverId()));
    }
    for (CoreClusterMember core : cluster.coreMembers()) {
        assertEventually(core + " should have groups", () -> getServerGroups(core.database()), new GroupsMatcher(expected), 30, SECONDS);
    }
    // when
    expected.remove(makeCoreGroups(suffix.get(), 1));
    expected.remove(makeReplicaGroups(suffix.get(), 2));
    cluster.getCoreMemberById(1).shutdown();
    cluster.getReadReplicaById(2).shutdown();
    // should update groups of restarted servers
    suffix.set("after");
    cluster.addCoreMemberWithId(1).start();
    cluster.addReadReplicaWithId(2).start();
    expected.add(makeCoreGroups(suffix.get(), 1));
    expected.add(makeReplicaGroups(suffix.get(), 2));
    // then
    for (CoreClusterMember core : cluster.coreMembers()) {
        assertEventually(core + " should have groups", () -> getServerGroups(core.database()), new GroupsMatcher(expected), 30, SECONDS);
    }
}
Also used : HashMap(java.util.HashMap) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Cluster(org.neo4j.causalclustering.discovery.Cluster) AtomicReference(java.util.concurrent.atomic.AtomicReference) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) IntFunction(java.util.function.IntFunction) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Example 14 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class TransactionLogRecoveryIT method coreShouldStartWithSeedHavingPartialTransactionWriteCrash.

@Test
public void coreShouldStartWithSeedHavingPartialTransactionWriteCrash() throws Exception {
    // given: a fully synced cluster with some data
    dataMatchesEventually(createEmptyNodes(cluster, 10), cluster.coreMembers());
    // when: shutting down a core
    CoreClusterMember core = cluster.getCoreMemberById(0);
    core.shutdown();
    // and making sure there will be something new to pull
    CoreClusterMember lastWrites = createEmptyNodes(cluster, 10);
    // and writing a partial tx
    writePartialTx(core.storeDir());
    // and deleting the cluster state, making sure a snapshot is required during startup
    // effectively a seeding scenario -- representing the use of the unbind command on a crashed store
    fs.deleteRecursively(core.clusterStateDirectory());
    // then: we should still be able to start
    core.start();
    // and become fully synced again
    dataMatchesEventually(lastWrites, singletonList(core));
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Test(org.junit.Test)

Example 15 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember in project neo4j by neo4j.

the class ClusterFormationIT method shouldSupportBuiltInProcedures.

@Test
public void shouldSupportBuiltInProcedures() throws Exception {
    cluster.addReadReplicaWithId(0).start();
    Stream.concat(cluster.readReplicas().stream().map(ReadReplica::database), cluster.coreMembers().stream().map(CoreClusterMember::database)).forEach(gdb -> {
        {
            Result result = gdb.execute("CALL dbms.procedures()");
            assertTrue(result.hasNext());
            result.close();
        }
        try (InternalTransaction tx = gdb.beginTransaction(KernelTransaction.Type.explicit, EnterpriseSecurityContext.AUTH_DISABLED)) {
            Result result = gdb.execute(tx, "CALL dbms.listQueries()", Collections.emptyMap());
            assertTrue(result.hasNext());
            result.close();
            tx.success();
        }
    });
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)45 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)45 Cluster (org.neo4j.causalclustering.discovery.Cluster)20 Node (org.neo4j.graphdb.Node)16 File (java.io.File)12 ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)11 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)10 Driver (org.neo4j.driver.v1.Driver)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (org.neo4j.driver.v1.Session)9 Rule (org.junit.Rule)8 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)8 TimeUnit (java.util.concurrent.TimeUnit)7 Transaction (org.neo4j.graphdb.Transaction)7 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)6 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Role (org.neo4j.causalclustering.core.consensus.roles.Role)5