use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class ReadReplicaReplicationIT method shouldEventuallyPullTransactionDownToAllReadReplicas.
@Test
public void shouldEventuallyPullTransactionDownToAllReadReplicas() throws Exception {
// given
Cluster cluster = clusterRule.withNumberOfReadReplicas(0).startCluster();
int nodesBeforeReadReplicaStarts = 1;
cluster.coreTx((db, tx) -> {
db.schema().constraintFor(Label.label("Foo")).assertPropertyIsUnique("foobar").create();
tx.success();
});
// when
for (int i = 0; i < 100; i++) {
cluster.coreTx((db, tx) -> {
createData(db, nodesBeforeReadReplicaStarts);
tx.success();
});
}
Set<Path> labelScanStoreFiles = new HashSet<>();
cluster.coreTx((db, tx) -> gatherLabelScanStoreFiles(db, labelScanStoreFiles));
AtomicBoolean labelScanStoreCorrectlyPlaced = new AtomicBoolean(false);
Monitors monitors = new Monitors();
ReadReplica rr = cluster.addReadReplicaWithIdAndMonitors(0, monitors);
Path readReplicateStoreDir = rr.storeDir().toPath().toAbsolutePath();
monitors.addMonitorListener((FileCopyMonitor) file -> {
Path relativPath = readReplicateStoreDir.relativize(file.toPath().toAbsolutePath());
relativPath = relativPath.subpath(1, relativPath.getNameCount());
if (labelScanStoreFiles.contains(relativPath)) {
labelScanStoreCorrectlyPlaced.set(true);
}
});
rr.start();
for (int i = 0; i < 100; i++) {
cluster.coreTx((db, tx) -> {
createData(db, nodesBeforeReadReplicaStarts);
tx.success();
});
}
// then
for (final ReadReplica server : cluster.readReplicas()) {
GraphDatabaseService readReplica = server.database();
try (Transaction tx = readReplica.beginTx()) {
ThrowingSupplier<Long, Exception> nodeCount = () -> count(readReplica.getAllNodes());
assertEventually("node to appear on read replica", nodeCount, is(400L), 1, MINUTES);
for (Node node : readReplica.getAllNodes()) {
assertThat(node.getProperty("foobar").toString(), startsWith("baz_bat"));
}
tx.success();
}
}
assertTrue(labelScanStoreCorrectlyPlaced.get());
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class ReadReplicaStoreCopyIT method addStoreCopyBlockingMonitor.
private static Semaphore addStoreCopyBlockingMonitor(ReadReplica readReplica) {
DependencyResolver dependencyResolver = readReplica.database().getDependencyResolver();
Monitors monitors = dependencyResolver.resolveDependency(Monitors.class);
Semaphore semaphore = new Semaphore(0);
monitors.addMonitorListener((FileCopyMonitor) file -> {
try {
semaphore.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
});
return semaphore;
}
use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.
the class ReadReplicaToReadReplicaCatchupIT method shouldCatchUpFromCoresWhenPreferredReadReplicasAreUnavailable.
@Test
public void shouldCatchUpFromCoresWhenPreferredReadReplicasAreUnavailable() throws Throwable {
// given
Cluster cluster = clusterRule.startCluster();
int numberOfNodes = 1;
int firstReadReplicaLocalMemberId = 101;
cluster.coreTx((db, tx) -> {
db.schema().constraintFor(label("Foo")).assertPropertyIsUnique("foobar").create();
tx.success();
});
createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
ReadReplica firstReadReplica = cluster.addReadReplicaWithIdAndMonitors(firstReadReplicaLocalMemberId, new Monitors());
firstReadReplica.start();
checkDataHasReplicatedToReadReplicas(cluster, numberOfNodes);
upstreamFactory.setCurrent(firstReadReplica);
ReadReplica secondReadReplica = cluster.addReadReplicaWithId(202);
secondReadReplica.setUpstreamDatabaseSelectionStrategy("specific");
secondReadReplica.start();
checkDataHasReplicatedToReadReplicas(cluster, numberOfNodes);
firstReadReplica.shutdown();
upstreamFactory.reset();
cluster.removeReadReplicaWithMemberId(firstReadReplicaLocalMemberId);
// when
// More transactions into core
createLabelledNodesWithProperty(cluster, numberOfNodes, label("Foo"), () -> Pair.of("foobar", String.format("baz_bat%s", UUID.randomUUID())));
// then
// reached second read replica from cores
checkDataHasReplicatedToReadReplicas(cluster, numberOfNodes * 2);
}
use of org.neo4j.kernel.monitoring.Monitors 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.kernel.monitoring.Monitors in project neo4j by neo4j.
the class MasterImplConversationStopFuzzIT method shouldHandleRandomizedLoad.
@Test
public void shouldHandleRandomizedLoad() throws Throwable {
// Given
DefaultConversationSPI conversationSPI = new DefaultConversationSPI(locks, scheduler);
final ExposedConversationManager conversationManager = new ExposedConversationManager(conversationSPI, config, 100, 0);
ConversationTestMasterSPI conversationTestMasterSPI = new ConversationTestMasterSPI();
MasterImpl master = new MasterImpl(conversationTestMasterSPI, conversationManager, new Monitors().newMonitor(MasterImpl.Monitor.class), config);
life.add(conversationManager);
life.start();
ConversationKiller conversationKiller = new ConversationKiller(conversationManager);
executor.submit(conversationKiller);
List<Callable<Void>> slaveWorkers = workers(master, numberOfWorkers);
List<Future<Void>> workers = executor.invokeAll(slaveWorkers);
// Wait for all workers to complete
for (Future<Void> future : workers) {
future.get();
}
conversationKiller.stop();
assertTrue(executionStatistic.isSuccessfulExecution());
}
Aggregations