Search in sources :

Example 1 with IndexNotApplicableKernelException

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

the class Operations method validateNoExistingNodeWithExactValues.

/**
 * Check so that there is not an existing node with the exact match of label and property
 */
private void validateNoExistingNodeWithExactValues(IndexBackedConstraintDescriptor constraint, PropertyIndexQuery.ExactPredicate[] propertyValues, long modifiedNode) throws UniquePropertyValueValidationException, UnableToValidateConstraintException {
    IndexDescriptor index = allStoreHolder.indexGetForName(constraint.getName());
    try (FullAccessNodeValueIndexCursor valueCursor = cursors.allocateFullAccessNodeValueIndexCursor(ktx.cursorContext(), memoryTracker);
        IndexReaders indexReaders = new IndexReaders(index, allStoreHolder)) {
        assertIndexOnline(index);
        SchemaDescriptor schema = index.schema();
        long[] labelIds = schema.lockingKeys();
        if (labelIds.length != 1) {
            throw new UnableToValidateConstraintException(constraint, new AssertionError(format("Constraint indexes are not expected to be multi-token indexes, " + "but the constraint %s was referencing an index with the following schema: %s.", constraint.userDescription(token), schema.userDescription(token))), token);
        }
        // Take a big fat lock, and check for existing node in index
        ktx.lockClient().acquireExclusive(ktx.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelIds[0], propertyValues));
        allStoreHolder.nodeIndexSeekWithFreshIndexReader(valueCursor, indexReaders.createReader(), propertyValues);
        if (valueCursor.next() && valueCursor.nodeReference() != modifiedNode) {
            throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(valueCursor.nodeReference(), NO_SUCH_NODE, PropertyIndexQuery.asValueTuple(propertyValues)), token);
        }
    } catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
        throw new UnableToValidateConstraintException(constraint, e, token);
    }
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) UnableToValidateConstraintException(org.neo4j.kernel.api.exceptions.schema.UnableToValidateConstraintException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)

Example 2 with IndexNotApplicableKernelException

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

the class SchemaComplianceChecker method queryIndexOrEmpty.

private static LongIterator queryIndexOrEmpty(ValueIndexReader reader, PropertyIndexQuery[] query) {
    try {
        NodeValueIterator indexedNodeIds = new NodeValueIterator();
        reader.query(NULL_CONTEXT, indexedNodeIds, unconstrained(), query);
        return indexedNodeIds;
    } catch (IndexNotApplicableKernelException e) {
        throw new RuntimeException(format("Consistency checking error: index provider does not support exact query %s", Arrays.toString(query)), e);
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)

Example 3 with IndexNotApplicableKernelException

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

the class NativeIndexAccessorTests method expectIndexOrder.

private static void expectIndexOrder(Value[] allValues, ValueGroup valueGroup, ValueIndexReader reader, IndexOrder supportedOrder, PropertyIndexQuery.RangePredicate<?> supportedQuery) throws IndexNotApplicableKernelException {
    Value[] expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).toArray(Value[]::new);
    if (supportedOrder == IndexOrder.ASCENDING) {
        Arrays.sort(expectedValues, Values.COMPARATOR);
    } else if (supportedOrder == IndexOrder.DESCENDING) {
        Arrays.sort(expectedValues, Values.COMPARATOR.reversed());
    }
    SimpleEntityValueClient client = new SimpleEntityValueClient();
    reader.query(NULL_CONTEXT, client, constrained(supportedOrder, true), supportedQuery);
    int i = 0;
    while (client.next()) {
        assertEquals(expectedValues[i++], client.values[0], "values in order");
    }
    assertEquals(i, expectedValues.length, "found all values");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IndexOrder(org.neo4j.internal.schema.IndexOrder) Arrays(java.util.Arrays) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Iterators.filter(org.neo4j.internal.helpers.collection.Iterators.filter) NULL_CONTEXT(org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT) Value(org.neo4j.values.storable.Value) RandomValues(org.neo4j.values.storable.RandomValues) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) IndexEntryUpdate.remove(org.neo4j.storageengine.api.IndexEntryUpdate.remove) Predicates.alwaysTrue(org.neo4j.function.Predicates.alwaysTrue) EMPTY_LONG_ARRAY(org.neo4j.collection.PrimitiveLongCollections.EMPTY_LONG_ARRAY) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) Collectors(java.util.stream.Collectors) PointValue(org.neo4j.values.storable.PointValue) String.format(java.lang.String.format) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueCreatorUtil.countUniqueValues(org.neo4j.kernel.impl.index.schema.ValueCreatorUtil.countUniqueValues) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexDirectoryStructure.directoriesByProvider(org.neo4j.kernel.api.index.IndexDirectoryStructure.directoriesByProvider) Iterables.asUniqueSet(org.neo4j.internal.helpers.collection.Iterables.asUniqueSet) IndexQueryConstraints.unorderedValues(org.neo4j.internal.kernel.api.IndexQueryConstraints.unorderedValues) IndexEntryUpdate.change(org.neo4j.storageengine.api.IndexEntryUpdate.change) Predicates.in(org.neo4j.function.Predicates.in) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexSample(org.neo4j.kernel.api.index.IndexSample) Iterator(java.util.Iterator) ValueType(org.neo4j.values.storable.ValueType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) IndexQueryConstraints.constrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.constrained) PrimitiveLongCollections(org.neo4j.collection.PrimitiveLongCollections) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) LongIterator(org.eclipse.collections.api.iterator.LongIterator) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) Values.of(org.neo4j.values.storable.Values.of) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) ValueGroup(org.neo4j.values.storable.ValueGroup) Collections(java.util.Collections) ONLINE(org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 4 with IndexNotApplicableKernelException

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

the class FusionIndexReader method query.

@Override
public void query(QueryContext context, IndexProgressor.EntityValueClient cursor, IndexQueryConstraints constraints, PropertyIndexQuery... predicates) throws IndexNotApplicableKernelException {
    IndexSlot slot = slotSelector.selectSlot(predicates, PropertyIndexQuery::valueCategory);
    if (slot != null) {
        instanceSelector.select(slot).query(context, cursor, constraints, predicates);
    } else {
        if (constraints.isOrdered()) {
            throw new UnsupportedOperationException(format("Tried to query index with unsupported order %s. Supported orders for query %s are %s.", constraints.order(), Arrays.toString(predicates), IndexOrder.NONE));
        }
        BridgingIndexProgressor multiProgressor = new BridgingIndexProgressor(cursor, descriptor.schema().getPropertyIds());
        cursor.initialize(descriptor, multiProgressor, predicates, constraints, false);
        try {
            instanceSelector.forAll(reader -> {
                try {
                    reader.query(context, multiProgressor, constraints, predicates);
                } catch (IndexNotApplicableKernelException e) {
                    throw new InnerException(e);
                }
            });
        } catch (InnerException e) {
            throw e.getCause();
        }
    }
}
Also used : IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) BridgingIndexProgressor(org.neo4j.kernel.api.index.BridgingIndexProgressor)

Example 5 with IndexNotApplicableKernelException

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

the class SimpleValueIndexReader method toLuceneQuery.

private static Query toLuceneQuery(PropertyIndexQuery... predicates) throws IndexNotApplicableKernelException {
    PropertyIndexQuery predicate = predicates[0];
    switch(predicate.type()) {
        case exact:
            Value[] values = new Value[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] = ((PropertyIndexQuery.ExactPredicate) predicates[i]).value();
            }
            return LuceneDocumentStructure.newSeekQuery(values);
        case exists:
            for (PropertyIndexQuery p : predicates) {
                if (p.type() != IndexQueryType.exists) {
                    throw new IndexNotApplicableKernelException("Exists followed by another query predicate type is not supported.");
                }
            }
            return LuceneDocumentStructure.newScanQuery();
        case range:
            assertNotComposite(predicates);
            if (predicate.valueGroup() == ValueGroup.TEXT) {
                PropertyIndexQuery.TextRangePredicate sp = (PropertyIndexQuery.TextRangePredicate) predicate;
                return LuceneDocumentStructure.newRangeSeekByStringQuery(sp.from(), sp.fromInclusive(), sp.to(), sp.toInclusive());
            }
            throw new UnsupportedOperationException(format("Range scans of value group %s are not supported", predicate.valueGroup()));
        case stringPrefix:
            assertNotComposite(predicates);
            PropertyIndexQuery.StringPrefixPredicate spp = (PropertyIndexQuery.StringPrefixPredicate) predicate;
            return LuceneDocumentStructure.newRangeSeekByPrefixQuery(spp.prefix().stringValue());
        case stringContains:
            assertNotComposite(predicates);
            PropertyIndexQuery.StringContainsPredicate scp = (PropertyIndexQuery.StringContainsPredicate) predicate;
            return LuceneDocumentStructure.newWildCardStringQuery(scp.contains().stringValue());
        case stringSuffix:
            assertNotComposite(predicates);
            PropertyIndexQuery.StringSuffixPredicate ssp = (PropertyIndexQuery.StringSuffixPredicate) predicate;
            return LuceneDocumentStructure.newSuffixStringQuery(ssp.suffix().stringValue());
        default:
            // todo figure out a more specific exception
            throw new RuntimeException("Index query not supported: " + Arrays.toString(predicates));
    }
}
Also used : IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) Value(org.neo4j.values.storable.Value)

Aggregations

IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)10 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)5 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)5 Test (org.junit.jupiter.api.Test)4 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 LongIterator (org.eclipse.collections.api.iterator.LongIterator)2 Assertions.assertArrayEquals (org.junit.jupiter.api.Assertions.assertArrayEquals)2