use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.
the class Cluster method leaderTx.
/**
* Perform a transaction against the leader of the core cluster, retrying as necessary.
*/
private CoreClusterMember leaderTx(BiConsumer<CoreGraphDatabase, Transaction> op, int timeout, TimeUnit timeUnit) throws Exception {
ThrowingSupplier<CoreClusterMember, Exception> supplier = () -> {
CoreClusterMember member = awaitLeader(timeout, timeUnit);
CoreGraphDatabase db = member.database();
if (db == null) {
throw new DatabaseShutdownException();
}
try (Transaction tx = db.beginTx()) {
op.accept(db, tx);
return member;
} catch (Throwable e) {
if (isTransientFailure(e)) {
// this is not the best, but it helps in debugging
System.err.println("Transient failure in leader transaction, trying again.");
e.printStackTrace();
return null;
} else {
throw e;
}
}
};
return awaitEx(supplier, notNull()::test, timeout, timeUnit);
}
use of org.neo4j.causalclustering.core.CoreGraphDatabase 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.core.CoreGraphDatabase 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.core.CoreGraphDatabase in project neo4j by neo4j.
the class ClusterFormationIT method shouldBeAbleToAddAndRemoveCoreMembersUnderModestLoad.
@Test
public void shouldBeAbleToAddAndRemoveCoreMembersUnderModestLoad() throws Exception {
// given
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
CoreGraphDatabase leader = cluster.getDbWithRole(Role.LEADER).database();
try (Transaction tx = leader.beginTx()) {
leader.createNode();
tx.success();
}
});
// when
cluster.getCoreMemberById(0).shutdown();
cluster.getCoreMemberById(0).start();
// then
assertEquals(3, cluster.numberOfCoreMembersReportedByTopology());
// when
cluster.removeCoreMemberWithMemberId(0);
// then
assertEquals(2, cluster.numberOfCoreMembersReportedByTopology());
// when
cluster.addCoreMemberWithId(4).start();
// then
assertEquals(3, cluster.numberOfCoreMembersReportedByTopology());
executorService.shutdown();
}
use of org.neo4j.causalclustering.core.CoreGraphDatabase in project neo4j by neo4j.
the class CausalClusteringProceduresIT method coreProceduresShouldBeAvailable.
@Test
public void coreProceduresShouldBeAvailable() throws Throwable {
String[] coreProcs = new String[] { // Server role
"dbms.cluster.role", // Discover the cluster topology
"dbms.cluster.routing.getServers", // Discover appropriate discovery service
"dbms.cluster.overview", // Kernel built procedures
"dbms.procedures", // Built in procedure from enterprise
"dbms.listQueries" };
for (String procedure : coreProcs) {
Optional<CoreClusterMember> firstCore = cluster.coreMembers().stream().findFirst();
assert firstCore.isPresent();
CoreGraphDatabase database = firstCore.get().database();
InternalTransaction tx = database.beginTransaction(KernelTransaction.Type.explicit, AUTH_DISABLED);
Result coreResult = database.execute("CALL " + procedure + "()");
assertTrue("core with procedure " + procedure, coreResult.hasNext());
coreResult.close();
tx.close();
}
}
Aggregations