use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class DeletionTest method shouldDeleteRecords.
/**
* The problem would manifest even if the transaction was performed on the Master, it would then occur when the
* Slave pulls updates and tries to apply the transaction. The reason for the test to run transactions against the
* Slave is because it makes guarantees for when the master has to apply the transaction.
*/
@Test
public void shouldDeleteRecords() throws Throwable {
// given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
Relationship rel;
try (Transaction tx = slave.beginTx()) {
rel = slave.createNode().createRelationshipTo(slave.createNode(), withName("FOO"));
tx.success();
}
try (Transaction transaction = master.beginTx()) {
assertNotNull(master.getRelationshipById(rel.getId()));
}
// when
try (Transaction tx = slave.beginTx()) {
rel.delete();
tx.success();
}
// then - there should have been no exceptions
slave.shutdown();
master.shutdown();
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TestBasicHaOperations method testBasicPropagationFromSlaveToMaster.
@Test
public void testBasicPropagationFromSlaveToMaster() throws Throwable {
// given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
long nodeId;
// a node with a property
try (Transaction tx = master.beginTx()) {
Node node = master.createNode();
nodeId = node.getId();
node.setProperty("foo", "bar");
tx.success();
}
cluster.sync();
// the slave does a change
try (Transaction tx = slave.beginTx()) {
slave.getNodeById(nodeId).setProperty("foo", "bar2");
tx.success();
}
// the master must pick up the change
try (Transaction tx = master.beginTx()) {
assertEquals("bar2", master.getNodeById(nodeId).getProperty("foo"));
tx.success();
}
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TestBasicHaOperations method testBasicPropagationFromMasterToSlave.
@Test
public void testBasicPropagationFromMasterToSlave() throws Throwable {
// given
ManagedCluster cluster = clusterRule.startCluster();
long nodeId = 4;
HighlyAvailableGraphDatabase master = cluster.getMaster();
try (Transaction tx = master.beginTx()) {
Node node = master.createNode();
node.setProperty("Hello", "World");
nodeId = node.getId();
tx.success();
}
cluster.sync();
// No need to wait, the push factor is 2
HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave();
checkNodeOnSlave(nodeId, slave1);
HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(slave1);
checkNodeOnSlave(nodeId, slave2);
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class MeasureUpdatePullingRecordAndIndexGap method shouldMeasureThatGap.
@Test
public void shouldMeasureThatGap() throws Exception {
// GIVEN
ManagedCluster cluster = clusterRule.startCluster();
createIndexes(cluster.getMaster());
cluster.sync();
awaitIndexes(cluster);
final AtomicBoolean halter = new AtomicBoolean();
AtomicLong[] highIdNodes = new AtomicLong[numberOfIndexes];
CountDownLatch endLatch = new CountDownLatch(numberOfIndexes + 1);
for (int i = 0; i < highIdNodes.length; i++) {
highIdNodes[i] = new AtomicLong();
}
startLoadOn(cluster.getMaster(), halter, highIdNodes, endLatch);
GraphDatabaseAPI slave = cluster.getAnySlave();
startCatchingUp(slave, halter, endLatch);
// WHEN measuring...
final AtomicInteger good = new AtomicInteger(), bad = new AtomicInteger(), ugly = new AtomicInteger();
startMeasuringTheGap(good, bad, ugly, halter, highIdNodes, slave);
for (long endTime = currentTimeMillis() + SECONDS.toMillis(30); currentTimeMillis() < endTime; ) {
printStats(good.get(), bad.get(), ugly.get());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
halter.set(true);
endLatch.await();
// THEN
printStats(good.get(), bad.get(), ugly.get());
}
use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.
the class TxPushStrategyConfigIT method twoRoundRobin.
@Test
public void twoRoundRobin() throws Exception {
ManagedCluster cluster = startCluster(4, 2, HaSettings.TxPushStrategy.round_robin);
HighlyAvailableGraphDatabase master = cluster.getMaster();
Monitors monitors = master.getDependencyResolver().resolveDependency(Monitors.class);
AtomicInteger totalMissedReplicas = new AtomicInteger();
monitors.addMonitorListener((MasterTransactionCommitProcess.Monitor) totalMissedReplicas::addAndGet);
long txId = getLastTx(master);
int count = 15;
for (int i = 0; i < count; i++) {
createTransactionOnMaster(cluster);
}
long min = -1, max = -1;
for (GraphDatabaseAPI db : cluster.getAllMembers()) {
long tx = getLastTx(db);
min = min == -1 ? tx : min(min, tx);
max = max == -1 ? tx : max(max, tx);
}
assertEquals(txId + count, max);
assertTrue("There should be members with transactions in the cluster", min != -1 && max != -1);
int minLaggingBehindThreshold = 1 + /* this is the value without errors */
totalMissedReplicas.get();
assertThat("There should at most be a txId gap of 1 among the cluster members since the transaction pushing " + "goes in a round robin fashion. min:" + min + ", max:" + max, (int) (max - min), lessThanOrEqualTo(minLaggingBehindThreshold));
}
Aggregations