use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase 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.readreplica.ReadReplicaGraphDatabase 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.readreplica.ReadReplicaGraphDatabase in project neo4j by neo4j.
the class CausalClusteringProceduresIT method readReplicaProceduresShouldBeAvailable.
@Test
public void readReplicaProceduresShouldBeAvailable() throws Exception {
// given
String[] readReplicaProcs = new String[] { // Server role
"dbms.cluster.role", // Kernel built procedures
"dbms.procedures", // Built in procedure from enterprise
"dbms.listQueries" };
// when
for (String procedure : readReplicaProcs) {
Optional<ReadReplica> firstReadReplica = cluster.readReplicas().stream().findFirst();
assert firstReadReplica.isPresent();
ReadReplicaGraphDatabase database = firstReadReplica.get().database();
InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
Result readReplicaResult = database.execute("CALL " + procedure + "()");
// then
assertTrue("read replica with procedure " + procedure, readReplicaResult.hasNext());
readReplicaResult.close();
tx.close();
}
}
use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase in project neo4j by neo4j.
the class BackupReadReplicaIT method makeSureBackupCanBePerformed.
@Test
public void makeSureBackupCanBePerformed() throws Throwable {
// Run backup
CoreGraphDatabase leader = createSomeData(cluster);
ReadReplicaGraphDatabase readReplica = cluster.findAnyReadReplica().database();
awaitEx(() -> readReplicasUpToDateAsTheLeader(leader, readReplica), 1, TimeUnit.MINUTES);
DbRepresentation beforeChange = DbRepresentation.of(readReplica);
String backupAddress = this.backupAddress(readReplica);
String[] args = backupArguments(backupAddress, backupPath, "readreplica");
assertEquals(0, runBackupToolFromOtherJvmToGetExitCode(clusterRule.clusterDirectory(), args));
// Add some new data
DbRepresentation afterChange = DbRepresentation.of(createSomeData(cluster));
// Verify that backed up database can be started and compare representation
DbRepresentation backupRepresentation = DbRepresentation.of(new File(backupPath, "readreplica"), getConfig());
assertEquals(beforeChange, backupRepresentation);
assertNotEquals(backupRepresentation, afterChange);
}
use of org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase 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
}
}
Aggregations