Skip to content

Commit

Permalink
Check that transaction is open before returning property value
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Dec 4, 2017
1 parent 26cbd27 commit 7b0ccd5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Expand Up @@ -198,7 +198,8 @@ public KernelTransactionImplementation( StatementOperationParts statementOperati
this.statistics = new Statistics( this, cpuClock, heapAllocation );
this.userMetaData = new HashMap<>();
AllStoreHolder allStoreHolder =
new AllStoreHolder( storageEngine, storageStatement, this, cursors, explicitIndexStore );
new AllStoreHolder( storageEngine, storageStatement, this, cursors, explicitIndexStore,
this::assertTransactionOpen );
this.operations =
new Operations(
allStoreHolder,
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException;
import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.AssertOpen;
import org.neo4j.kernel.api.ExplicitIndex;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
Expand Down Expand Up @@ -71,9 +72,11 @@ public class AllStoreHolder extends Read implements Token
public AllStoreHolder( StorageEngine engine,
StorageStatement statement,
TxStateHolder txStateHolder,
Cursors cursors, ExplicitIndexStore explicitIndexStore )
Cursors cursors,
ExplicitIndexStore explicitIndexStore,
AssertOpen assertOpen )
{
super( cursors, txStateHolder );
super( cursors, txStateHolder, assertOpen );
this.storeReadLayer = engine.storeReadLayer();
this.statement = statement; // use provided statement, to assert no leakage
this.explicitIndexes = Suppliers.lazySingleton( txStateHolder::explicitIndexTxState );
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.regex.Pattern;

import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.AssertOpen;
import org.neo4j.kernel.impl.store.LongerShortString;
import org.neo4j.kernel.impl.store.PropertyType;
import org.neo4j.kernel.impl.store.ShortArray;
Expand Down Expand Up @@ -59,19 +60,21 @@ public class PropertyCursor extends PropertyRecord implements org.neo4j.internal
private PropertyContainerState propertiesState;
private Iterator<StorageProperty> changedProperties;
private StorageProperty stateValue;
private AssertOpen assertOpen;

public PropertyCursor()
{
super( NO_ID );
}

void init( long reference, Read read )
void init( long reference, Read read, AssertOpen assertOpen )
{
if ( getId() != NO_ID )
{
clear();
}

this.assertOpen = assertOpen;
this.block = Integer.MAX_VALUE;
this.read = read;
if ( reference == NO_ID )
Expand Down Expand Up @@ -249,6 +252,14 @@ public Value propertyValue()
return stateValue.value();
}

Value value = readValue();

assertOpen.assertOpen();
return value;
}

private Value readValue()
{
PropertyType type = type();
if ( type == null )
{
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.neo4j.internal.kernel.api.Scan;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.AssertOpen;
import org.neo4j.kernel.api.ExplicitIndex;
import org.neo4j.kernel.api.ExplicitIndexHits;
import org.neo4j.kernel.api.txstate.ExplicitIndexTransactionState;
Expand Down Expand Up @@ -61,11 +62,13 @@ abstract class Read implements TxStateHolder,
{
private final Cursors cursors;
private final TxStateHolder txStateHolder;
private final AssertOpen assertOpen;

Read( Cursors cursors, TxStateHolder txStateHolder )
Read( Cursors cursors, TxStateHolder txStateHolder, AssertOpen assertOpen )
{
this.cursors = cursors;
this.txStateHolder = txStateHolder;
this.assertOpen = assertOpen;
}

@Override
Expand Down Expand Up @@ -277,19 +280,19 @@ else if ( hasFilterFlag( reference ) ) // this relationship chain need to be fil
@Override
public final void nodeProperties( long reference, org.neo4j.internal.kernel.api.PropertyCursor cursor )
{
((PropertyCursor) cursor).init( reference, this );
((PropertyCursor) cursor).init( reference, this, assertOpen );
}

@Override
public final void relationshipProperties( long reference, org.neo4j.internal.kernel.api.PropertyCursor cursor )
{
((PropertyCursor) cursor).init( reference, this );
((PropertyCursor) cursor).init( reference, this, assertOpen );
}

@Override
public final void graphProperties( org.neo4j.internal.kernel.api.PropertyCursor cursor )
{
((PropertyCursor) cursor).init( graphPropertiesReference(), this );
((PropertyCursor) cursor).init( graphPropertiesReference(), this, assertOpen );
}

abstract long graphPropertiesReference();
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.neo4j.collection.primitive.PrimitiveLongObjectMap;
import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.AssertOpen;
import org.neo4j.kernel.api.ExplicitIndex;
import org.neo4j.kernel.api.txstate.TxStateHolder;
import org.neo4j.kernel.impl.store.DynamicRecordAllocator;
Expand Down Expand Up @@ -67,7 +68,7 @@ public DynamicRecord nextRecord()

MockStore( Cursors cursors )
{
super( cursors, mock( TxStateHolder.class ) );
super( cursors, mock( TxStateHolder.class ), AssertOpen.ALWAYS_OPEN );
}

@Override
Expand Down

0 comments on commit 7b0ccd5

Please sign in to comment.