Search in sources :

Example 41 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class SchemaIndexHaIT method awaitIndexOnline.

private static void awaitIndexOnline(IndexDefinition requestedIndex, GraphDatabaseService db, Map<Object, Node> expectedData) throws InterruptedException {
    try (Transaction tx = db.beginTx()) {
        IndexDefinition index = reHomedIndexDefinition(db, requestedIndex);
        long timeout = System.currentTimeMillis() + SECONDS.toMillis(120);
        while (!indexOnline(index, db)) {
            Thread.sleep(1);
            if (System.currentTimeMillis() > timeout) {
                fail("Expected index to come online within a reasonable time.");
            }
        }
        assertIndexContents(index, db, expectedData);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Example 42 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition 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 43 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition 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 44 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition 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 45 with IndexDefinition

use of org.neo4j.graphdb.schema.IndexDefinition in project neo4j by neo4j.

the class Schema method awaitIndexes.

private void awaitIndexes(Output out, org.neo4j.graphdb.schema.Schema schema, Label[] labels, String property) throws RemoteException {
    for (IndexDefinition index : indexesByLabelAndProperty(schema, labels, property)) {
        if (schema.getIndexState(index) != IndexState.ONLINE) {
            out.println(String.format("Awaiting :%s ON %s %s", index.getLabel().name(), asList(index.getPropertyKeys()), IndexState.ONLINE));
            schema.awaitIndexOnline(index, 10000, TimeUnit.DAYS);
        }
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition)

Aggregations

IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)84 Test (org.junit.Test)56 Transaction (org.neo4j.graphdb.Transaction)32 StringContains.containsString (org.hamcrest.core.StringContains.containsString)11 Node (org.neo4j.graphdb.Node)9 Statement (org.neo4j.kernel.api.Statement)7 ArrayList (java.util.ArrayList)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 HighlyAvailableGraphDatabase (org.neo4j.kernel.ha.HighlyAvailableGraphDatabase)4 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)4 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)3 Iterator (java.util.Iterator)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 TransactionData (org.neo4j.graphdb.event.TransactionData)2 TransactionEventHandler (org.neo4j.graphdb.event.TransactionEventHandler)2 ConstraintDefinition (org.neo4j.graphdb.schema.ConstraintDefinition)2