Skip to content

Commit

Permalink
Revert "Merge pull request #9 from davidegrohmann/3.3-relationship-gr…
Browse files Browse the repository at this point in the history
…oup-cursor"

This reverts commit 06380f4, reversing
changes made to a204b9c.
  • Loading branch information
MishaDemianenko committed May 25, 2017
1 parent 67bd2b3 commit 2d1c557
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 183 deletions.
Expand Up @@ -44,7 +44,7 @@ protected <R extends AbstractBaseRecord> RecordStore<R> wrapStore( RecordStore<R
{ {
AccessStats accessStats = new AccessStats( store.getClass().getSimpleName(), store.getRecordsPerPage() ); AccessStats accessStats = new AccessStats( store.getClass().getSimpleName(), store.getRecordsPerPage() );
accessStatistics.register( store, accessStats ); accessStatistics.register( store, accessStats );
return new AccessStatsKeepingRecordStore<>( store, accessStats ); return new AccessStatsKeepingRecordStore( store, accessStats );
} }


private static class AccessStatsKeepingRecordStore<RECORD extends AbstractBaseRecord> private static class AccessStatsKeepingRecordStore<RECORD extends AbstractBaseRecord>
Expand All @@ -58,6 +58,11 @@ private static class AccessStatsKeepingRecordStore<RECORD extends AbstractBaseRe
this.accessStats = accessStats; this.accessStats = accessStats;
} }


protected AccessStats getAccessStats()
{
return accessStats;
}

@Override @Override
public RECORD getRecord( long id, RECORD record, RecordLoad load ) public RECORD getRecord( long id, RECORD record, RecordLoad load )
{ {
Expand Down
Expand Up @@ -32,7 +32,6 @@
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord; import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord;


import static org.neo4j.kernel.impl.api.store.StoreStatement.read;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP; import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE; import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;


Expand All @@ -49,7 +48,7 @@ public class DegreeVisitable implements DegreeVisitor.Visitable, Disposable
private long nodeId; private long nodeId;
private long groupId; private long groupId;


DegreeVisitable( RelationshipStore relationshipStore, RelationshipGroupStore groupStore, public DegreeVisitable( RelationshipStore relationshipStore, RelationshipGroupStore groupStore,
Consumer<DegreeVisitable> cache ) Consumer<DegreeVisitable> cache )
{ {
this.relationshipStore = relationshipStore; this.relationshipStore = relationshipStore;
Expand All @@ -74,7 +73,7 @@ public void accept( DegreeVisitor visitor )
boolean keepGoing = true; boolean keepGoing = true;
while ( keepGoing && groupId != NO_NEXT_RELATIONSHIP.longValue() ) while ( keepGoing && groupId != NO_NEXT_RELATIONSHIP.longValue() )
{ {
RelationshipGroupRecord record = read( groupId, groupStore, groupRecord, FORCE, groupCursor ); RelationshipGroupRecord record = StoreStatement.read( groupId, groupStore, groupRecord, FORCE, groupCursor );
if ( record.inUse() ) if ( record.inUse() )
{ {
int type = record.getType(); int type = record.getType();
Expand All @@ -89,12 +88,12 @@ public void accept( DegreeVisitor visitor )


private long countByFirstPrevPointer( long relationshipId ) private long countByFirstPrevPointer( long relationshipId )
{ {
if ( Record.NO_NEXT_RELATIONSHIP.is( relationshipId ) ) if ( relationshipId == Record.NO_NEXT_RELATIONSHIP.longValue() )
{ {
return 0; return 0;
} }
RelationshipRecord record = RelationshipRecord record =
read( relationshipId, relationshipStore, relationshipRecord, FORCE, relationshipCursor ); StoreStatement.read( relationshipId, relationshipStore, relationshipRecord, FORCE, relationshipCursor );
if ( record.getFirstNode() == nodeId ) if ( record.getFirstNode() == nodeId )
{ {
return record.getFirstPrevRel(); return record.getFirstPrevRel();
Expand Down

This file was deleted.

Expand Up @@ -56,6 +56,7 @@
import org.neo4j.kernel.impl.store.InvalidRecordException; import org.neo4j.kernel.impl.store.InvalidRecordException;
import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.NodeStore; import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.RecordStore; import org.neo4j.kernel.impl.store.RecordStore;
import org.neo4j.kernel.impl.store.RelationshipStore; import org.neo4j.kernel.impl.store.RelationshipStore;
import org.neo4j.kernel.impl.store.SchemaStorage; import org.neo4j.kernel.impl.store.SchemaStorage;
Expand Down Expand Up @@ -83,7 +84,9 @@
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;


import static org.neo4j.collection.primitive.Primitive.intSet; import static org.neo4j.collection.primitive.Primitive.intSet;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK; import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
import static org.neo4j.register.Registers.newDoubleLongRegister; import static org.neo4j.register.Registers.newDoubleLongRegister;
import static org.neo4j.storageengine.api.Direction.BOTH; import static org.neo4j.storageengine.api.Direction.BOTH;
import static org.neo4j.storageengine.api.Direction.INCOMING; import static org.neo4j.storageengine.api.Direction.INCOMING;
Expand Down Expand Up @@ -588,7 +591,15 @@ public PrimitiveIntSet relationshipTypes( StorageStatement statement, NodeItem n
PrimitiveIntSet set = intSet(); PrimitiveIntSet set = intSet();
if ( node.isDense() ) if ( node.isDense() )
{ {
statement.acquireRelationshipGroupCursor( node.nextGroupId() ).forAll( group -> set.add( group.type() ) ); RelationshipGroupRecord groupRecord = relationshipGroupStore.newRecord();
RecordCursor<RelationshipGroupRecord> cursor = statement.recordCursors().relationshipGroup();
for ( long id = node.nextGroupId(); id != NO_NEXT_RELATIONSHIP.intValue(); id = groupRecord.getNext() )
{
if ( cursor.next( id, groupRecord, FORCE ) )
{
set.add( groupRecord.getType() );
}
}
} }
else else
{ {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.storageengine.api.StorageProperty; import org.neo4j.storageengine.api.StorageProperty;
import org.neo4j.storageengine.api.txstate.PropertyContainerState; import org.neo4j.storageengine.api.txstate.PropertyContainerState;


Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.kernel.api.properties.DefinedProperty; import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.kernel.impl.store.PropertyStore; import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.storageengine.api.txstate.PropertyContainerState; import org.neo4j.storageengine.api.txstate.PropertyContainerState;


public class StoreSinglePropertyCursor extends StoreAbstractPropertyCursor public class StoreSinglePropertyCursor extends StoreAbstractPropertyCursor
Expand Down
Expand Up @@ -20,7 +20,9 @@
package org.neo4j.kernel.impl.api.store; package org.neo4j.kernel.impl.api.store;


import org.neo4j.kernel.impl.locking.LockService; import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.kernel.impl.store.RelationshipStore; import org.neo4j.kernel.impl.store.RelationshipStore;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.kernel.impl.util.InstanceCache; import org.neo4j.kernel.impl.util.InstanceCache;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;


Expand Down
Expand Up @@ -32,14 +32,14 @@
import org.neo4j.kernel.impl.locking.LockService; import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.store.CommonAbstractStore; import org.neo4j.kernel.impl.store.CommonAbstractStore;
import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.kernel.impl.store.UnderlyingStorageException; import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.RecordLoad; import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.util.InstanceCache; import org.neo4j.kernel.impl.util.InstanceCache;
import org.neo4j.storageengine.api.Direction; import org.neo4j.storageengine.api.Direction;
import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.PropertyItem;
import org.neo4j.storageengine.api.RelationshipGroupItem;
import org.neo4j.storageengine.api.RelationshipItem; import org.neo4j.storageengine.api.RelationshipItem;
import org.neo4j.storageengine.api.StorageStatement; import org.neo4j.storageengine.api.StorageStatement;
import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexReader;
Expand All @@ -62,11 +62,11 @@ public class StoreStatement implements StorageStatement
private final InstanceCache<StoreNodeRelationshipCursor> nodeRelationshipsCursor; private final InstanceCache<StoreNodeRelationshipCursor> nodeRelationshipsCursor;
private final InstanceCache<StorePropertyCursor> propertyCursorCache; private final InstanceCache<StorePropertyCursor> propertyCursorCache;
private final InstanceCache<StoreSinglePropertyCursor> singlePropertyCursorCache; private final InstanceCache<StoreSinglePropertyCursor> singlePropertyCursorCache;
private final InstanceCache<RelationshipGroupCursor> relationshipGroupCursorCache;
private final InstanceCache<DegreeVisitable> degreeVisitableCache; private final InstanceCache<DegreeVisitable> degreeVisitableCache;
private final NeoStores neoStores; private final NeoStores neoStores;
private final Supplier<IndexReaderFactory> indexReaderFactorySupplier; private final Supplier<IndexReaderFactory> indexReaderFactorySupplier;
private final Supplier<LabelScanReader> labelScanStore; private final Supplier<LabelScanReader> labelScanStore;
private final RecordCursors recordCursors;


private IndexReaderFactory indexReaderFactory; private IndexReaderFactory indexReaderFactory;
private LabelScanReader labelScanReader; private LabelScanReader labelScanReader;
Expand All @@ -80,6 +80,7 @@ public StoreStatement( NeoStores neoStores, Supplier<IndexReaderFactory> indexRe
this.neoStores = neoStores; this.neoStores = neoStores;
this.indexReaderFactorySupplier = indexReaderFactory; this.indexReaderFactorySupplier = indexReaderFactory;
this.labelScanStore = labelScanReaderSupplier; this.labelScanStore = labelScanReaderSupplier;
this.recordCursors = new RecordCursors( neoStores );


nodeCursor = new InstanceCache<NodeCursor>() nodeCursor = new InstanceCache<NodeCursor>()
{ {
Expand Down Expand Up @@ -139,14 +140,6 @@ protected DegreeVisitable create()
this ); this );
} }
}; };
relationshipGroupCursorCache = new InstanceCache<RelationshipGroupCursor>()
{
@Override
protected RelationshipGroupCursor create()
{
return new RelationshipGroupCursor( neoStores.getRelationshipGroupStore(), this );
}
};
} }


@Override @Override
Expand Down Expand Up @@ -209,15 +202,9 @@ public Cursor<PropertyItem> acquireSinglePropertyCursor( long propertyId, int pr
} }


@Override @Override
public Cursor<RelationshipGroupItem> acquireRelationshipGroupCursor( long relationshipGroupId ) public DegreeVisitor.Visitable acquireDenseNodeDegreeCounter( long nodeId, long groupId )
{ {
return relationshipGroupCursorCache.get().init( relationshipGroupId ); return degreeVisitableCache.get().init( nodeId, groupId );
}

@Override
public DegreeVisitor.Visitable acquireDenseNodeDegreeCounter( long nodeId, long relationshipGroupId )
{
return degreeVisitableCache.get().init( nodeId, relationshipGroupId );
} }


@Override @Override
Expand All @@ -240,8 +227,8 @@ public void close()
nodeRelationshipsCursor.close(); nodeRelationshipsCursor.close();
propertyCursorCache.close(); propertyCursorCache.close();
singlePropertyCursorCache.close(); singlePropertyCursorCache.close();
relationshipGroupCursorCache.close();
degreeVisitableCache.close(); degreeVisitableCache.close();
recordCursors.close();
closed = true; closed = true;
} }


Expand Down Expand Up @@ -284,6 +271,12 @@ public IndexReader getFreshIndexReader( IndexDescriptor descriptor ) throws Inde
return indexReaderFactory().newUnCachedReader( descriptor ); return indexReaderFactory().newUnCachedReader( descriptor );
} }


@Override
public RecordCursors recordCursors()
{
return recordCursors;
}

public static <RECORD extends AbstractBaseRecord, STORE extends CommonAbstractStore<RECORD,?>> RECORD read( long id, public static <RECORD extends AbstractBaseRecord, STORE extends CommonAbstractStore<RECORD,?>> RECORD read( long id,
STORE store, RECORD record, RecordLoad mode, PageCursor cursor ) STORE store, RECORD record, RecordLoad mode, PageCursor cursor )
{ {
Expand Down
Expand Up @@ -77,6 +77,20 @@ public interface RecordCursor<R extends AbstractBaseRecord> extends Cursor<R>
*/ */
boolean next( long id ); boolean next( long id );


/**
* An additional way of placing this cursor at an arbitrary record id.
* Calling this method will not advance the "current id" as to change which {@link #next()} will load next.
* This method is useful when there's an opportunity to load a record from an already acquired
* {@link PageCursor} and potentially even an already pinned page.
*
* @param id record id to place cursor at.
* @param record record to load the record data into.
* @param mode {@link RecordLoad} mode temporarily overriding the default provided in
* {@link #acquire(long, RecordLoad)}.
* @return whether or not that record is in use.
*/
boolean next( long id, R record, RecordLoad mode );

/** /**
* Read all records in the chain starting from the id this cursor is positioned at using either * Read all records in the chain starting from the id this cursor is positioned at using either
* {@link #acquire(long, RecordLoad)} or {@link #placeAt(long, RecordLoad)}. Each next record in the chain is * {@link #acquire(long, RecordLoad)} or {@link #placeAt(long, RecordLoad)}. Each next record in the chain is
Expand Down Expand Up @@ -141,5 +155,11 @@ public boolean next( long id )
{ {
return actual.next( id ); return actual.next( id );
} }

@Override
public boolean next( long id, R record, RecordLoad mode )
{
return actual.next( id, record, mode );
}
} }
} }

0 comments on commit 2d1c557

Please sign in to comment.