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;
}
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();
}
}
}
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);
}
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);
}
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());
}
}
}
Aggregations