Search in sources :

Example 36 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class LabelIT method creatingIndexOnMasterShouldHaveSlavesBuildItAsWell.

@Test
public void creatingIndexOnMasterShouldHaveSlavesBuildItAsWell() throws Throwable {
    // GIVEN
    HighlyAvailableGraphDatabase slave1 = cluster.getAnySlave();
    HighlyAvailableGraphDatabase slave2 = cluster.getAnySlave(/*except*/
    slave1);
    Label label = label("Person");
    // WHEN
    TransactionContinuation txOnSlave1 = createNodeAndKeepTxOpen(slave1, label);
    TransactionContinuation txOnSlave2 = createNodeAndKeepTxOpen(slave2, label);
    commit(txOnSlave1);
    commit(txOnSlave2);
    // THEN
    assertEquals(getLabelId(slave1, label), getLabelId(slave2, label));
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 37 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class SchemaIndexHaIT method creatingIndexOnMasterShouldHaveSlavesBuildItAsWell.

@Test
public void creatingIndexOnMasterShouldHaveSlavesBuildItAsWell() throws Throwable {
    // GIVEN
    ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    Map<Object, Node> data = createSomeData(master);
    // WHEN
    IndexDefinition index = createIndex(master);
    cluster.sync();
    // THEN
    awaitIndexOnline(index, cluster, data);
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 38 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class SchemaIndexHaIT method populatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy.

@Test
public void populatingSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable {
    /*
        The master has an index that is currently populating.
        Then a slave comes online and contacts the master to get copies of the store files.
        Because the index is still populating, it won't be copied. Instead the slave will build its own.
        We want to observe that the slave builds an index that eventually comes online.
         */
    // GIVEN
    ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory(IS_MASTER);
    ManagedCluster cluster = clusterRule.withDbFactory(dbFactory).startCluster();
    try {
        cluster.await(allSeesAllAsAvailable());
        HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
        // A slave is offline, and has no store files
        ClusterManager.RepairKit slaveDown = bringSlaveOfflineAndRemoveStoreFiles(cluster, slave);
        // And I create an index on the master, and wait for population to start
        HighlyAvailableGraphDatabase master = cluster.getMaster();
        Map<Object, Node> data = createSomeData(master);
        createIndex(master);
        dbFactory.awaitPopulationStarted(master);
        // WHEN the slave comes online before population has finished on the master
        slave = slaveDown.repair();
        cluster.await(allSeesAllAsAvailable(), 180);
        cluster.sync();
        // THEN, population should finish successfully on both master and slave
        dbFactory.triggerFinish(master);
        // Check master
        IndexDefinition index;
        try (Transaction tx = master.beginTx()) {
            index = Iterables.single(master.schema().getIndexes());
            awaitIndexOnline(index, master, data);
            tx.success();
        }
        // Check slave
        try (Transaction tx = slave.beginTx()) {
            awaitIndexOnline(index, slave, data);
            tx.success();
        }
    } finally {
        for (HighlyAvailableGraphDatabase db : cluster.getAllMembers()) {
            dbFactory.triggerFinish(db);
        }
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 39 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class SchemaIndexHaIT method onlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy.

@Test
public void onlineSchemaIndicesOnMasterShouldBeBroughtOnlineOnSlavesAfterStoreCopy() throws Throwable {
    /*
        The master has an index that is online.
        Then a slave comes online and contacts the master to get copies of the store files.
        Because the index is online, it should be copied, and the slave should successfully bring the index online.
         */
    // GIVEN
    ControlledGraphDatabaseFactory dbFactory = new ControlledGraphDatabaseFactory();
    ManagedCluster cluster = clusterRule.withDbFactory(dbFactory).startCluster();
    cluster.await(allSeesAllAsAvailable(), 120);
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    // All slaves in the cluster, except the one I care about, proceed as normal
    proceedAsNormalWithIndexPopulationOnAllSlavesExcept(dbFactory, cluster, slave);
    // A slave is offline, and has no store files
    ClusterManager.RepairKit slaveDown = bringSlaveOfflineAndRemoveStoreFiles(cluster, slave);
    // And I create an index on the master, and wait for population to start
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    Map<Object, Node> data = createSomeData(master);
    createIndex(master);
    dbFactory.awaitPopulationStarted(master);
    // And the population finishes
    dbFactory.triggerFinish(master);
    IndexDefinition index;
    try (Transaction tx = master.beginTx()) {
        index = Iterables.single(master.schema().getIndexes());
        awaitIndexOnline(index, master, data);
        tx.success();
    }
    // WHEN the slave comes online after population has finished on the master
    slave = slaveDown.repair();
    cluster.await(allSeesAllAsAvailable());
    cluster.sync();
    // THEN the index should work on the slave
    dbFactory.triggerFinish(slave);
    try (Transaction tx = slave.beginTx()) {
        awaitIndexOnline(index, slave, data);
        tx.success();
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Transaction(org.neo4j.graphdb.Transaction) HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ManagedCluster(org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster) Node(org.neo4j.graphdb.Node) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 40 with HighlyAvailableGraphDatabase

use of org.neo4j.kernel.ha.HighlyAvailableGraphDatabase in project neo4j by neo4j.

the class SlaveWritingAfterStoreCopyTest method shouldHandleSlaveWritingFirstAfterStoryCopy.

@Test
public void shouldHandleSlaveWritingFirstAfterStoryCopy() throws Throwable {
    // Given
    Set<Long> expected = new HashSet();
    ClusterManager.ManagedCluster cluster = clusterRule.startCluster();
    HighlyAvailableGraphDatabase master = cluster.getMaster();
    HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
    // When
    expected.add(createOneNode(master));
    cluster.sync();
    // ... crash the slave
    File slaveStoreDirectory = cluster.getStoreDir(slave);
    ClusterManager.RepairKit shutdownSlave = cluster.shutdown(slave);
    deleteRecursively(slaveStoreDirectory);
    // ... and slave copy store from master
    slave = shutdownSlave.repair();
    // ... and first write after crash occurs on salve
    expected.add(createOneNode(slave));
    cluster.sync();
    // Then
    assertTrue(expected.equals(collectIds(master)));
    assertTrue(expected.equals(collectIds(slave)));
}
Also used : HighlyAvailableGraphDatabase(org.neo4j.kernel.ha.HighlyAvailableGraphDatabase) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)80 Test (org.junit.Test)68 Transaction (org.neo4j.graphdb.Transaction)38 ClusterManager (org.neo4j.kernel.impl.ha.ClusterManager)24 Node (org.neo4j.graphdb.Node)22 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)16 File (java.io.File)12 InstanceId (org.neo4j.cluster.InstanceId)10 Response (javax.ws.rs.core.Response)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 TransientTransactionFailureException (org.neo4j.graphdb.TransientTransactionFailureException)5 TestHighlyAvailableGraphDatabaseFactory (org.neo4j.graphdb.factory.TestHighlyAvailableGraphDatabaseFactory)5 RepairKit (org.neo4j.kernel.impl.ha.ClusterManager.RepairKit)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ClusterClient (org.neo4j.cluster.client.ClusterClient)4 TransactionTerminatedException (org.neo4j.graphdb.TransactionTerminatedException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IOException (java.io.IOException)3 URI (java.net.URI)3 ExecutionException (java.util.concurrent.ExecutionException)3