Search in sources :

Example 1 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class TestSlaveOnlyCluster method testMasterElectionAfterMasterRecoversInSlaveOnlyCluster.

@Test
public void testMasterElectionAfterMasterRecoversInSlaveOnlyCluster() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    assertThat(cluster.getServerId(cluster.getMaster()), equalTo(new InstanceId(3)));
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    CountDownLatch masterFailedLatch = createMasterFailLatch(cluster);
    RepairKit repairKit = cluster.fail(master);
    try {
        assertTrue(masterFailedLatch.await(60, TimeUnit.SECONDS));
    } finally {
        repairKit.repair();
    }
    cluster.await(allSeesAllAsAvailable());
    long nodeId = createNodeWithPropertyOn(cluster.getAnySlave(), PROPERTY, VALUE);
    try (Transaction ignore = master.beginTx()) {
        assertThat(master.getNodeById(nodeId).getProperty(PROPERTY), equalTo(VALUE));
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) InstanceId(org.neo4j.cluster.InstanceId) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) RepairKit(org.neo4j.kernel.impl.ha.ClusterManager.RepairKit) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class HACountsPropagationTest method shouldPropagateRelationshipCountsInHA.

@Test
public void shouldPropagateRelationshipCountsInHA() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        Node left = master.createNode();
        Node right = master.createNode(Label.label("A"));
        left.createRelationshipTo(right, RelationshipType.withName("Type"));
        tx.success();
    }
    cluster.sync();
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        CountsTracker counts = counts(db);
        assertEquals(1, counts.relationshipCount(-1, -1, -1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, -1, 0, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, 0, -1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.relationshipCount(-1, 0, 0, newDoubleLongRegister()).readSecond());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 3 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class HACountsPropagationTest method shouldPropagateNodeCountsInHA.

@Test
public void shouldPropagateNodeCountsInHA() throws Throwable {
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        master.createNode();
        master.createNode(Label.label("A"));
        tx.success();
    }
    cluster.sync();
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        CountsTracker counts = counts(db);
        assertEquals(2, counts.nodeCount(-1, newDoubleLongRegister()).readSecond());
        assertEquals(1, counts.nodeCount(0, /* A */
        newDoubleLongRegister()).readSecond());
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 4 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class TransactionThroughMasterSwitchStressIT method oneRound.

private void oneRound() throws Throwable {
    // GIVEN a cluster and a node
    final String key = "key";
    ManagedCluster cluster = clusterRule.startCluster();
    final GraphDatabaseService master = cluster.getMaster();
    final long nodeId = createNode(master);
    cluster.sync();
    // and a bunch of workers contending on that node, each changing it
    Workers<Runnable> transactors = new Workers<>("Transactors");
    final AtomicInteger successes = new AtomicInteger();
    final AtomicBoolean end = new AtomicBoolean();
    for (int i = 0; i < 10; i++) {
        transactors.start(new Runnable() {

            @Override
            public void run() {
                Random random = ThreadLocalRandom.current();
                while (!end.get()) {
                    boolean committed = true;
                    try (Transaction tx = master.beginTx()) {
                        Node node = master.getNodeById(nodeId);
                        // Acquiring lock, read int property value, increment, set incremented int property
                        // should not break under any circumstances.
                        tx.acquireWriteLock(node);
                        node.setProperty(key, (Integer) node.getProperty(key, 0) + 1);
                        // Throw in relationship for good measure
                        node.createRelationshipTo(master.createNode(), TEST);
                        Thread.sleep(random.nextInt(1_000));
                        tx.success();
                    } catch (Throwable e) {
                        // It's OK
                        committed = false;
                    }
                    if (committed) {
                        successes.incrementAndGet();
                    }
                }
            }
        });
    }
    // WHEN entering a period of induced cluster instabilities
    reelectTheSameMasterMakingItGoToPendingAndBack(cluster);
    // ... letting transactions run a bit after the role switch as well.
    long targetSuccesses = successes.get() + 20;
    while (successes.get() < targetSuccesses) {
        Thread.sleep(100);
    }
    end.set(true);
    transactors.awaitAndThrowOnError(RuntimeException.class);
    // THEN verify that the count is equal to the number of successful transactions
    assertEquals(successes.get(), getNodePropertyValue(master, nodeId, key));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Transaction(org.neo4j.graphdb.Transaction) Workers(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.Workers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)

Example 5 with ManagedCluster

use of org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster in project neo4j by neo4j.

the class AutoIndexConfigIT method programmaticConfigShouldSurviveMasterSwitches.

@Test
public void programmaticConfigShouldSurviveMasterSwitches() throws Throwable {
    String propertyToIndex = "programmatic-property";
    // Given
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    AutoIndexer<Node> originalAutoIndex = slave.index().getNodeAutoIndexer();
    originalAutoIndex.setEnabled(true);
    originalAutoIndex.startAutoIndexingProperty(propertyToIndex);
    // When
    cluster.shutdown(cluster.getMaster());
    cluster.await(masterAvailable());
    // Then
    AutoIndexer<Node> newAutoIndex = slave.index().getNodeAutoIndexer();
    assertThat(newAutoIndex.isEnabled(), is(true));
    assertThat(newAutoIndex.getAutoIndexedProperties(), hasItem(propertyToIndex));
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) 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