Search in sources :

Example 1 with IndexPopulationProgress

use of org.neo4j.graphdb.index.IndexPopulationProgress in project neo4j by neo4j.

the class SchemaImplTest method testGetIndexPopulationProgress.

@Test
public void testGetIndexPopulationProgress() throws Exception {
    assertFalse(indexExists(Label.label("User")));
    // Create some nodes
    try (Transaction tx = db.beginTx()) {
        Label label = Label.label("User");
        // Create a huge bunch of users so the index takes a while to build
        for (int id = 0; id < 100000; id++) {
            Node userNode = db.createNode(label);
            userNode.setProperty("username", "user" + id + "@neo4j.org");
        }
        tx.success();
    }
    // Create an index
    IndexDefinition indexDefinition;
    try (Transaction tx = db.beginTx()) {
        Schema schema = db.schema();
        indexDefinition = schema.indexFor(Label.label("User")).on("username").create();
        tx.success();
    }
    // Get state and progress
    try (Transaction tx = db.beginTx()) {
        Schema schema = db.schema();
        Schema.IndexState state;
        IndexPopulationProgress progress;
        do {
            state = schema.getIndexState(indexDefinition);
            progress = schema.getIndexPopulationProgress(indexDefinition);
            assertTrue(progress.getCompletedPercentage() >= 0);
            assertTrue(progress.getCompletedPercentage() <= 100);
            Thread.sleep(10);
        } while (state == Schema.IndexState.POPULATING);
        assertTrue(state == Schema.IndexState.ONLINE);
        assertEquals(100.0f, progress.getCompletedPercentage(), 0.0f);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) Node(org.neo4j.graphdb.Node) Schema(org.neo4j.graphdb.schema.Schema) Label(org.neo4j.graphdb.Label) Test(org.junit.Test)

Example 2 with IndexPopulationProgress

use of org.neo4j.graphdb.index.IndexPopulationProgress in project neo4j by neo4j.

the class SchemaImpl method getIndexPopulationProgress.

@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        PopulationProgress progress = readOps.indexGetPopulationProgress(descriptor);
        return new IndexPopulationProgress(progress.getCompleted(), progress.getTotal());
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new NotFoundException(format("No index for label %s on property %s", index.getLabel().name(), index.getPropertyKeys()));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) IndexPopulationProgress(org.neo4j.graphdb.index.IndexPopulationProgress) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Aggregations

IndexPopulationProgress (org.neo4j.graphdb.index.IndexPopulationProgress)2 Test (org.junit.Test)1 Label (org.neo4j.graphdb.Label)1 Node (org.neo4j.graphdb.Node)1 NotFoundException (org.neo4j.graphdb.NotFoundException)1 Transaction (org.neo4j.graphdb.Transaction)1 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)1 Schema (org.neo4j.graphdb.schema.Schema)1 ReadOperations (org.neo4j.kernel.api.ReadOperations)1 Statement (org.neo4j.kernel.api.Statement)1 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)1 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)1 PopulationProgress (org.neo4j.storageengine.api.schema.PopulationProgress)1