Skip to content

Commit

Permalink
Acquire FreshIndexReader in the StorageLayer
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed May 8, 2017
1 parent 290af31 commit b09d1c8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
Expand Up @@ -718,21 +718,21 @@ public Iterator<IndexDescriptor> indexesGetAll( KernelStatement state )
} }


@Override @Override
public long nodeGetFromUniqueIndexSeek( public long nodeGetFromUniqueIndexSeek( KernelStatement statement, IndexDescriptor index,
KernelStatement state, IndexDescriptor index, IndexQuery.ExactPredicate... query ) IndexQuery.ExactPredicate... query )
throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException throws IndexNotFoundKernelException, IndexBrokenKernelException, IndexNotApplicableKernelException
{ {
IndexReader reader = state.getStoreStatement().getFreshIndexReader( index ); IndexReader reader = storeLayer.indexGetFreshReader( statement.getStoreStatement(), index );


/* Here we have an intricate scenario where we need to return the PrimitiveLongIterator /* 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 * 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 * 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 * a fresh reader that isn't associated with the current transaction and hence will not be
* automatically closed. */ * automatically closed. */
PrimitiveLongResourceIterator committed = resourceIterator( reader.query( query ), reader ); PrimitiveLongResourceIterator committed = resourceIterator( reader.query( query ), reader );
PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches( this, state, committed, query ); PrimitiveLongIterator exactMatches = LookupFilter.exactIndexMatches( this, statement, committed, query );
PrimitiveLongIterator changesFiltered = PrimitiveLongIterator changesFiltered =
filterIndexStateChangesForSeek( state, exactMatches, index, OrderedPropertyValues.of( query ) ); filterIndexStateChangesForSeek( statement, exactMatches, index, OrderedPropertyValues.of( query ) );
return single( resourceIterator( changesFiltered, committed ), NO_SUCH_NODE ); return single( resourceIterator( changesFiltered, committed ), NO_SUCH_NODE );
} }


Expand Down
Expand Up @@ -269,6 +269,13 @@ public IndexReader indexGetReader( StorageStatement statement, IndexDescriptor i
return statement.getIndexReader( index ); return statement.getIndexReader( index );
} }


@Override
public IndexReader indexGetFreshReader( StorageStatement statement, IndexDescriptor index )
throws IndexNotFoundKernelException
{
return statement.getFreshIndexReader( index );
}

@Override @Override
public Iterator<ConstraintDescriptor> constraintsGetForSchema( SchemaDescriptor descriptor ) public Iterator<ConstraintDescriptor> constraintsGetForSchema( SchemaDescriptor descriptor )
{ {
Expand Down
Expand Up @@ -170,6 +170,9 @@ long indexGetCommittedId( IndexDescriptor index )
IndexReader indexGetReader( StorageStatement statement, IndexDescriptor index ) IndexReader indexGetReader( StorageStatement statement, IndexDescriptor index )
throws IndexNotFoundKernelException; throws IndexNotFoundKernelException;


IndexReader indexGetFreshReader( StorageStatement storeStatement, IndexDescriptor index )
throws IndexNotFoundKernelException;

/** /**
* @param labelName name of label. * @param labelName name of label.
* @return token id of label. * @return token id of label.
Expand Down
Expand Up @@ -40,7 +40,6 @@
import org.neo4j.kernel.impl.api.StatementOperationsTestHelper; import org.neo4j.kernel.impl.api.StatementOperationsTestHelper;
import org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing; import org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing;
import org.neo4j.kernel.impl.api.operations.EntityOperations; import org.neo4j.kernel.impl.api.operations.EntityOperations;
import org.neo4j.kernel.impl.api.store.StoreStatement;
import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics; import org.neo4j.kernel.impl.constraints.StandardConstraintSemantics;
import org.neo4j.kernel.impl.index.LegacyIndexStore; import org.neo4j.kernel.impl.index.LegacyIndexStore;
import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.NodeItem;
Expand Down Expand Up @@ -98,9 +97,8 @@ public void before() throws Exception
indexReader = mock( IndexReader.class ); indexReader = mock( IndexReader.class );
when( store.indexGetReader( any( StorageStatement.class ), eq( indexDescriptor ) ) ) when( store.indexGetReader( any( StorageStatement.class ), eq( indexDescriptor ) ) )
.thenReturn( indexReader ); .thenReturn( indexReader );
StoreStatement statement = mock( StoreStatement.class ); when( store.indexGetFreshReader( any( StorageStatement.class ), eq( indexDescriptor ) ) )
when( state.getStoreStatement() ).thenReturn( statement ); .thenReturn( indexReader );
when( statement.getFreshIndexReader( indexDescriptor ) ).thenReturn( indexReader );


StateHandlingStatementOperations stateHandlingOperations = new StateHandlingStatementOperations( StateHandlingStatementOperations stateHandlingOperations = new StateHandlingStatementOperations(
store, store,
Expand Down
Expand Up @@ -472,14 +472,13 @@ public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWit
public void indexQueryClosesIndexReader() throws Exception public void indexQueryClosesIndexReader() throws Exception
{ {
KernelStatement kernelStatement = mock( KernelStatement.class ); KernelStatement kernelStatement = mock( KernelStatement.class );
StoreStatement storeStatement = mock( StoreStatement.class );
IndexReader indexReader = mock( IndexReader.class ); IndexReader indexReader = mock( IndexReader.class );

when( indexReader.query( any() ) ).thenReturn( PrimitiveLongCollections.emptyIterator() ); when( indexReader.query( any() ) ).thenReturn( PrimitiveLongCollections.emptyIterator() );
when( storeStatement.getFreshIndexReader( any() ) ).thenReturn( indexReader ); StoreReadLayer storeReadLayer = mock( StoreReadLayer.class );
when( kernelStatement.getStoreStatement() ).thenReturn( storeStatement ); when( storeReadLayer.indexGetFreshReader( any( StorageStatement.class ), any( IndexDescriptor.class ) ) )
.thenReturn( indexReader );


StateHandlingStatementOperations operations = newTxStateOps( mock( StoreReadLayer.class ) ); StateHandlingStatementOperations operations = newTxStateOps( storeReadLayer );


operations.nodeGetFromUniqueIndexSeek( operations.nodeGetFromUniqueIndexSeek(
kernelStatement, kernelStatement,
Expand Down

0 comments on commit b09d1c8

Please sign in to comment.