Search in sources :

Example 51 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class RemoveOrphanConstraintIndexesOnStartup method perform.

public void perform() {
    try (KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        for (NewIndexDescriptor index : loop(statement.readOperations().uniqueIndexesGetAll())) {
            if (statement.readOperations().indexGetOwningUniquenessConstraintId(index) == null) {
                log.info("Removing orphan constraint index: " + index);
                statement.schemaWriteOperations().uniqueIndexDrop(index);
            }
        }
        transaction.success();
    } catch (KernelException e) {
        log.error("Failed to execute orphan index checking transaction.", e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 52 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class StateHandlingStatementOperations method indexCreate.

@Override
public NewIndexDescriptor indexCreate(KernelStatement state, LabelSchemaDescriptor descriptor) {
    NewIndexDescriptor indexDescriptor = NewIndexDescriptorFactory.forSchema(descriptor);
    state.txState().indexRuleDoAdd(indexDescriptor);
    return indexDescriptor;
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 53 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor 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)

Example 54 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaImpl method getIndexState.

@Override
public IndexState getIndexState(final IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        InternalIndexState indexState = readOps.indexGetState(descriptor);
        switch(indexState) {
            case POPULATING:
                return POPULATING;
            case ONLINE:
                return ONLINE;
            case FAILED:
                return FAILED;
            default:
                throw new IllegalArgumentException(String.format("Illegal index state %s", indexState));
        }
    } 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) InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) 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)

Example 55 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaImpl method getIndexFailure.

@Override
public String getIndexFailure(IndexDefinition index) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        ReadOperations readOps = statement.readOperations();
        NewIndexDescriptor descriptor = getIndexDescriptor(readOps, index);
        return readOps.indexGetFailure(descriptor);
    } 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) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) 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

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4