Skip to content

Commit

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

This reverts commit 4b462d0, reversing
changes made to 48c374c.
  • Loading branch information
MishaDemianenko committed May 25, 2017
1 parent 9b05c60 commit a4d82d3
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 189 deletions.
Expand Up @@ -61,10 +61,11 @@ public class NodeCursor implements NodeItem, Cursor<NodeItem>, Disposable
private Iterator<Long> added; private Iterator<Long> added;
private PageCursor pageCursor; private PageCursor pageCursor;


NodeCursor( NodeStore nodeStore, Consumer<NodeCursor> instanceCache, LockService lockService ) NodeCursor( NodeRecord nodeRecord, Consumer<NodeCursor> instanceCache, NodeStore nodeStore,
LockService lockService )
{ {
this.pageCursor = nodeStore.newPageCursor(); this.pageCursor = nodeStore.newPageCursor();
this.nodeRecord = nodeStore.newRecord(); this.nodeRecord = nodeRecord;
this.instanceCache = instanceCache; this.instanceCache = instanceCache;
this.nodeStore = nodeStore; this.nodeStore = nodeStore;
this.lockService = lockService; this.lockService = lockService;
Expand Down
Expand Up @@ -19,54 +19,46 @@
*/ */
package org.neo4j.kernel.impl.api.store; package org.neo4j.kernel.impl.api.store;


import java.io.IOException;
import java.util.function.IntPredicate; import java.util.function.IntPredicate;


import org.neo4j.cursor.Cursor; import org.neo4j.cursor.Cursor;
import org.neo4j.function.Disposable; import org.neo4j.function.Disposable;
import org.neo4j.io.pagecache.PageCursor;
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.RecordCursor;
import org.neo4j.kernel.impl.store.UnderlyingStorageException; import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.store.record.Record;
import org.neo4j.storageengine.api.PropertyItem; import org.neo4j.storageengine.api.PropertyItem;
import org.neo4j.storageengine.api.txstate.PropertyContainerState; import org.neo4j.storageengine.api.txstate.PropertyContainerState;


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


public abstract class StoreAbstractPropertyCursor implements PropertyItem, Cursor<PropertyItem>, Disposable public abstract class StoreAbstractPropertyCursor implements PropertyItem, Cursor<PropertyItem>, Disposable
{ {
protected final StorePropertyPayloadCursor payload; protected final StorePropertyPayloadCursor payload;
private final PageCursor cursor; private final RecordCursor<PropertyRecord> recordCursor;
private final PropertyRecord record;
private final PropertyStore propertyStore;


protected boolean fetched; protected boolean fetched;
private boolean doneTraversingTheChain; private boolean doneTraversingTheChain;
private DefinedProperty property; private DefinedProperty property;
private IntPredicate propertyKeyIds; private IntPredicate propertyKeyIds;
private long nextPropertyId;
private Lock lock; private Lock lock;
protected PropertyContainerState state; protected PropertyContainerState state;


StoreAbstractPropertyCursor( PropertyStore propertyStore ) StoreAbstractPropertyCursor( RecordCursors cursors )
{ {
this.cursor = propertyStore.newPageCursor(); this.payload = new StorePropertyPayloadCursor( cursors.propertyString(), cursors.propertyArray() );
this.propertyStore = propertyStore; this.recordCursor = cursors.property();
this.record = propertyStore.newRecord();
this.payload = new StorePropertyPayloadCursor( propertyStore.getStringStore(), propertyStore.getArrayStore() );
} }


protected final void initialize( IntPredicate propertyKeyIds, long firstPropertyId, Lock lock, protected final void initialize( IntPredicate propertyKeyIds, long firstPropertyId, Lock lock,
PropertyContainerState state ) PropertyContainerState state )
{ {
this.propertyKeyIds = propertyKeyIds; this.propertyKeyIds = propertyKeyIds;
this.nextPropertyId = firstPropertyId;
this.lock = lock; this.lock = lock;
this.state = state; this.state = state;
recordCursor.placeAt( firstPropertyId, FORCE );
} }


@Override @Override
Expand All @@ -87,17 +79,16 @@ private boolean fetchNext()
} }


// No, OK continue down the chain and hunt for more... // No, OK continue down the chain and hunt for more...
PropertyRecord propertyRecord = readRecord(); if ( recordCursor.next() )
nextPropertyId = propertyRecord.getNextProp();
if ( propertyRecord.inUse() )
{ {
PropertyRecord propertyRecord = recordCursor.get();
payload.init( propertyKeyIds, propertyRecord.getBlocks(), propertyRecord.getNumberOfBlocks() ); payload.init( propertyKeyIds, propertyRecord.getBlocks(), propertyRecord.getNumberOfBlocks() );
if ( payloadHasNext() ) if ( payloadHasNext() )
{ {
return true; return true;
} }
} }
else if ( Record.NO_NEXT_PROPERTY.is( nextPropertyId ) ) else if ( Record.NO_NEXT_PROPERTY.is( recordCursor.get().getNextProp() ) )
{ {
// No more records in this chain, i.e. no more properties. // No more records in this chain, i.e. no more properties.
doneTraversingTheChain = true; doneTraversingTheChain = true;
Expand All @@ -111,23 +102,6 @@ else if ( Record.NO_NEXT_PROPERTY.is( nextPropertyId ) )
return (property = nextAdded()) != null; return (property = nextAdded()) != null;
} }


private PropertyRecord readRecord()
{
try
{
record.clear();
if ( !Record.NO_NEXT_PROPERTY.is( nextPropertyId ) )
{
propertyStore.readIntoRecord( nextPropertyId, record, FORCE, cursor );
}
return record;
}
catch ( IOException e )
{
throw new UnderlyingStorageException( e );
}
}

private boolean payloadHasNext() private boolean payloadHasNext()
{ {
boolean next = payload.next(); boolean next = payload.next();
Expand Down Expand Up @@ -182,7 +156,6 @@ public final void close()
payload.close(); payload.close();
propertyKeyIds = null; propertyKeyIds = null;
property = null; property = null;
nextPropertyId = NO_SUCH_PROPERTY;
doClose(); doClose();
} }
finally finally
Expand All @@ -197,7 +170,5 @@ public final void close()
@Override @Override
public void dispose() public void dispose()
{ {
cursor.close();
payload.dispose();
} }
} }
Expand Up @@ -24,7 +24,6 @@


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.RecordCursors; 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 All @@ -40,9 +39,9 @@ public class StorePropertyCursor extends StoreAbstractPropertyCursor


private Iterator<StorageProperty> storagePropertyIterator; private Iterator<StorageProperty> storagePropertyIterator;


public StorePropertyCursor( PropertyStore propertyStore, Consumer<StorePropertyCursor> instanceCache ) public StorePropertyCursor( RecordCursors cursors, Consumer<StorePropertyCursor> instanceCache )
{ {
super( propertyStore ); super( cursors );
this.instanceCache = instanceCache; this.instanceCache = instanceCache;
} }


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


import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.function.IntPredicate; import java.util.function.IntPredicate;


import org.neo4j.function.Disposable;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.impl.store.CommonAbstractStore;
import org.neo4j.kernel.impl.store.DynamicArrayStore;
import org.neo4j.kernel.impl.store.DynamicStringStore;
import org.neo4j.kernel.impl.store.LongerShortString; import org.neo4j.kernel.impl.store.LongerShortString;
import org.neo4j.kernel.impl.store.PropertyType; import org.neo4j.kernel.impl.store.PropertyType;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.ShortArray; import org.neo4j.kernel.impl.store.ShortArray;
import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.impl.store.record.DynamicRecord; import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.PropertyBlock; import org.neo4j.kernel.impl.store.record.PropertyBlock;
import org.neo4j.kernel.impl.store.record.Record; import org.neo4j.kernel.impl.store.record.Record;
Expand All @@ -50,7 +44,7 @@
* During initialization the raw property block {@code long}s are read from * During initialization the raw property block {@code long}s are read from
* the given property record. * the given property record.
*/ */
class StorePropertyPayloadCursor implements Disposable class StorePropertyPayloadCursor
{ {
private static final int MAX_BYTES_IN_SHORT_STRING_OR_SHORT_ARRAY = 32; private static final int MAX_BYTES_IN_SHORT_STRING_OR_SHORT_ARRAY = 32;
private static final int INTERNAL_BYTE_ARRAY_SIZE = 4096; private static final int INTERNAL_BYTE_ARRAY_SIZE = 4096;
Expand All @@ -61,11 +55,8 @@ class StorePropertyPayloadCursor implements Disposable
*/ */
private final ByteBuffer cachedBuffer = ByteBuffer.allocate( INTERNAL_BYTE_ARRAY_SIZE ); private final ByteBuffer cachedBuffer = ByteBuffer.allocate( INTERNAL_BYTE_ARRAY_SIZE );


private final DynamicRecord record; private final RecordCursor<DynamicRecord> stringRecordCursor;
private final PageCursor stringCursor; private final RecordCursor<DynamicRecord> arrayRecordCursor;
private final DynamicStringStore stringStore;
private final PageCursor arrayCursor;
private final DynamicArrayStore arrayStore;
private ByteBuffer buffer = cachedBuffer; private ByteBuffer buffer = cachedBuffer;


private long[] blocks; private long[] blocks;
Expand All @@ -74,13 +65,11 @@ class StorePropertyPayloadCursor implements Disposable
private IntPredicate propertyKeyIds; private IntPredicate propertyKeyIds;
private boolean exhausted; private boolean exhausted;


StorePropertyPayloadCursor( DynamicStringStore stringStore, DynamicArrayStore arrayStore ) StorePropertyPayloadCursor( RecordCursor<DynamicRecord> stringRecordCursor,
RecordCursor<DynamicRecord> arrayRecordCursor )
{ {
this.record = stringStore.newRecord(); this.stringRecordCursor = stringRecordCursor;
this.stringStore = stringStore; this.arrayRecordCursor = arrayRecordCursor;
this.stringCursor = stringStore.newPageCursor();
this.arrayStore = arrayStore;
this.arrayCursor = arrayStore.newPageCursor();
} }


void init( IntPredicate propertyKeyIds, long[] blocks, int numberOfBlocks ) void init( IntPredicate propertyKeyIds, long[] blocks, int numberOfBlocks )
Expand Down Expand Up @@ -174,15 +163,15 @@ Object value()
return LongerShortString.decode( blocks, position, currentBlocksUsed() ); return LongerShortString.decode( blocks, position, currentBlocksUsed() );
case STRING: case STRING:
{ {
readFromStore( stringStore, stringCursor ); readFromStore( stringRecordCursor );
buffer.flip(); buffer.flip();
return UTF8.decode( buffer.array(), 0, buffer.limit() ); return UTF8.decode( buffer.array(), 0, buffer.limit() );
} }
case SHORT_ARRAY: case SHORT_ARRAY:
return ShortArray.decode( valueAsBits() ); return ShortArray.decode( valueAsBits() );
case ARRAY: case ARRAY:
{ {
readFromStore( arrayStore, arrayCursor ); readFromStore( arrayRecordCursor );
buffer.flip(); buffer.flip();
return readArrayFromBuffer( buffer ); return readArrayFromBuffer( buffer );
} }
Expand Down Expand Up @@ -212,14 +201,16 @@ private Bits valueAsBits()
return bits; return bits;
} }


private void readFromStore( CommonAbstractStore<DynamicRecord,?> store, PageCursor cursor ) private void readFromStore( RecordCursor<DynamicRecord> cursor )
{ {
buffer.clear(); buffer.clear();
long blockId = PropertyBlock.fetchLong( currentHeader() ); long startBlockId = PropertyBlock.fetchLong( currentHeader() );
do cursor.placeAt( startBlockId, FORCE );
while ( true )
{ {
readRecord( store, cursor, blockId ); cursor.next();
byte[] data = record.getData(); DynamicRecord dynamicRecord = cursor.get();
byte[] data = dynamicRecord.getData();
if ( buffer.remaining() < data.length ) if ( buffer.remaining() < data.length )
{ {
buffer.flip(); buffer.flip();
Expand All @@ -228,21 +219,10 @@ private void readFromStore( CommonAbstractStore<DynamicRecord,?> store, PageCurs
buffer = newBuffer; buffer = newBuffer;
} }
buffer.put( data, 0, data.length ); buffer.put( data, 0, data.length );
blockId = record.getNextBlock(); if ( Record.NULL_REFERENCE.is( dynamicRecord.getNextBlock() ) )
} {
while ( !Record.NULL_REFERENCE.is( blockId ) ); break;
} }

private void readRecord( CommonAbstractStore<DynamicRecord,?> store, PageCursor cursor, long blockId )
{
try
{
record.clear();
store.readIntoRecord( blockId, record, FORCE, cursor );
}
catch ( IOException e )
{
throw new UnderlyingStorageException( e );
} }
} }


Expand Down Expand Up @@ -312,11 +292,4 @@ private static Object readArrayFromBuffer( ByteBuffer buffer )
buffer.order( ByteOrder.LITTLE_ENDIAN ); buffer.order( ByteOrder.LITTLE_ENDIAN );
} }
} }

@Override
public void dispose()
{
stringCursor.close();
arrayCursor.close();
}
} }
Expand Up @@ -23,7 +23,6 @@


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.RecordCursors; import org.neo4j.kernel.impl.store.RecordCursors;
import org.neo4j.storageengine.api.txstate.PropertyContainerState; import org.neo4j.storageengine.api.txstate.PropertyContainerState;


Expand All @@ -32,9 +31,9 @@ public class StoreSinglePropertyCursor extends StoreAbstractPropertyCursor
private final Consumer<StoreSinglePropertyCursor> instanceCache; private final Consumer<StoreSinglePropertyCursor> instanceCache;
private int propertyKeyId; private int propertyKeyId;


StoreSinglePropertyCursor( PropertyStore propertyStore, Consumer<StoreSinglePropertyCursor> instanceCache ) StoreSinglePropertyCursor( RecordCursors cursors, Consumer<StoreSinglePropertyCursor> instanceCache )
{ {
super( propertyStore ); super( cursors );
this.instanceCache = instanceCache; this.instanceCache = instanceCache;
} }


Expand Down
Expand Up @@ -89,7 +89,7 @@ public StoreStatement( NeoStores neoStores, Supplier<IndexReaderFactory> indexRe
@Override @Override
protected NodeCursor create() protected NodeCursor create()
{ {
return new NodeCursor( nodeStore, this, lockService ); return new NodeCursor( nodeStore.newRecord(), this, nodeStore, lockService );
} }
}; };
singleRelationshipCursor = new InstanceCache<StoreSingleRelationshipCursor>() singleRelationshipCursor = new InstanceCache<StoreSingleRelationshipCursor>()
Expand Down Expand Up @@ -124,15 +124,15 @@ protected StoreNodeRelationshipCursor create()
@Override @Override
protected StorePropertyCursor create() protected StorePropertyCursor create()
{ {
return new StorePropertyCursor( neoStores.getPropertyStore(), this ); return new StorePropertyCursor( recordCursors, this );
} }
}; };
singlePropertyCursorCache = new InstanceCache<StoreSinglePropertyCursor>() singlePropertyCursorCache = new InstanceCache<StoreSinglePropertyCursor>()
{ {
@Override @Override
protected StoreSinglePropertyCursor create() protected StoreSinglePropertyCursor create()
{ {
return new StoreSinglePropertyCursor( neoStores.getPropertyStore(), this ); return new StoreSinglePropertyCursor( recordCursors, this );
} }
}; };
} }
Expand Down
Expand Up @@ -21,6 +21,7 @@


import org.neo4j.io.IOUtils; import org.neo4j.io.IOUtils;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord; import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.PropertyRecord; import org.neo4j.kernel.impl.store.record.PropertyRecord;
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;
Expand All @@ -35,12 +36,16 @@ public class RecordCursors implements AutoCloseable
private final RecordCursor<RelationshipRecord> relationship; private final RecordCursor<RelationshipRecord> relationship;
private final RecordCursor<RelationshipGroupRecord> relationshipGroup; private final RecordCursor<RelationshipGroupRecord> relationshipGroup;
private final RecordCursor<PropertyRecord> property; private final RecordCursor<PropertyRecord> property;
private final RecordCursor<DynamicRecord> propertyString;
private final RecordCursor<DynamicRecord> propertyArray;


public RecordCursors( NeoStores neoStores ) public RecordCursors( NeoStores neoStores )
{ {
relationship = newCursor( neoStores.getRelationshipStore() ); relationship = newCursor( neoStores.getRelationshipStore() );
relationshipGroup = newCursor( neoStores.getRelationshipGroupStore() ); relationshipGroup = newCursor( neoStores.getRelationshipGroupStore() );
property = newCursor( neoStores.getPropertyStore() ); property = newCursor( neoStores.getPropertyStore() );
propertyString = newCursor( neoStores.getPropertyStore().getStringStore() );
propertyArray = newCursor( neoStores.getPropertyStore().getArrayStore() );
} }


private static <R extends AbstractBaseRecord> RecordCursor<R> newCursor( RecordStore<R> store ) private static <R extends AbstractBaseRecord> RecordCursor<R> newCursor( RecordStore<R> store )
Expand All @@ -51,7 +56,8 @@ private static <R extends AbstractBaseRecord> RecordCursor<R> newCursor( RecordS
@Override @Override
public void close() public void close()
{ {
IOUtils.closeAll( RuntimeException.class, relationship, relationshipGroup, property ); IOUtils.closeAll( RuntimeException.class, relationship, relationshipGroup, property, propertyArray,
propertyString );
} }


public RecordCursor<RelationshipRecord> relationship() public RecordCursor<RelationshipRecord> relationship()
Expand All @@ -68,4 +74,14 @@ public RecordCursor<PropertyRecord> property()
{ {
return property; return property;
} }

public RecordCursor<DynamicRecord> propertyArray()
{
return propertyArray;
}

public RecordCursor<DynamicRecord> propertyString()
{
return propertyString;
}
} }

0 comments on commit a4d82d3

Please sign in to comment.