Skip to content

Commit

Permalink
Extract interface to StoreNodeCursor
Browse files Browse the repository at this point in the history
and moves some physical node reading details into it
  • Loading branch information
tinwelint committed Jun 11, 2018
1 parent 1a65ebc commit 66237dc
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 181 deletions.
Expand Up @@ -89,7 +89,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {

val bridge = mock[ThreadToStatementContextBridge]
val transaction = mock[KernelTransaction]
when(transaction.cursors()).thenReturn(new DefaultCursors())
when(transaction.cursors()).thenReturn(new DefaultCursors(null))
when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction)
val tc = new Neo4jTransactionalContext(graph, bridge, locker, outerTx, statement,null, null)
val transactionalContext = TransactionalContextWrapper(tc)
Expand All @@ -113,7 +113,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {
val bridge = mock[ThreadToStatementContextBridge]
val transaction = mock[KernelTransaction]
when(transaction.acquireStatement()).thenReturn(statement)
when(transaction.cursors()).thenReturn(new DefaultCursors())
when(transaction.cursors()).thenReturn(new DefaultCursors(null))
when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction)
val tc = new Neo4jTransactionalContext(graph, bridge, locker, outerTx, statement,null, null)
val transactionalContext = TransactionalContextWrapper(tc)
Expand Down Expand Up @@ -216,7 +216,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {
val bridge = mock[ThreadToStatementContextBridge]
val transaction = mock[KernelTransaction]
when(transaction.acquireStatement()).thenReturn(statement)
when(transaction.cursors()).thenReturn(new DefaultCursors())
when(transaction.cursors()).thenReturn(new DefaultCursors(null))
when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction)
val tc = new Neo4jTransactionalContext(graph, bridge, locker, outerTx, statement, null, null)
val transactionalContext = TransactionalContextWrapper(tc)
Expand Down
Expand Up @@ -673,7 +673,7 @@ private NeoStoreKernelModule buildKernel( LogFiles logFiles, TransactionAppender
constraintIndexCreator, statementOperationParts, schemaWriteGuard, transactionHeaderInformationFactory,
transactionCommitProcess, indexConfigStore, explicitIndexProviderLookup, hooks, transactionMonitor,
availabilityGuard, tracers, storageEngine, procedures, transactionIdStore, clock,
cpuClockRef, heapAllocationRef, accessCapability, DefaultCursors::new, autoIndexing,
cpuClockRef, heapAllocationRef, accessCapability, DefaultCursors.supplier( storageEngine ), autoIndexing,
explicitIndexStore, versionContextSupplier, collectionsFactorySupplier, constraintSemantics,
databaseSchemaState, indexingService, propertyKeyTokenHolder ) );

Expand Down
Expand Up @@ -73,9 +73,6 @@
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
Expand Down Expand Up @@ -104,7 +101,6 @@

public class AllStoreHolder extends Read
{
private final StorageReader.Nodes nodes;
private final StorageReader.Groups groups;
private final StorageReader.Properties properties;
private final StorageReader.Relationships relationships;
Expand All @@ -123,7 +119,6 @@ public AllStoreHolder(
{
super( cursors, ktx );
this.storageReader = storageReader;
this.nodes = storageReader.nodes();
this.relationships = storageReader.relationships();
this.groups = storageReader.groups();
this.properties = storageReader.properties();
Expand Down Expand Up @@ -672,12 +667,6 @@ public Iterator<ConstraintDescriptor> constraintsGetForRelationshipType( int typ
return constraints;
}

@Override
PageCursor nodePage( long reference )
{
return nodes.openPageCursorForReading( reference );
}

@Override
PageCursor relationshipPage( long reference )
{
Expand Down Expand Up @@ -708,24 +697,6 @@ PageCursor arrayPage( long reference )
return properties.openArrayPageCursor( reference );
}

@Override
RecordCursor<DynamicRecord> labelCursor()
{
return nodes.newLabelCursor();
}

@Override
void node( NodeRecord record, long reference, PageCursor pageCursor )
{
nodes.getRecordByCursor( reference, record, RecordLoad.CHECK, pageCursor );
}

@Override
void nodeAdvance( NodeRecord record, PageCursor pageCursor )
{
nodes.nextRecordByCursor( record, RecordLoad.CHECK, pageCursor );
}

@Override
void relationship( RelationshipRecord record, long reference, PageCursor pageCursor )
{
Expand Down Expand Up @@ -769,12 +740,6 @@ void group( RelationshipGroupRecord record, long reference, PageCursor page )
groups.getRecordByCursor( reference, record, RecordLoad.FORCE, page );
}

@Override
long nodeHighMark()
{
return nodes.getHighestPossibleIdInUse();
}

@Override
long relationshipHighMark()
{
Expand Down
Expand Up @@ -24,15 +24,19 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

import org.neo4j.internal.kernel.api.AutoCloseablePlus;
import org.neo4j.internal.kernel.api.CursorFactory;
import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.storageengine.api.StorageReader;

import static java.lang.String.format;
import static org.neo4j.util.FeatureToggles.flag;

public class DefaultCursors implements CursorFactory
{
private final StorageReader storageReader;
private DefaultNodeCursor nodeCursor;
private DefaultRelationshipScanCursor relationshipScanCursor;
private DefaultRelationshipTraversalCursor relationshipTraversalCursor;
Expand All @@ -46,12 +50,22 @@ public class DefaultCursors implements CursorFactory
private static final boolean DEBUG_CLOSING = flag( DefaultCursors.class, "trackCursors", false );
private List<CloseableStacktrace> closeables = new ArrayList<>();

public DefaultCursors( StorageReader storageReader )
{
this.storageReader = storageReader;
}

public static Supplier<DefaultCursors> supplier( StorageEngine storageEngine )
{
return () -> new DefaultCursors( storageEngine.newReader() );
}

@Override
public DefaultNodeCursor allocateNodeCursor()
{
if ( nodeCursor == null )
{
return trace( new DefaultNodeCursor( this ) );
return trace( new DefaultNodeCursor( this, storageReader.allocateNodeCursor() ) );
}

try
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.neo4j.internal.kernel.api.RelationshipGroupCursor;
import org.neo4j.internal.kernel.api.RelationshipTraversalCursor;
import org.neo4j.kernel.api.txstate.TransactionState;
import org.neo4j.storageengine.api.StorageNodeCursor;
import org.neo4j.storageengine.api.txstate.LongDiffSets;
import org.neo4j.storageengine.api.txstate.NodeState;

Expand All @@ -43,20 +44,20 @@ class DefaultNodeCursor implements NodeCursor
private Read read;
private HasChanges hasChanges = HasChanges.MAYBE;
private LongIterator addedNodes;
private StoreNodeCursor storeCursor;
private StorageNodeCursor storeCursor;
private long single;

private final DefaultCursors pool;

DefaultNodeCursor( DefaultCursors pool )
DefaultNodeCursor( DefaultCursors pool, StorageNodeCursor storeCursor )
{
this.pool = pool;
this.storeCursor = new StoreNodeCursor();
this.storeCursor = storeCursor;
}

void scan( Read read )
{
storeCursor.scan( read );
storeCursor.scan();
this.read = read;
this.single = NO_ID;
this.hasChanges = HasChanges.MAYBE;
Expand All @@ -65,7 +66,7 @@ void scan( Read read )

void single( long reference, Read read )
{
storeCursor.single( reference, read );
storeCursor.single( reference );
this.read = read;
this.single = reference;
this.hasChanges = HasChanges.MAYBE;
Expand Down
Expand Up @@ -50,9 +50,6 @@
import org.neo4j.kernel.impl.locking.LockTracer;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.ResourceTypes;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
Expand Down Expand Up @@ -571,8 +568,6 @@ public final void futureRelationshipPropertyReferenceRead( long reference )
@Override
public abstract IndexReference index( int label, int... properties );

abstract PageCursor nodePage( long reference );

abstract PageCursor relationshipPage( long reference );

abstract PageCursor groupPage( long reference );
Expand All @@ -583,12 +578,6 @@ public final void futureRelationshipPropertyReferenceRead( long reference )

abstract PageCursor arrayPage( long reference );

abstract RecordCursor<DynamicRecord> labelCursor();

abstract void node( NodeRecord record, long reference, PageCursor pageCursor );

abstract void nodeAdvance( NodeRecord record, PageCursor pageCursor );

abstract void relationship( RelationshipRecord record, long reference, PageCursor pageCursor );

abstract void relationshipAdvance( RelationshipRecord record, PageCursor pageCursor );
Expand All @@ -599,8 +588,6 @@ public final void futureRelationshipPropertyReferenceRead( long reference )

abstract void group( RelationshipGroupRecord record, long reference, PageCursor page );

abstract long nodeHighMark();

abstract long relationshipHighMark();

abstract TextValue string( StorePropertyCursor cursor, long reference, PageCursor page );
Expand Down

0 comments on commit 66237dc

Please sign in to comment.