Search in sources :

Example 1 with IndexPopulationProgress

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

the class SchemaImplTest method testGetIndexPopulationProgress.

@Test
void testGetIndexPopulationProgress() throws Exception {
    assertFalse(indexExists(USER_LABEL));
    // 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 = tx.createNode(label);
            userNode.setProperty("username", "user" + id + "@neo4j.org");
        }
        tx.commit();
    }
    // Create an index
    IndexDefinition indexDefinition;
    try (Transaction tx = db.beginTx()) {
        Schema schema = tx.schema();
        indexDefinition = schema.indexFor(USER_LABEL).on("username").create();
        tx.commit();
    }
    // Get state and progress
    try (Transaction tx = db.beginTx()) {
        Schema schema = tx.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);
        assertSame(state, Schema.IndexState.ONLINE);
        assertEquals(100.0, progress.getCompletedPercentage(), 0.0001);
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexPopulationProgress(org.neo4j.graphdb.schema.IndexPopulationProgress) Node(org.neo4j.graphdb.Node) Schema(org.neo4j.graphdb.schema.Schema) Label(org.neo4j.graphdb.Label) Test(org.junit.jupiter.api.Test)

Example 2 with IndexPopulationProgress

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

the class SchemaImpl method getIndexPopulationProgress.

@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
    try {
        transaction.assertOpen();
        SchemaRead schemaRead = transaction.schemaRead();
        IndexDescriptor descriptor = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
        PopulationProgress progress = schemaRead.indexGetPopulationProgress(descriptor);
        return progress.toIndexPopulationProgress();
    } catch (KernelException e) {
        throw newIndexNotFoundException(index, e);
    }
}
Also used : PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) IndexPopulationProgress(org.neo4j.graphdb.schema.IndexPopulationProgress) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

IndexPopulationProgress (org.neo4j.graphdb.schema.IndexPopulationProgress)2 Test (org.junit.jupiter.api.Test)1 KernelException (org.neo4j.exceptions.KernelException)1 Label (org.neo4j.graphdb.Label)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)1 Schema (org.neo4j.graphdb.schema.Schema)1 PopulationProgress (org.neo4j.internal.kernel.api.PopulationProgress)1 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)1 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)1 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)1 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)1 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1