Search in sources :

Example 1 with IndexNotApplicableKernelException

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

the class PropertyAndNodeIndexedCheck method verifyNodeCorrectlyIndexedUniquely.

private void verifyNodeCorrectlyIndexedUniquely(long nodeId, int propertyKeyId, Object propertyValue, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, IndexRule indexRule, IndexReader reader) {
    PrimitiveLongIterator indexedNodeIds = null;
    try {
        indexedNodeIds = reader.query(IndexQuery.exact(propertyKeyId, propertyValue));
    } catch (IndexNotApplicableKernelException e) {
        indexedNodeIds = PrimitiveLongCollections.emptyIterator();
    }
    // For verifying node indexed uniquely in offline CC, if one match found in the first stage match,
    // then there is no need to filter the result. The result is a exact match.
    // If multiple matches found, we need to filter the result to get exact matches.
    indexedNodeIds = filterIfMultipleValuesFound(indexedNodeIds, propertyKeyId, propertyValue);
    boolean found = false;
    while (indexedNodeIds.hasNext()) {
        long indexedNodeId = indexedNodeIds.next();
        if (nodeId == indexedNodeId) {
            found = true;
        } else {
            engine.report().uniqueIndexNotUnique(indexRule, propertyValue, indexedNodeId);
        }
    }
    if (!found) {
        engine.report().notIndexed(indexRule, propertyValue);
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)

Example 2 with IndexNotApplicableKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException 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 3 with IndexNotApplicableKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException 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 IndexNotApplicableKernelException

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

the class SimpleIndexReader method query.

@Override
public PrimitiveLongIterator query(IndexQuery... predicates) throws IndexNotApplicableKernelException {
    IndexQuery predicate = predicates[0];
    switch(predicate.type()) {
        case exact:
            Object[] values = new Object[predicates.length];
            for (int i = 0; i < predicates.length; i++) {
                assert predicates[i].type() == exact : "Exact followed by another query predicate type is not supported at this moment.";
                values[i] = ((IndexQuery.ExactPredicate) predicates[i]).value();
            }
            return seek(values);
        case exists:
            for (IndexQuery p : predicates) {
                if (p.type() != IndexQueryType.exists) {
                    throw new IndexNotApplicableKernelException("Exists followed by another query predicate type is not supported.");
                }
            }
            return scan();
        case rangeNumeric:
            assertNotComposite(predicates);
            IndexQuery.NumberRangePredicate np = (IndexQuery.NumberRangePredicate) predicate;
            return rangeSeekByNumberInclusive(np.from(), np.to());
        case rangeString:
            assertNotComposite(predicates);
            IndexQuery.StringRangePredicate sp = (IndexQuery.StringRangePredicate) predicate;
            return rangeSeekByString(sp.from(), sp.fromInclusive(), sp.to(), sp.toInclusive());
        case stringPrefix:
            assertNotComposite(predicates);
            IndexQuery.StringPrefixPredicate spp = (IndexQuery.StringPrefixPredicate) predicate;
            return rangeSeekByPrefix(spp.prefix());
        case stringContains:
            assertNotComposite(predicates);
            IndexQuery.StringContainsPredicate scp = (IndexQuery.StringContainsPredicate) predicate;
            return containsString(scp.contains());
        case stringSuffix:
            assertNotComposite(predicates);
            IndexQuery.StringSuffixPredicate ssp = (IndexQuery.StringSuffixPredicate) predicate;
            return endsWith(ssp.suffix());
        default:
            // todo figure out a more specific exception
            throw new RuntimeException("Index query not supported: " + Arrays.toString(predicates));
    }
}
Also used : IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)

Aggregations

IndexNotApplicableKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)4 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)1 ReadOperations (org.neo4j.kernel.api.ReadOperations)1 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)1 IndexBrokenKernelException (org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException)1 UnableToValidateConstraintException (org.neo4j.kernel.api.exceptions.schema.UnableToValidateConstraintException)1 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)1 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 EntityReadOperations (org.neo4j.kernel.impl.api.operations.EntityReadOperations)1 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)1 LegacyIndexReadOperations (org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations)1 SchemaReadOperations (org.neo4j.kernel.impl.api.operations.SchemaReadOperations)1 Locks (org.neo4j.kernel.impl.locking.Locks)1 SimpleStatementLocks (org.neo4j.kernel.impl.locking.SimpleStatementLocks)1 StorageStatement (org.neo4j.storageengine.api.StorageStatement)1 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)1