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);
}
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);
}
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));
}
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));
}
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();
}
Aggregations