Skip to content

Commit

Permalink
Revert "Merge pull request #5 from davidegrohmann/3.3-page-cursors-in…
Browse files Browse the repository at this point in the history
…-node-cursors"

This reverts commit 48c374c, reversing
changes made to f9f03c2.
  • Loading branch information
MishaDemianenko committed May 25, 2017
1 parent a4d82d3 commit 9b083dc
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 213 deletions.
30 changes: 0 additions & 30 deletions community/common/src/main/java/org/neo4j/function/Disposable.java

This file was deleted.

Expand Up @@ -21,7 +21,6 @@

import java.util.Optional;

import org.neo4j.function.Disposable;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.api.security.SecurityContext;
Expand Down Expand Up @@ -77,7 +76,7 @@
* }
* </pre>
*/
public interface KernelTransaction extends AutoCloseable, Disposable
public interface KernelTransaction extends AutoCloseable
{
enum Type
{
Expand Down
Expand Up @@ -794,7 +794,6 @@ public String toString()
return "KernelTransaction[" + lockSessionId + "]";
}

@Override
public void dispose()
{
storageStatement.close();
Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.neo4j.kernel.api.StatementConstants;
import org.neo4j.kernel.impl.store.NodeStore;

public class AllNodeProgression implements NodeProgression
public class AllNodeProgression implements Progression
{
private final AllIdIterator allIdIterator;

Expand Down
Expand Up @@ -19,59 +19,54 @@
*/
package org.neo4j.kernel.impl.api.store;

import java.io.IOException;
import java.util.Iterator;
import java.util.function.Consumer;

import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.cursor.Cursor;
import org.neo4j.function.Disposable;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.store.NodeLabelsField;
import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.Record;
import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.util.IoPrimitiveUtils;
import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.txstate.NodeState;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState;

import static org.neo4j.collection.primitive.PrimitiveIntCollections.asSet;
import static org.neo4j.kernel.impl.api.store.NodeProgression.Mode.APPEND;
import static org.neo4j.kernel.impl.api.store.NodeProgression.Mode.FETCH;
import static org.neo4j.kernel.impl.api.store.Progression.Mode.APPEND;
import static org.neo4j.kernel.impl.api.store.Progression.Mode.FETCH;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK_SERVICE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.CHECK;
import static org.neo4j.kernel.impl.util.IoPrimitiveUtils.safeCastLongToInt;

public class NodeCursor implements NodeItem, Cursor<NodeItem>, Disposable
public class NodeCursor implements NodeItem, Cursor<NodeItem>
{
private final NodeRecord nodeRecord;
private final Consumer<NodeCursor> instanceCache;
private final NodeStore nodeStore;
private final RecordCursors recordCursors;
private final LockService lockService;

private NodeProgression progression;
private Progression progression;
private ReadableTransactionState state;
private boolean fetched;
private long[] labels;
private Iterator<Long> added;
private PageCursor pageCursor;

NodeCursor( NodeRecord nodeRecord, Consumer<NodeCursor> instanceCache, NodeStore nodeStore,
NodeCursor( NodeRecord nodeRecord, Consumer<NodeCursor> instanceCache, RecordCursors recordCursors,
LockService lockService )
{
this.pageCursor = nodeStore.newPageCursor();
this.nodeRecord = nodeRecord;
this.instanceCache = instanceCache;
this.nodeStore = nodeStore;
this.recordCursors = recordCursors;
this.lockService = lockService;
}

public Cursor<NodeItem> init( NodeProgression progression, ReadableTransactionState state )
public Cursor<NodeItem> init( Progression progression, ReadableTransactionState state )
{
this.progression = progression;
this.state = state;
Expand All @@ -93,7 +88,8 @@ private boolean fetchNext()
long id;
while ( (id = progression.nextId()) >= 0 )
{
if ( (state == null || !state.nodeIsDeletedInThisTx( id )) && readNodeRecord( id ) )
if ( (state == null || !state.nodeIsDeletedInThisTx( id )) &&
recordCursors.node().next( id, nodeRecord, RecordLoad.CHECK ) )
{
return true;
}
Expand All @@ -114,20 +110,6 @@ private boolean fetchNext()
return false;
}

private boolean readNodeRecord( long id )
{
try
{
nodeRecord.clear();
nodeStore.readIntoRecord( id, nodeRecord, CHECK, pageCursor );
return nodeRecord.inUse();
}
catch ( IOException e )
{
throw new UnderlyingStorageException( e );
}
}

private void recordFromTxState( long id )
{
nodeRecord.clear();
Expand All @@ -143,13 +125,6 @@ public void close()
instanceCache.accept( this );
}

@Override
public void dispose()
{
pageCursor.close();
pageCursor = null;
}

@Override
public NodeItem get()
{
Expand Down Expand Up @@ -196,7 +171,7 @@ private long[] loadedLabels()
{
if ( labels == null )
{
labels = NodeLabelsField.get( nodeRecord, nodeStore );
labels = NodeLabelsField.get( nodeRecord, recordCursors.label() );
}
return labels;
}
Expand Down Expand Up @@ -247,7 +222,7 @@ private Lock acquireLock()
try
{
// It's safer to re-read the node record here, specifically nextProp, after acquiring the lock
if ( !readNodeRecord( nodeRecord.getId() ) )
if ( !recordCursors.node().next( nodeRecord.getId(), nodeRecord, CHECK ) )
{
// So it looks like the node has been deleted. The current behavior of NodeStore#loadRecord
// is to only set the inUse field on loading an unused record. This should (and will)
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.neo4j.kernel.impl.api.store;

public interface NodeProgression
public interface Progression
{
enum Mode
{
Expand Down
Expand Up @@ -21,7 +21,7 @@

import org.neo4j.kernel.api.StatementConstants;

public class SingleNodeProgression implements NodeProgression
public class SingleNodeProgression implements Progression
{
private long nodeId;

Expand Down
Expand Up @@ -22,7 +22,6 @@
import java.util.function.IntPredicate;

import org.neo4j.cursor.Cursor;
import org.neo4j.function.Disposable;
import org.neo4j.kernel.api.properties.DefinedProperty;
import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.kernel.impl.store.RecordCursor;
Expand All @@ -34,7 +33,7 @@

import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;

public abstract class StoreAbstractPropertyCursor implements PropertyItem, Cursor<PropertyItem>, Disposable
public abstract class StoreAbstractPropertyCursor implements Cursor<PropertyItem>, PropertyItem
{
protected final StorePropertyPayloadCursor payload;
private final RecordCursor<PropertyRecord> recordCursor;
Expand Down Expand Up @@ -166,9 +165,4 @@ public final void close()
}

protected abstract void doClose();

@Override
public void dispose()
{
}
}
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.kernel.impl.api.store;

import org.neo4j.cursor.Cursor;
import org.neo4j.function.Disposable;
import org.neo4j.kernel.impl.api.RelationshipVisitor;
import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.kernel.impl.locking.LockService;
Expand All @@ -38,7 +37,7 @@
* Base cursor for relationships.
*/
public abstract class StoreAbstractRelationshipCursor
implements RelationshipVisitor<RuntimeException>, RelationshipItem, Cursor<RelationshipItem>, Disposable
implements RelationshipVisitor<RuntimeException>, Cursor<RelationshipItem>, RelationshipItem
{
protected final RelationshipRecord relationshipRecord;
final RecordCursor<RelationshipRecord> relationshipRecordCursor;
Expand Down Expand Up @@ -99,7 +98,8 @@ public final long endNode()
@Override
public final long otherNode( long nodeId )
{
return relationshipRecord.getFirstNode() == nodeId ? relationshipRecord.getSecondNode() : relationshipRecord.getFirstNode();
return relationshipRecord.getFirstNode() == nodeId ?
relationshipRecord.getSecondNode() : relationshipRecord.getFirstNode();
}

@Override
Expand Down Expand Up @@ -155,9 +155,4 @@ public void close()
{
fetched = false;
}

@Override
public void dispose()
{
}
}
Expand Up @@ -37,6 +37,7 @@ public class StorePropertyCursor extends StoreAbstractPropertyCursor
{
private final Consumer<StorePropertyCursor> instanceCache;

private boolean fromDisk;
private Iterator<StorageProperty> storagePropertyIterator;

public StorePropertyCursor( RecordCursors cursors, Consumer<StorePropertyCursor> instanceCache )
Expand Down Expand Up @@ -75,6 +76,7 @@ protected DefinedProperty nextAdded()
@Override
protected void doClose()
{
fromDisk = false;
instanceCache.accept( this );
}
}
Expand Up @@ -89,7 +89,7 @@ public StoreStatement( NeoStores neoStores, Supplier<IndexReaderFactory> indexRe
@Override
protected NodeCursor create()
{
return new NodeCursor( nodeStore.newRecord(), this, nodeStore, lockService );
return new NodeCursor( nodeStore.newRecord(), this, recordCursors, lockService );
}
};
singleRelationshipCursor = new InstanceCache<StoreSingleRelationshipCursor>()
Expand Down Expand Up @@ -210,12 +210,6 @@ public void close()
{
assert !closed;
closeSchemaResources();
nodeCursor.close();
singleRelationshipCursor.close();
iteratorRelationshipCursor.close();
nodeRelationshipsCursor.close();
propertyCursorCache.close();
singlePropertyCursorCache.close();
recordCursors.close();
closed = true;
}
Expand Down
Expand Up @@ -1037,7 +1037,7 @@ public RECORD getRecord( long id, RECORD record, RecordLoad mode )
}
}

public void readIntoRecord( long id, RECORD record, RecordLoad mode, PageCursor cursor ) throws IOException
void readIntoRecord( long id, RECORD record, RecordLoad mode, PageCursor cursor ) throws IOException
{
// Mark the record with this id regardless of whether or not we load the contents of it.
// This is done in this method since there are multiple call sites and they all want the id
Expand Down Expand Up @@ -1132,18 +1132,6 @@ public Collection<RECORD> getRecords( long firstId, RecordLoad mode )
}
}

public PageCursor newPageCursor()
{
try
{
return storeFile.io( getNumberOfReservedLowIds(), PF_SHARED_READ_LOCK );
}
catch ( IOException e )
{
throw new UnderlyingStorageException( e );
}
}

@Override
public RecordCursor<RECORD> newRecordCursor( final RECORD record )
{
Expand Down
Expand Up @@ -64,6 +64,15 @@ public static long[] get( NodeRecord node, NodeStore nodeStore )
return getDynamicLabelsArray( node.getUsedDynamicLabelRecords(), nodeStore.getDynamicLabelStore() );
}

public static long[] get( NodeRecord node, RecordCursor<DynamicRecord> dynamicLabelCursor )
{
if ( node.isLight() )
{
NodeStore.ensureHeavy( node, dynamicLabelCursor );
}
return getDynamicLabelsArrayFromHeavyRecords( node.getUsedDynamicLabelRecords() );
}

@Override
public long[] getIfLoaded()
{
Expand Down
Expand Up @@ -59,6 +59,13 @@ public static long[] get( NodeRecord node, NodeStore nodeStore )
: InlineNodeLabels.get( node );
}

public static long[] get( NodeRecord node, RecordCursor<DynamicRecord> dynamicLabelCursor )
{
return fieldPointsToDynamicRecordOfLabels( node.getLabelField() )
? DynamicNodeLabels.get( node, dynamicLabelCursor )
: InlineNodeLabels.get( node );
}

public static boolean fieldPointsToDynamicRecordOfLabels( long labelField )
{
return (labelField & 0x8000000000L) != 0;
Expand Down

0 comments on commit 9b083dc

Please sign in to comment.