Search in sources :

Example 11 with ManagedCluster

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

the class SchemaIndexHaIT method creatingIndexOnSlaveIsNotAllowed.

@Test
public void creatingIndexOnSlaveIsNotAllowed() throws Throwable {
    // GIVEN
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    // WHEN
    try {
        createIndex(slave);
        fail("should have thrown exception");
    } catch (ConstraintViolationException e) {
    // expected
    }
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) Test(org.junit.Test)

Example 12 with ManagedCluster

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

the class SchemaIndexHaIT method indexPopulationJobsShouldContinueThroughRoleSwitch.

@Test
public void indexPopulationJobsShouldContinueThroughRoleSwitch() throws Throwable {
    // GIVEN a cluster of 3
    ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();
    ManagedCluster cluster = clusterRule.withDbFactory(dbFactory).startCluster();
    HighlyAvailableGraphDatabase firstMaster = cluster.getMaster();
    // where the master gets some data created as well as an index
    Map<Object, Node> data = createSomeData(firstMaster);
    createIndex(firstMaster);
    //dbFactory.awaitPopulationStarted( firstMaster );
    dbFactory.triggerFinish(firstMaster);
    // Pick a slave, pull the data and the index
    HighlyAvailableGraphDatabase aSlave = cluster.getAnySlave();
    aSlave.getDependencyResolver().resolveDependency(UpdatePuller.class).pullUpdates();
    // and await the index population to start. It will actually block as long as we want it to
    dbFactory.awaitPopulationStarted(aSlave);
    // WHEN we shut down the master
    cluster.shutdown(firstMaster);
    dbFactory.triggerFinish(aSlave);
    cluster.await(masterAvailable(firstMaster));
    // get the new master, which should be the slave we pulled from above
    HighlyAvailableGraphDatabase newMaster = cluster.getMaster();
    // THEN
    assertEquals("Unexpected new master", aSlave, newMaster);
    try (Transaction tx = newMaster.beginTx()) {
        IndexDefinition index = Iterables.single(newMaster.schema().getIndexes());
        awaitIndexOnline(index, newMaster, data);
        tx.success();
    }
    // FINALLY: let all db's finish
    for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
        dbFactory.triggerFinish(db);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) UpdatePuller(org.neo4j.kernel.ha.UpdatePuller) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 13 with ManagedCluster

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

the class TxPushStrategyConfigIT method shouldPushToOneLessSlaveOnSlaveCommit.

@Test
public void shouldPushToOneLessSlaveOnSlaveCommit() throws Exception {
    ManagedCluster cluster = startCluster(4, 2, HaSettings.TxPushStrategy.fixed_descending);
    int missed = 0;
    missed += createTransactionOn(cluster, new InstanceId(FIRST_SLAVE));
    assertLastTransactions(cluster, lastTx(MASTER, BASE_TX_ID + 1, missed), lastTx(FIRST_SLAVE, BASE_TX_ID + 1, missed), lastTx(SECOND_SLAVE, BASE_TX_ID, missed), lastTx(THIRD_SLAVE, BASE_TX_ID + 1, missed));
    missed += createTransactionOn(cluster, new InstanceId(SECOND_SLAVE));
    assertLastTransactions(cluster, lastTx(MASTER, BASE_TX_ID + 2, missed), lastTx(FIRST_SLAVE, BASE_TX_ID + 1, missed), lastTx(SECOND_SLAVE, BASE_TX_ID + 2, missed), lastTx(THIRD_SLAVE, BASE_TX_ID + 2, missed));
    missed += createTransactionOn(cluster, new InstanceId(THIRD_SLAVE));
    assertLastTransactions(cluster, lastTx(MASTER, BASE_TX_ID + 3, missed), lastTx(FIRST_SLAVE, BASE_TX_ID + 1, missed), lastTx(SECOND_SLAVE, BASE_TX_ID + 3, missed), lastTx(THIRD_SLAVE, BASE_TX_ID + 3, missed));
}
Also used : InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Test(org.junit.Test)

Example 14 with ManagedCluster

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

the class TxPushStrategyConfigIT method shouldPushToSlavesInAscendingOrder.

@Test
public void shouldPushToSlavesInAscendingOrder() throws Exception {
    ManagedCluster cluster = startCluster(4, 2, HaSettings.TxPushStrategy.fixed_ascending);
    for (int i = 0; i < 5; i++) {
        int missed = createTransactionOnMaster(cluster);
        assertLastTransactions(cluster, lastTx(FIRST_SLAVE, BASE_TX_ID + 1 + i, missed));
        assertLastTransactions(cluster, lastTx(SECOND_SLAVE, BASE_TX_ID + 1 + i, missed));
        assertLastTransactions(cluster, lastTx(THIRD_SLAVE, BASE_TX_ID, missed));
    }
}
Also used : ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Test(org.junit.Test)

Example 15 with ManagedCluster

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

the class ReadOnlySlaveTest method givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException.

@Test
public void givenClusterWithReadOnlySlaveWhenAddNewLabelOnSlaveThenThrowException() throws Throwable {
    // Given
    ManagedCluster cluster = clusterRule.startCluster();
    Node node;
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    try (Transaction tx = master.beginTx()) {
        node = master.createNode();
        tx.success();
    }
    // When
    HighlyAvailableGraphDatabase readOnlySlave = cluster.getMemberByServerId(new InstanceId(2));
    try (Transaction tx = readOnlySlave.beginTx()) {
        Node slaveNode = readOnlySlave.getNodeById(node.getId());
        // Then
        slaveNode.addLabel(Label.label("FOO"));
        tx.success();
        fail("Should have thrown exception");
    } catch (WriteOperationsNotAllowedException ex) {
    // Ok!
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) InstanceId(org.neo4j.cluster.InstanceId) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) WriteOperationsNotAllowedException(org.neo4j.graphdb.security.WriteOperationsNotAllowedException) 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