Search in sources :

Example 26 with IndexReader

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

the class StateHandlingStatementOperations method nodeGetFromUniqueIndexSeek.

@Override
public long nodeGetFromUniqueIndexSeek(KernelStatement state, NewIndexDescriptor index, IndexQuery.ExactPredicate... query) throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException {
    IndexReader reader = state.getStoreStatement().getFreshIndexReader(index);
    /* Here we have an intricate scenario where we need to return the PrimitiveLongIterator
         * since subsequent filtering will happen outside, but at the same time have the ability to
         * close the IndexReader when done iterating over the lookup result. This is because we get
         * a fresh reader that isn't associated with the current transaction and hence will not be
         * automatically closed. */
    PrimitiveLongResourceIterator committed = resourceIterator(reader.query(query), reader);
    PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches(this, state, committed, query);
    PrimitiveLongIterator changesFiltered = filterIndexStateChangesForSeek(state, exactMatches, index, OrderedPropertyValues.of(query));
    return single(resourceIterator(changesFiltered, committed), NO_SUCH_NODE);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) PrimitiveLongResourceIterator(org.neo4j.collection.primitive.PrimitiveLongResourceIterator)

Example 27 with IndexReader

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

the class IndexQueryTransactionStateTest method before.

@Before
public void before() throws Exception {
    TransactionState txState = new TxState();
    state = StatementOperationsTestHelper.mockedState(txState);
    store = mock(StoreReadLayer.class);
    when(store.indexGetState(newIndexDescriptor)).thenReturn(InternalIndexState.ONLINE);
    when(store.indexesGetForLabel(labelId)).then(answerAsIteratorFrom(indexes));
    when(store.indexesGetAll()).then(answerAsIteratorFrom(indexes));
    when(store.constraintsGetForLabel(labelId)).thenReturn(Collections.emptyIterator());
    when(store.indexGetForLabelAndPropertyKey(newIndexDescriptor.schema())).thenReturn(newIndexDescriptor);
    statement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(statement);
    indexReader = mock(IndexReader.class);
    when(statement.getIndexReader(newIndexDescriptor)).thenReturn(indexReader);
    when(statement.getFreshIndexReader(newIndexDescriptor)).thenReturn(indexReader);
    StateHandlingStatementOperations stateHandlingOperations = new StateHandlingStatementOperations(store, new InternalAutoIndexing(Config.empty(), null), mock(ConstraintIndexCreator.class), mock(LegacyIndexStore.class));
    txContext = new ConstraintEnforcingEntityOperations(new StandardConstraintSemantics(), stateHandlingOperations, stateHandlingOperations, stateHandlingOperations, stateHandlingOperations);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) LegacyIndexStore(org.neo4j.kernel.impl.index.LegacyIndexStore) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) InternalAutoIndexing(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) ConstraintEnforcingEntityOperations(org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) Before(org.junit.Before)

Example 28 with IndexReader

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery() 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.StringSuffixPredicate indexQuery = IndexQuery.stringSuffix(index.schema().getPropertyId(), "suffix");
    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 29 with IndexReader

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

the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery.

@Test
public void shouldConsiderTransactionStateDuringIndexSeekWithIndexQuery() 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.indexUpdatesForSeek(index, OrderedPropertyValues.ofUndefined("value"))).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.ExactPredicate query = IndexQuery.exact(index.schema().getPropertyId(), "value");
    when(indexReader.query(query)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
    StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
    // When
    PrimitiveLongIterator results = context.indexQuery(statement, index, query);
    // 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 30 with IndexReader

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

the class StateHandlingStatementOperationsTest method indexQueryClosesIndexReader.

@Test
public void indexQueryClosesIndexReader() throws Exception {
    KernelStatement kernelStatement = mock(KernelStatement.class);
    StoreStatement storeStatement = mock(StoreStatement.class);
    IndexReader indexReader = mock(IndexReader.class);
    when(indexReader.query(any())).thenReturn(PrimitiveLongCollections.emptyIterator());
    when(storeStatement.getFreshIndexReader(any())).thenReturn(indexReader);
    when(kernelStatement.getStoreStatement()).thenReturn(storeStatement);
    StateHandlingStatementOperations operations = newTxStateOps(mock(StoreReadLayer.class));
    operations.nodeGetFromUniqueIndexSeek(kernelStatement, NewIndexDescriptorFactory.uniqueForLabel(1, 1), IndexQuery.exact(1, "foo"));
    verify(indexReader).close();
}
Also used : KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

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