use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldShutdownRatherThanPullUpdatesFromCoreMemberWithDifferentStoreIdIfLocalStoreIsNonEmpty.
@Test
public void shouldShutdownRatherThanPullUpdatesFromCoreMemberWithDifferentStoreIdIfLocalStoreIsNonEmpty() throws Exception {
Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
cluster.coreTx(createSomeData);
cluster.awaitCoreMemberWithRole(Role.FOLLOWER, 2, TimeUnit.SECONDS);
// Get a read replica and make sure that it is operational
ReadReplica readReplica = cluster.addReadReplicaWithId(4);
readReplica.start();
readReplica.database().beginTx().close();
// Change the store id, so it should fail to join the cluster again
changeStoreId(readReplica);
readReplica.shutdown();
try {
readReplica.start();
fail("Should have failed to start");
} catch (RuntimeException required) {
// Lifecycle should throw exception, server should not start.
assertThat(required.getCause(), instanceOf(LifecycleException.class));
assertThat(required.getCause().getCause(), instanceOf(Exception.class));
assertThat(required.getCause().getCause().getMessage(), containsString("This read replica cannot join the cluster. " + "The local database is not empty and has a mismatching storeId:"));
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaReplicationIT method allServersBecomeAvailable.
@Test
public void allServersBecomeAvailable() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
// 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 ReadReplicaReplicationIT method shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning.
@Test
public void shouldBeAbleToPullTxAfterHavingDownloadedANewStoreAfterPruning() throws Exception {
// given
Map<String, String> params = stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "keep_none", GraphDatabaseSettings.logical_log_rotation_threshold.name(), "1M", GraphDatabaseSettings.check_point_interval_time.name(), "100ms");
Cluster cluster = clusterRule.withSharedCoreParams(params).startCluster();
cluster.coreTx((db, tx) -> {
createData(db, 10);
tx.success();
});
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
ReadReplica readReplica = cluster.getReadReplicaById(0);
long highestReadReplicaLogVersion = physicalLogFiles(readReplica).getHighestLogVersion();
readReplica.shutdown();
CoreClusterMember core;
do {
core = cluster.coreTx((db, tx) -> {
createData(db, 1_000);
tx.success();
});
} while (physicalLogFiles(core).getLowestLogVersion() <= highestReadReplicaLogVersion);
readReplica.start();
awaitEx(() -> readReplicasUpToDateAsTheLeader(cluster.awaitLeader(), cluster.readReplicas()), 1, TimeUnit.MINUTES);
// when
cluster.coreTx((db, tx) -> {
createData(db, 10);
tx.success();
});
// then
assertEventually("The read replica has the same data as the core members", () -> DbRepresentation.of(readReplica.database()), equalTo(DbRepresentation.of(cluster.awaitLeader().database())), 10, TimeUnit.SECONDS);
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class ReadReplicaStoreCopyIT method shouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore.
@Test(timeout = 120_000)
public void shouldNotBePossibleToStartTransactionsWhenReadReplicaCopiesStore() throws Throwable {
Cluster cluster = clusterRule.startCluster();
ReadReplica readReplica = cluster.findAnyReadReplica();
readReplica.txPollingClient().stop();
writeSomeDataAndForceLogRotations(cluster);
Semaphore storeCopyBlockingSemaphore = addStoreCopyBlockingMonitor(readReplica);
try {
readReplica.txPollingClient().start();
waitForStoreCopyToStartAndBlock(storeCopyBlockingSemaphore);
ReadReplicaGraphDatabase replicaGraphDatabase = readReplica.database();
try {
replicaGraphDatabase.beginTx();
fail("Exception expected");
} catch (Exception e) {
assertThat(e, instanceOf(TransactionFailureException.class));
assertThat(e.getMessage(), containsString("Database is stopped to copy store"));
}
} finally {
// release all waiters of the semaphore
storeCopyBlockingSemaphore.release(Integer.MAX_VALUE);
}
}
use of org.neo4j.causalclustering.discovery.Cluster in project neo4j by neo4j.
the class RecoveryIT method singleServerWithinClusterShouldBeConsistentAfterRestart.
@Test
public void singleServerWithinClusterShouldBeConsistentAfterRestart() throws Exception {
// given
Cluster cluster = clusterRule.startCluster();
int clusterSize = cluster.numberOfCoreMembersReportedByTopology();
fireSomeLoadAtTheCluster(cluster);
Set<File> storeDirs = cluster.coreMembers().stream().map(CoreClusterMember::storeDir).collect(toSet());
// when
for (int i = 0; i < clusterSize; i++) {
cluster.removeCoreMemberWithMemberId(i);
fireSomeLoadAtTheCluster(cluster);
cluster.addCoreMemberWithId(i).start();
}
// then
assertEventually("All cores have the same data", () -> cluster.coreMembers().stream().map(this::dbRepresentation).collect(toSet()).size(), equalTo(1), 10, TimeUnit.SECONDS);
cluster.shutdown();
storeDirs.forEach(this::assertConsistent);
}
Aggregations