Search in sources :

Example 16 with ReadReplica

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

the class ReadReplicaStoreCopyIT method addStoreCopyBlockingMonitor.

private static Semaphore addStoreCopyBlockingMonitor(ReadReplica readReplica) {
    DependencyResolver dependencyResolver = readReplica.database().getDependencyResolver();
    Monitors monitors = dependencyResolver.resolveDependency(Monitors.class);
    Semaphore semaphore = new Semaphore(0);
    monitors.addMonitorListener((FileCopyMonitor) file -> {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    });
    return semaphore;
}
Also used : FALSE(org.neo4j.kernel.configuration.Settings.FALSE) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) ReadReplicaGraphDatabase(org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase) Monitors(org.neo4j.kernel.monitoring.Monitors) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) ClusterRule(org.neo4j.test.causalclustering.ClusterRule) Assert.assertThat(org.junit.Assert.assertThat) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) CoreClusterMember(org.neo4j.causalclustering.discovery.CoreClusterMember) Assert.fail(org.junit.Assert.fail) FileCopyMonitor(org.neo4j.causalclustering.catchup.tx.FileCopyMonitor) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) IOException(java.io.IOException) Assert.assertEventually(org.neo4j.test.assertion.Assert.assertEventually) Cluster(org.neo4j.causalclustering.discovery.Cluster) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Rule(org.junit.Rule) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Matchers.is(org.hamcrest.Matchers.is) GraphDatabaseSettings(org.neo4j.graphdb.factory.GraphDatabaseSettings) Matchers.containsString(org.hamcrest.Matchers.containsString) ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Monitors(org.neo4j.kernel.monitoring.Monitors) Semaphore(java.util.concurrent.Semaphore) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 17 with ReadReplica

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

the class ReadReplicaToReadReplicaCatchupIT method checkDataHasReplicatedToReadReplicas.

static void checkDataHasReplicatedToReadReplicas(Cluster cluster, long numberOfNodes) throws Exception {
    for (final ReadReplica server : cluster.readReplicas()) {
        GraphDatabaseService readReplica = server.database();
        try (Transaction tx = readReplica.beginTx()) {
            ThrowingSupplier<Long, Exception> nodeCount = () -> count(readReplica.getAllNodes());
            assertEventually("node to appear on read replica", nodeCount, is(numberOfNodes), 1, MINUTES);
            for (Node node : readReplica.getAllNodes()) {
                assertThat(node.getProperty("foobar").toString(), startsWith("baz_bat"));
            }
            tx.success();
        }
    }
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) UpstreamDatabaseSelectionException(org.neo4j.causalclustering.readreplica.UpstreamDatabaseSelectionException)

Example 18 with ReadReplica

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

the class ReadReplicaToReadReplicaCatchupIT method shouldCatchUpFromCoresWhenPreferredReadReplicasAreUnavailable.

@Test
public void shouldCatchUpFromCoresWhenPreferredReadReplicasAreUnavailable() throws Throwable {
    // given
    Cluster cluster = clusterRule.startCluster();
    int numberOfNodes = 1;
    int firstReadReplicaLocalMemberId = 101;
    cluster.coreTx((db, tx) -> {
        db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
        tx.success();
    });
    createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
    ReadReplica firstReadReplica = cluster.addReadReplicaWithIdAndMonitors(firstReadReplicaLocalMemberId, new Monitors());
    firstReadReplica.start();
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodes);
    upstreamFactory.setCurrent(firstReadReplica);
    ReadReplica secondReadReplica = cluster.addReadReplicaWithId(202);
    secondReadReplica.setUpstreamDatabaseSelectionStrategy("specific");
    secondReadReplica.start();
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodes);
    firstReadReplica.shutdown();
    upstreamFactory.reset();
    cluster.removeReadReplicaWithMemberId(firstReadReplicaLocalMemberId);
    // when
    // More transactions into core
    createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
    // then
    // reached second read replica from cores
    checkDataHasReplicatedToReadReplicas(cluster, numberOfNodes * 2);
}
Also used : ReadReplica(org.neo4j.causalclustering.discovery.ReadReplica) Monitors(org.neo4j.kernel.monitoring.Monitors) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 19 with ReadReplica

use of org.neo4j.causalclustering.discovery.ReadReplica 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 20 with ReadReplica

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

Aggregations

ReadReplica (org.neo4j.causalclustering.discovery.ReadReplica)22 Test (org.junit.Test)20 Cluster (org.neo4j.causalclustering.discovery.Cluster)13 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)13 IOException (java.io.IOException)8 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Rule (org.junit.Rule)6 Node (org.neo4j.graphdb.Node)6 Transaction (org.neo4j.graphdb.Transaction)6 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)6 TransactionFailureException (org.neo4j.kernel.api.exceptions.TransactionFailureException)6 UnsatisfiedDependencyException (org.neo4j.kernel.impl.util.UnsatisfiedDependencyException)6 LifecycleException (org.neo4j.kernel.lifecycle.LifecycleException)6 Monitors (org.neo4j.kernel.monitoring.Monitors)6 ClusterRule (org.neo4j.test.causalclustering.ClusterRule)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 TimeUnit (java.util.concurrent.TimeUnit)5