Search in sources :

Example 6 with ManagedCluster

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();
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 7 with ManagedCluster

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();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 8 with ManagedCluster

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);
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 9 with ManagedCluster

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with ManagedCluster

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));
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

Aggregations

ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)34 Test (org.junit.Test)32 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)16 Transaction (org.neo4j.graphdb.Transaction)15 Node (org.neo4j.graphdb.Node)13 InstanceId (org.neo4j.cluster.InstanceId)6 File (java.io.File)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)4 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)4 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CountsTracker (org.neo4j.kernel.impl.store.counts.CountsTracker)2 DbRepresentation (org.neo4j.test.DbRepresentation)2 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1