Search in sources :

Example 6 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForRangeSeekByString(index, "Anne", true, "Bill", false)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.StringRangePredicate rangePredicate = IndexQuery.range(index.schema().getPropertyId(), "Anne", true, "Bill", false);
    when(indexReader.query(rangePredicate)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, rangePredicate);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 7 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery() throws Exception {
    // Given
    TransactionState txState = mock(TransactionState.class);
    KernelStatement statement = mock(KernelStatement.class);
    when(statement.hasTxStateWithChanges()).thenReturn(true);
    when(statement.txState()).thenReturn(txState);
    when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
    when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    IndexReader indexReader = addMockedIndexReader(statement);
    IndexQuery.StringContainsPredicate indexQuery = IndexQuery.stringContains(index.schema().getPropertyId(), "contains");
    when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
    // Then
    assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 8 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class SimpleIndexPopulatorCompatibility method shouldApplyUpdatesIdempotently.

@Test
public void shouldApplyUpdatesIdempotently() throws Exception {
    // GIVEN
    IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.empty());
    IndexPopulator populator = indexProvider.getPopulator(17, descriptor, indexSamplingConfig);
    populator.create();
    populator.configureSampling(true);
    long nodeId = 1;
    final String propertyValue = "value1";
    PropertyAccessor propertyAccessor = (nodeId1, propertyKeyId) -> Property.stringProperty(propertyKeyId, propertyValue);
    // this update (using add())...
    populator.add(singletonList(IndexEntryUpdate.add(nodeId, descriptor.schema(), propertyValue)));
    // ...is the same as this update (using update())
    try (IndexUpdater updater = populator.newPopulatingUpdater(propertyAccessor)) {
        updater.process(add(nodeId, descriptor.schema(), propertyValue));
    }
    populator.close(true);
    // then
    IndexAccessor accessor = indexProvider.getOnlineAccessor(17, descriptor, indexSamplingConfig);
    try (IndexReader reader = accessor.newReader()) {
        int propertyKeyId = descriptor.schema().getPropertyId();
        PrimitiveLongIterator nodes = reader.query(IndexQuery.exact(propertyKeyId, propertyValue));
        assertEquals(asSet(1L), PrimitiveLongCollections.toSet(nodes));
    }
    accessor.close();
}
Also used : Arrays(java.util.Arrays) Config(org.neo4j.kernel.configuration.Config) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) Test(org.junit.Test) Property(org.neo4j.kernel.api.properties.Property) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) Collections.singletonList(java.util.Collections.singletonList) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Ignore(org.junit.Ignore) IndexEntryUpdate.add(org.neo4j.kernel.api.index.IndexEntryUpdate.add) FAILED(org.neo4j.kernel.api.index.InternalIndexState.FAILED) Assert.fail(org.junit.Assert.fail) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Assert.assertEquals(org.junit.Assert.assertEquals) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 9 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class IndexAccessorCompatibility method metaGet.

private List<Long> metaGet(ReaderInteraction interaction) throws Exception {
    try (IndexReader reader = accessor.newReader()) {
        List<Long> list = new LinkedList<>();
        for (PrimitiveLongIterator iterator = interaction.results(reader); iterator.hasNext(); ) {
            list.add(iterator.next());
        }
        Collections.sort(list);
        return list;
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) LinkedList(java.util.LinkedList)

Example 10 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class PropertyAndNodeIndexedCheck method checkIndexToLabels.

private void checkIndexToLabels(NodeRecord record, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, RecordAccess records, Collection<PropertyRecord> propertyRecs) {
    Set<Long> labels = NodeLabelReader.getListOfLabels(record, records, engine);
    List<PropertyBlock> properties = null;
    for (IndexRule indexRule : indexes.rules()) {
        long labelId = indexRule.schema().getLabelId();
        if (!labels.contains(labelId)) {
            continue;
        }
        if (properties == null) {
            properties = propertyReader.propertyBlocks(propertyRecs);
        }
        // assuming 1 property always
        int propertyId = indexRule.schema().getPropertyId();
        PropertyBlock property = propertyWithKey(properties, propertyId);
        if (property == null) {
            continue;
        }
        try (IndexReader reader = indexes.accessorFor(indexRule).newReader()) {
            Object propertyValue = propertyReader.propertyValue(property).value();
            long nodeId = record.getId();
            if (indexRule.canSupportUniqueConstraint()) {
                verifyNodeCorrectlyIndexedUniquely(nodeId, property.getKeyIndexId(), propertyValue, engine, indexRule, reader);
            } else {
                verifyNodeCorrectlyIndexed(nodeId, propertyValue, engine, indexRule, reader);
            }
        }
    }
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) IndexReader(org.neo4j.storageengine.api.schema.IndexReader)

Aggregations

IndexReader (org.neo4j.storageengine.api.schema.IndexReader)50 Test (org.junit.Test)38 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)19 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)10 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)10 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)9 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)9 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)6 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)5 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TermQuery (org.apache.lucene.search.TermQuery)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.fail (org.junit.Assert.fail)2 Before (org.junit.Before)2