Search in sources :

Example 31 with CoreClusterMember

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

the class ReadReplicaReplicationIT method shouldBeAbleToCopyStoresFromCoreToReadReplica.

@Test
public void shouldBeAbleToCopyStoresFromCoreToReadReplica() throws Exception {
    // given
    Map<String, String> params = stringMap(CausalClusteringSettings.raft_log_rotation_size.name(), "1k", CausalClusteringSettings.raft_log_pruning_frequency.name(), "500ms", CausalClusteringSettings.state_machine_flush_window_size.name(), "1", CausalClusteringSettings.raft_log_pruning_strategy.name(), "1 entries");
    Cluster cluster = clusterRule.withNumberOfReadReplicas(0).withSharedCoreParams(params).withRecordFormat(HighLimit.NAME).startCluster();
    cluster.coreTx((db, tx) -> {
        Node node = db.createNode(Label.label("L"));
        for (int i = 0; i < 10; i++) {
            node.setProperty("prop-" + i, "this is a quite long string to get to the log limit soonish");
        }
        tx.success();
    });
    long baseVersion = versionBy(cluster.awaitLeader().raftLogDirectory(), Math::max);
    CoreClusterMember coreGraphDatabase = null;
    for (int j = 0; j < 2; j++) {
        coreGraphDatabase = cluster.coreTx((db, tx) -> {
            Node node = db.createNode(Label.label("L"));
            for (int i = 0; i < 10; i++) {
                node.setProperty("prop-" + i, "this is a quite long string to get to the log limit soonish");
            }
            tx.success();
        });
    }
    File raftLogDir = coreGraphDatabase.raftLogDirectory();
    assertEventually("pruning happened", () -> versionBy(raftLogDir, Math::min), greaterThan(baseVersion), 5, SECONDS);
    // when
    cluster.addReadReplicaWithIdAndRecordFormat(4, HighLimit.NAME).start();
    // then
    for (final ReadReplica readReplica : cluster.readReplicas()) {
        assertEventually("read replica available", () -> readReplica.database().isAvailable(0), is(true), 10, 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) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 32 with CoreClusterMember

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

the class ReadReplicaToReadReplicaCatchupIT method shouldEventuallyPullTransactionAcrossReadReplicas.

@Test
public void shouldEventuallyPullTransactionAcrossReadReplicas() throws Throwable {
    // given
    Cluster cluster = clusterRule.startCluster();
    int numberOfNodesToCreate = 100;
    cluster.coreTx((db, tx) -> {
        db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
        tx.success();
    });
    createLabelledNodesWithProperty(cluster, numberOfNodesToCreate, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
    ReadReplica firstReadReplica = cluster.addReadReplicaWithIdAndMonitors(101, new Monitors());
    firstReadReplica.start();
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
    for (CoreClusterMember coreClusterMember : cluster.coreMembers()) {
        coreClusterMember.stopCatchupServer();
    }
    // when
    upstreamFactory.setCurrent(firstReadReplica);
    ReadReplica secondReadReplica = cluster.addReadReplicaWithId(202);
    secondReadReplica.setUpstreamDatabaseSelectionStrategy("specific");
    secondReadReplica.start();
    // then
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Monitors(org.neo4j.kernel.monitoring.Monitors) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 33 with CoreClusterMember

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

the class RestartIT method shouldHaveWritableClusterAfterCompleteRestart.

@Test
public void shouldHaveWritableClusterAfterCompleteRestart() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    cluster.shutdown();
    // when
    cluster.start();
    CoreClusterMember last = cluster.coreTx((db, tx) -> {
        Node node = db.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    });
    // then
    dataMatchesEventually(last, cluster.coreMembers());
    cluster.shutdown();
}
Also used : CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 34 with CoreClusterMember

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

the class RestartIT method readReplicaTest.

@Test
public void readReplicaTest() throws Exception {
    // given
    Cluster cluster = clusterRule.withNumberOfCoreMembers(2).withNumberOfReadReplicas(1).startCluster();
    // when
    final GraphDatabaseService coreDB = cluster.awaitLeader(5, TimeUnit.SECONDS).database();
    try (Transaction tx = coreDB.beginTx()) {
        Node node = coreDB.createNode(label("boo"));
        node.setProperty("foobar", "baz_bat");
        tx.success();
    }
    cluster.addCoreMemberWithId(2).start();
    cluster.shutdown();
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        for (CoreClusterMember core : cluster.coreMembers()) {
            ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(core.storeDir(), Config.embeddedDefaults(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), fileSystem, false, new CheckConsistencyConfig(true, true, true, false));
            assertTrue("Inconsistent: " + core, result.isSuccessful());
        }
        for (ReadReplica readReplica : cluster.readReplicas()) {
            ConsistencyCheckService.Result result = new ConsistencyCheckService().runFullConsistencyCheck(readReplica.storeDir(), Config.embeddedDefaults(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), fileSystem, false, new CheckConsistencyConfig(true, true, true, false));
            assertTrue("Inconsistent: " + readReplica, result.isSuccessful());
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) CheckConsistencyConfig(org.neo4j.consistency.checking.full.CheckConsistencyConfig) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Transaction(org.neo4j.graphdb.Transaction) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Node(org.neo4j.graphdb.Node) Cluster(org.neo4j.causalclustering.discovery.Cluster) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) Test(org.junit.Test)

Example 35 with CoreClusterMember

use of org.neo4j.causalclustering.discovery.CoreClusterMember 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)

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