use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class CoreToCoreCopySnapshotIT method shouldBeAbleToDownloadLargerFreshSnapshot.
@Test
public void shouldBeAbleToDownloadLargerFreshSnapshot() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
CoreClusterMember source = cluster.coreTx((db, tx) -> {
createData(db, 1000);
tx.success();
});
// when
CoreClusterMember follower = cluster.awaitCoreMemberWithRole(Role.FOLLOWER, 5, TimeUnit.SECONDS);
// shutdown the follower, remove the store, restart
follower.shutdown();
deleteDirectoryRecursively(follower.storeDir(), follower.serverId());
deleteDirectoryRecursively(follower.clusterStateDirectory(), follower.serverId());
follower.start();
// then
assertEquals(DbRepresentation.of(source.database()), DbRepresentation.of(follower.database()));
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class CoreToCoreCopySnapshotIT method shouldBeAbleToDownloadToNewInstanceAfterPruning.
@Test
public void shouldBeAbleToDownloadToNewInstanceAfterPruning() throws Exception {
// given
Map<String, String> params = stringMap(CausalClusteringSettings.state_machine_flush_window_size.name(), "1", CausalClusteringSettings.raft_log_pruning_strategy.name(), "3 entries", CausalClusteringSettings.raft_log_rotation_size.name(), "1K");
Cluster cluster = clusterRule.withSharedCoreParams(params).startCluster();
CoreClusterMember leader = cluster.coreTx((db, tx) -> {
createData(db, 10000);
tx.success();
});
// when
for (CoreClusterMember coreDb : cluster.coreMembers()) {
coreDb.coreState().prune();
}
// to force a change of leader
cluster.removeCoreMember(leader);
leader = cluster.awaitLeader();
int newDbId = 3;
cluster.addCoreMemberWithId(newDbId).start();
CoreGraphDatabase newDb = cluster.getCoreMemberById(newDbId).database();
// then
assertEquals(DbRepresentation.of(leader.database()), DbRepresentation.of(newDb));
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaHierarchicalCatchupIT method shouldCatchupThroughHierarchy.
@Test
public void shouldCatchupThroughHierarchy() throws Throwable {
clusterRule = clusterRule.withInstanceReadReplicaParam(CausalClusteringSettings.server_groups, id -> serverGroups.get(id)).withInstanceCoreParam(CausalClusteringSettings.server_groups, id -> serverGroups.get(id));
// given
Cluster cluster = clusterRule.startCluster();
int numberOfNodesToCreate = 100;
cluster.coreTx((db, tx) -> {
db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
tx.success();
});
// 0, 1, 2 are core instances
createLabelledNodesWithProperty(cluster, numberOfNodesToCreate, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
// 3, 4 are other DCs
ReadReplica east3 = cluster.addReadReplicaWithId(3);
east3.start();
ReadReplica west4 = cluster.addReadReplicaWithId(4);
west4.start();
checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
for (CoreClusterMember coreClusterMember : cluster.coreMembers()) {
coreClusterMember.stopCatchupServer();
}
// 5, 6 are other DCs
ReadReplica east5 = cluster.addReadReplicaWithId(5);
east5.setUpstreamDatabaseSelectionStrategy("connect-within-data-center");
east5.start();
ReadReplica west6 = cluster.addReadReplicaWithId(6);
west6.setUpstreamDatabaseSelectionStrategy("connect-within-data-center");
west6.start();
checkDataHasReplicatedToReadReplicas(cluster, numberOfNodesToCreate);
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaReplicationIT method transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused.
@Test
public void transactionsShouldNotAppearOnTheReadReplicaWhilePollingIsPaused() throws Throwable {
// given
Cluster cluster = clusterRule.startCluster();
ReadReplicaGraphDatabase readReplicaGraphDatabase = cluster.findAnyReadReplica().database();
CatchupPollingProcess pollingClient = readReplicaGraphDatabase.getDependencyResolver().resolveDependency(CatchupPollingProcess.class);
pollingClient.stop();
cluster.coreTx((coreGraphDatabase, transaction) -> {
coreGraphDatabase.createNode();
transaction.success();
});
CoreGraphDatabase leaderDatabase = cluster.awaitLeader().database();
long transactionVisibleOnLeader = transactionIdTracker(leaderDatabase).newestEncounteredTxId();
// when the poller is paused, transaction doesn't make it to the read replica
try {
transactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(3));
fail("should have thrown exception");
} catch (TransactionFailureException e) {
// expected timeout
}
// when the poller is resumed, it does make it to the read replica
pollingClient.start();
transactionIdTracker(readReplicaGraphDatabase).awaitUpToDate(transactionVisibleOnLeader, ofSeconds(3));
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaReplicationIT method aReadReplicShouldBeAbleToRejoinTheCluster.
@Test
public void aReadReplicShouldBeAbleToRejoinTheCluster() throws Exception {
int readReplicaId = 4;
Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
cluster.coreTx(createSomeData);
cluster.addReadReplicaWithId(readReplicaId).start();
// let's spend some time by adding more data
cluster.coreTx(createSomeData);
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
cluster.removeReadReplicaWithMemberId(readReplicaId);
// let's spend some time by adding more data
cluster.coreTx(createSomeData);
cluster.addReadReplicaWithId(readReplicaId).start();
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
Function<ClusterMember, DbRepresentation> toRep = db -> DbRepresentation.of(db.database());
Set<DbRepresentation> dbs = cluster.coreMembers().stream().map(toRep).collect(toSet());
dbs.addAll(cluster.readReplicas().stream().map(toRep).collect(toSet()));
cluster.shutdown();
assertEquals(1, dbs.size());
}
Aggregations