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