Search in sources :

Example 1 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class StatementOperationsTestHelper method mockedState.

public static KernelStatement mockedState(final TransactionState txState) {
    KernelStatement state = mock(KernelStatement.class);
    Locks.Client locks = mock(Locks.Client.class);
    try {
        IndexReader indexReader = mock(IndexReader.class);
        when(indexReader.query(Matchers.isA(IndexQuery.ExactPredicate.class))).thenReturn(PrimitiveLongCollections.emptyIterator());
        StorageStatement storageStatement = mock(StorageStatement.class);
        when(storageStatement.getIndexReader(Matchers.any())).thenReturn(indexReader);
        when(state.getStoreStatement()).thenReturn(storageStatement);
    } catch (IndexNotFoundKernelException | IndexNotApplicableKernelException e) {
        throw new Error(e);
    }
    when(state.txState()).thenReturn(txState);
    when(state.hasTxStateWithChanges()).thenAnswer(invocation -> txState.hasChanges());
    when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
    when(state.readOperations()).thenReturn(mock(ReadOperations.class));
    return state;
}
Also used : SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) LegacyIndexReadOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations) ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) StorageStatement(org.neo4j.storageengine.api.StorageStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Locks(org.neo4j.kernel.impl.locking.Locks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 2 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class DirectNonUniqueIndexSampler method result.

@Override
public IndexSample result() {
    try {
        // lucene index needs to be flushed to be sure that reader will see all the data :(
        luceneIndex.flush();
        luceneIndex.maybeRefreshBlocking();
        try (IndexReader indexReader = luceneIndex.getIndexReader()) {
            IndexSampler sampler = indexReader.createSampler();
            return sampler.sampleIndex();
        } catch (IOException | IndexNotFoundKernelException e) {
            throw new RuntimeException(e);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IOException(java.io.IOException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler)

Example 3 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.

private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
    try {
        NewIndexDescriptor index = constraint.ownedIndexDescriptor();
        assertIndexOnline(state, index);
        int labelId = index.schema().getLabelId();
        state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
        long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
        if (existing != NO_SUCH_NODE && existing != modifiedNode) {
            throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
        }
    } catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
        throw new UnableToValidateConstraintException(constraint, e);
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UnableToValidateConstraintException(org.neo4j.kernel.api.exceptions.schema.UnableToValidateConstraintException) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)

Example 4 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class Schema method sampleIndexes.

private void sampleIndexes(Label[] labels, String property, boolean sampleAll, boolean forceSample) throws ShellException {
    IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency(IndexingService.class);
    if (indexingService == null) {
        throw new ShellException("Internal error: failed to resolve IndexingService");
    }
    IndexSamplingMode samplingMode = getSamplingMode(forceSample);
    // Trigger sampling for all indices
    if (sampleAll) {
        indexingService.triggerIndexSampling(samplingMode);
        return;
    }
    validateLabelsAndProperty(labels, property);
    Statement statement = getServer().getStatement();
    int labelKey = statement.readOperations().labelGetForName(labels[0].name());
    int propertyKey = statement.readOperations().propertyKeyGetForName(property);
    if (labelKey == -1) {
        throw new ShellException("No label associated with '" + labels[0].name() + "' was found");
    }
    if (propertyKey == -1) {
        throw new ShellException("No property associated with '" + property + "' was found");
    }
    try {
        indexingService.triggerIndexSampling(SchemaDescriptorFactory.forLabel(labelKey, propertyKey), samplingMode);
    } catch (IndexNotFoundKernelException e) {
        throw new ShellException(e.getMessage());
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Statement(org.neo4j.kernel.api.Statement) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ShellException(org.neo4j.shell.ShellException)

Example 5 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class BuiltInProcedures method listIndexes.

@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
    try (Statement statement = tx.acquireStatement()) {
        ReadOperations operations = statement.readOperations();
        TokenNameLookup tokens = new StatementTokenNameLookup(operations);
        List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
        Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
        indexes.addAll(uniqueIndexes);
        indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
        ArrayList<IndexResult> result = new ArrayList<>();
        for (NewIndexDescriptor index : indexes) {
            try {
                String type;
                if (uniqueIndexes.contains(index)) {
                    type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
                } else {
                    type = IndexType.NODE_LABEL_PROPERTY.typeName();
                }
                result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
            } catch (IndexNotFoundKernelException e) {
                throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
            }
        }
        return result.stream();
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Label(org.neo4j.graphdb.Label) Context(org.neo4j.procedure.Context) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ArrayList(java.util.ArrayList) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Procedure(org.neo4j.procedure.Procedure) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) ReadOperations(org.neo4j.kernel.api.ReadOperations) Set(java.util.Set) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) Comparator(java.util.Comparator) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ReadOperations(org.neo4j.kernel.api.ReadOperations) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Aggregations

IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 IOException (java.io.IOException)5 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)4 Test (org.junit.Test)3 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)3 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)3 List (java.util.List)2 TaskCoordinator (org.neo4j.helpers.TaskCoordinator)2 Iterators.asSet (org.neo4j.helpers.collection.Iterators.asSet)2 Statement (org.neo4j.kernel.api.Statement)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2 IndexNotApplicableKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)2 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1