Skip to content

Commit

Permalink
Extract interface to StorePropertyCursor
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 66237dc commit d938e2b
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 193 deletions.
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.kernel.impl.newapi;

import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -72,8 +71,6 @@
import org.neo4j.kernel.impl.index.IndexEntityType;
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.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
Expand All @@ -84,13 +81,9 @@
import org.neo4j.storageengine.api.schema.PopulationProgress;
import org.neo4j.storageengine.api.schema.SchemaRule;
import org.neo4j.storageengine.api.txstate.ReadableDiffSets;
import org.neo4j.string.UTF8;
import org.neo4j.values.AnyValue;
import org.neo4j.values.ValueMapper;
import org.neo4j.values.storable.ArrayValue;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.Values;

import static java.lang.String.format;
import static org.neo4j.helpers.collection.Iterators.filter;
Expand All @@ -102,7 +95,6 @@
public class AllStoreHolder extends Read
{
private final StorageReader.Groups groups;
private final StorageReader.Properties properties;
private final StorageReader.Relationships relationships;
private final StorageReader storageReader;
private final ExplicitIndexStore explicitIndexStore;
Expand All @@ -121,7 +113,6 @@ public AllStoreHolder(
this.storageReader = storageReader;
this.relationships = storageReader.relationships();
this.groups = storageReader.groups();
this.properties = storageReader.properties();
this.explicitIndexStore = explicitIndexStore;
this.procedures = procedures;
this.schemaState = schemaState;
Expand Down Expand Up @@ -679,24 +670,6 @@ PageCursor groupPage( long reference )
return groups.openPageCursorForReading( reference );
}

@Override
PageCursor propertyPage( long reference )
{
return properties.openPageCursorForReading( reference );
}

@Override
PageCursor stringPage( long reference )
{
return properties.openStringPageCursor( reference );
}

@Override
PageCursor arrayPage( long reference )
{
return properties.openArrayPageCursor( reference );
}

@Override
void relationship( RelationshipRecord record, long reference, PageCursor pageCursor )
{
Expand All @@ -723,14 +696,6 @@ void relationshipFull( RelationshipRecord record, long reference, PageCursor pag
relationships.getRecordByCursor( reference, record, RecordLoad.FORCE, pageCursor );
}

@Override
void property( PropertyRecord record, long reference, PageCursor pageCursor )
{
// We need to load forcefully here since otherwise we can have inconsistent reads
// for properties across blocks, see org.neo4j.graphdb.ConsistentPropertyReadsIT
properties.getRecordByCursor( reference, record, RecordLoad.FORCE, pageCursor );
}

@Override
void group( RelationshipGroupRecord record, long reference, PageCursor page )
{
Expand All @@ -746,22 +711,6 @@ long relationshipHighMark()
return relationships.getHighestPossibleIdInUse();
}

@Override
TextValue string( StorePropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = properties.loadString( reference, cursor.buffer, page );
buffer.flip();
return Values.stringValue( UTF8.decode( buffer.array(), 0, buffer.limit() ) );
}

@Override
ArrayValue array( StorePropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = properties.loadArray( reference, cursor.buffer, page );
buffer.flip();
return PropertyStore.readArrayFromBuffer( buffer );
}

boolean nodeExistsInStore( long id )
{
return storageReader.nodeExists( id );
Expand Down
Expand Up @@ -146,7 +146,7 @@ public DefaultPropertyCursor allocatePropertyCursor()
{
if ( propertyCursor == null )
{
return trace( new DefaultPropertyCursor( this ) );
return trace( new DefaultPropertyCursor( this, storageReader.allocatePropertyCursor() ) );
}

try
Expand Down
Expand Up @@ -43,10 +43,10 @@ public class DefaultPropertyCursor implements PropertyCursor
private AssertOpen assertOpen;
private final DefaultCursors pool;

DefaultPropertyCursor( DefaultCursors pool )
DefaultPropertyCursor( DefaultCursors pool, StorePropertyCursor storeCursor )
{
this.pool = pool;
this.storeCursor = new StorePropertyCursor();
this.storeCursor = storeCursor;
}

void initNode( long nodeReference, long reference, Read read, AssertOpen assertOpen )
Expand Down Expand Up @@ -96,7 +96,7 @@ private void init( long reference, Read read, AssertOpen assertOpen )
{
this.assertOpen = assertOpen;
this.read = read;
this.storeCursor.init( reference, read );
this.storeCursor.init( reference );
}

@Override
Expand Down
Expand Up @@ -50,15 +50,12 @@
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.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RelationshipGroupRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord;
import org.neo4j.storageengine.api.lock.ResourceType;
import org.neo4j.storageengine.api.schema.IndexProgressor;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.LabelScanReader;
import org.neo4j.values.storable.ArrayValue;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values;
Expand Down Expand Up @@ -572,28 +569,16 @@ public final void futureRelationshipPropertyReferenceRead( long reference )

abstract PageCursor groupPage( long reference );

abstract PageCursor propertyPage( long reference );

abstract PageCursor stringPage( long reference );

abstract PageCursor arrayPage( long reference );

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

abstract void relationshipAdvance( RelationshipRecord record, PageCursor pageCursor );

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

abstract void property( PropertyRecord record, long reference, PageCursor pageCursor );

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

abstract long relationshipHighMark();

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

abstract ArrayValue array( StorePropertyCursor cursor, long reference, PageCursor page );

@Override
public TransactionState txState()
{
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
Expand Down
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
Expand All @@ -25,12 +25,16 @@
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.impl.store.GeometryType;
import org.neo4j.kernel.impl.store.LongerShortString;
import org.neo4j.kernel.impl.store.PropertyStore;
import org.neo4j.kernel.impl.store.PropertyType;
import org.neo4j.kernel.impl.store.ShortArray;
import org.neo4j.kernel.impl.store.TemporalType;
import org.neo4j.kernel.impl.store.record.PropertyBlock;
import org.neo4j.kernel.impl.store.record.PropertyRecord;
import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.kernel.impl.util.Bits;
import org.neo4j.storageengine.api.StoragePropertyCursor;
import org.neo4j.string.UTF8;
import org.neo4j.values.storable.ArrayValue;
import org.neo4j.values.storable.BooleanValue;
import org.neo4j.values.storable.ByteValue;
Expand All @@ -44,24 +48,27 @@
import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values;

public class StorePropertyCursor extends PropertyRecord
public class StorePropertyCursor extends PropertyRecord implements StoragePropertyCursor
{
private static final int MAX_BYTES_IN_SHORT_STRING_OR_SHORT_ARRAY = 32;
private static final int INITIAL_POSITION = -1;
private Read read;

private PropertyStore read;
private long next;
private int block;
ByteBuffer buffer;
public ByteBuffer buffer;
private PageCursor page;
private PageCursor stringPage;
private PageCursor arrayPage;

public StorePropertyCursor()
public StorePropertyCursor( PropertyStore read )
{
super( NO_ID );
this.read = read;
}

void init( long reference, Read read )
@Override
public void init( long reference )
{
if ( getId() != NO_ID )
{
Expand All @@ -70,12 +77,11 @@ void init( long reference, Read read )

//Set to high value to force a read
this.block = Integer.MAX_VALUE;
this.read = read;
if ( reference != NO_ID )
{
if ( page == null )
{
page = read.propertyPage( reference );
page = propertyPage( reference );
}
}

Expand Down Expand Up @@ -124,7 +130,7 @@ boolean next( IntPredicate filter )
return false;
}

read.property( this, next, page );
property( this, next, page );
next = getNextProp();
block = INITIAL_POSITION;
}
Expand All @@ -135,6 +141,7 @@ private long currentBlock()
return getBlocks()[block];
}

@Override
public void close()
{
if ( !isClosed() )
Expand All @@ -144,11 +151,13 @@ public void close()
}
}

@Override
public int propertyKey()
{
return PropertyBlock.keyIndexId( currentBlock() );
}

@Override
public ValueGroup propertyType()
{
PropertyType type = type();
Expand Down Expand Up @@ -183,6 +192,7 @@ private PropertyType type()
return PropertyType.getPropertyTypeOrNull( currentBlock() );
}

@Override
public Value propertyValue()
{
return readValue();
Expand Down Expand Up @@ -245,19 +255,19 @@ private ArrayValue readLongArray()
long reference = PropertyBlock.fetchLong( currentBlock() );
if ( arrayPage == null )
{
arrayPage = read.arrayPage( reference );
arrayPage = arrayPage( reference );
}
return read.array( this, reference, arrayPage );
return array( this, reference, arrayPage );
}

private TextValue readLongString()
{
long reference = PropertyBlock.fetchLong( currentBlock() );
if ( stringPage == null )
{
stringPage = read.stringPage( reference );
stringPage = stringPage( reference );
}
return read.string( this, reference, stringPage );
return string( this, reference, stringPage );
}

private Value readShortArray()
Expand Down Expand Up @@ -324,6 +334,7 @@ private BooleanValue readBoolean()
return Values.booleanValue( PropertyBlock.fetchByte( currentBlock() ) == 1 );
}

@Override
public boolean isClosed()
{
return read == null;
Expand All @@ -342,6 +353,7 @@ public String toString()
}
}

@Override
public void release()
{
if ( stringPage != null )
Expand All @@ -360,4 +372,40 @@ public void release()
page = null;
}
}

private PageCursor propertyPage( long reference )
{
return read.openPageCursorForReading( reference );
}

private PageCursor stringPage( long reference )
{
return read.openStringPageCursor( reference );
}

private PageCursor arrayPage( long reference )
{
return read.openArrayPageCursor( reference );
}

private void property( PropertyRecord record, long reference, PageCursor pageCursor )
{
// We need to load forcefully here since otherwise we can have inconsistent reads
// for properties across blocks, see org.neo4j.graphdb.ConsistentPropertyReadsIT
read.getRecordByCursor( reference, record, RecordLoad.FORCE, pageCursor );
}

private TextValue string( org.neo4j.kernel.impl.newapi.StorePropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = read.loadString( reference, cursor.buffer, page );
buffer.flip();
return Values.stringValue( UTF8.decode( buffer.array(), 0, buffer.limit() ) );
}

private ArrayValue array( org.neo4j.kernel.impl.newapi.StorePropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = read.loadArray( reference, cursor.buffer, page );
buffer.flip();
return PropertyStore.readArrayFromBuffer( buffer );
}
}
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
Expand Down

0 comments on commit d938e2b

Please sign in to comment.