use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldNotBeAbleToWriteToReadReplica.
@Test
public void shouldNotBeAbleToWriteToReadReplica() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
ReadReplicaGraphDatabase readReplica = cluster.findAnyReadReplica().database();
// when
try (Transaction tx = readReplica.beginTx()) {
Node node = readReplica.createNode();
node.setProperty("foobar", "baz_bat");
node.addLabel(Label.label("Foo"));
tx.success();
fail("should have thrown");
} catch (WriteOperationsNotAllowedException e) {
// then all good
}
}
use of org.neo4j.causalclustering.discovery.Cluster 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);
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaReplicationIT method readReplicasShouldRestartIfTheWholeClusterIsRestarted.
@Test
public void readReplicasShouldRestartIfTheWholeClusterIsRestarted() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
// when
cluster.shutdown();
cluster.start();
// then
for (final ReadReplica readReplica : cluster.readReplicas()) {
ThrowingSupplier<Boolean, Exception> availability = () -> readReplica.database().isAvailable(0);
assertEventually("read replica becomes available", availability, is(true), 10, SECONDS);
}
}
use of org.neo4j.causalclustering.discovery.Cluster 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.Cluster 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);
}
Aggregations