Skip to content

Commit

Permalink
Fixes from code review
Browse files Browse the repository at this point in the history
- set read to null on close in cursors
- some style
- some documentation
  • Loading branch information
pontusmelke committed Dec 4, 2017
1 parent 7b0ccd5 commit 3d45cc2
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 28 deletions.
Expand Up @@ -62,6 +62,8 @@ enum Type

/**
* @return The Write operations of the graph.
* @throws InvalidTransactionTypeKernelException when transaction cannot be upgraded to a write transaction. This
* can happen when there have been schema modifications.
*/
Write dataWrite() throws InvalidTransactionTypeKernelException;

Expand Down
Expand Up @@ -84,7 +84,7 @@ public Value propertyValue()
@Override
public <E extends Exception> void writeTo( ValueWriter<E> target )
{

throw new UnsupportedOperationException( "not implemented" );
}

@Override
Expand Down
Expand Up @@ -199,7 +199,7 @@ public KernelTransactionImplementation( StatementOperationParts statementOperati
this.userMetaData = new HashMap<>();
AllStoreHolder allStoreHolder =
new AllStoreHolder( storageEngine, storageStatement, this, cursors, explicitIndexStore,
this::assertTransactionOpen );
this::assertOpen );
this.operations =
new Operations(
allStoreHolder,
Expand Down Expand Up @@ -462,6 +462,15 @@ private void assertTransactionOpen()
}
}

private void assertOpen()
{
Optional<Status> terminationReason = getReasonIfTerminated();
if ( terminationReason.isPresent() )
{
throw new TransactionTerminatedException( terminationReason.get() );
}
}

private boolean hasChanges()
{
return hasTxStateWithChanges() || hasExplicitIndexChanges();
Expand Down
Expand Up @@ -449,9 +449,9 @@ public Map<String,Object> getAllProperties()
CursorFactory cursors = transaction.cursors();
Map<String,Object> properties = new HashMap<>();

try ( NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor propertyCursor = cursors.allocatePropertyCursor();
Statement ignore = actions.statement() )
try ( Statement ignore = actions.statement();
NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor propertyCursor = cursors.allocatePropertyCursor() )
{
Token token = transaction.token();
transaction.dataRead().singleNode( nodeId, nodes );
Expand Down
Expand Up @@ -332,8 +332,9 @@ public Node getNodeById( long id )
}

KernelTransaction ktx = spi.currentTransaction();
try ( NodeCursor nodeCursor = ktx.cursors().allocateNodeCursor();
Statement ignore = spi.currentStatement() )
try ( Statement ignore = spi.currentStatement();
NodeCursor nodeCursor = ktx.cursors().allocateNodeCursor()
)
{
ktx.dataRead().singleNode( id, nodeCursor );
if ( !nodeCursor.next() )
Expand Down
Expand Up @@ -302,7 +302,7 @@ ArrayValue array( PropertyCursor cursor, long reference, PageCursor page )
return PropertyUtil.readArrayFromBuffer( buffer );
}

public boolean nodeExists( long id )
public boolean nodeExistsInStore( long id )
{
return storeReadLayer.nodeExists( id );
}
Expand Down
Expand Up @@ -19,13 +19,10 @@
*/
package org.neo4j.kernel.impl.newapi;

import java.util.function.Supplier;

import org.neo4j.internal.kernel.api.CursorFactory;
import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.InwardKernel;
import org.neo4j.kernel.api.txstate.ExplicitIndexTransactionState;
import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.storageengine.api.StorageStatement;

Expand All @@ -48,7 +45,6 @@ public NewKernel( StorageEngine engine, InwardKernel kernel )
this.engine = engine;
this.kernel = kernel;
this.isRunning = false;
this.cursors = new Cursors( );
}

@Override
Expand Down Expand Up @@ -80,5 +76,6 @@ public void stop()
}
statement.close();
isRunning = false;
this.cursors = null;
}
}
Expand Up @@ -271,6 +271,9 @@ public void close()
pageCursor.close();
pageCursor = null;
}
read = null;
labelCursor = null;

reset();
}

Expand Down
Expand Up @@ -89,6 +89,7 @@ public void close()
node = NO_ID;
score = 0;
expectedSize = 0;
read = null;
}

@Override
Expand Down
Expand Up @@ -81,6 +81,7 @@ public void close()
super.close();
node = NO_ID;
labels = null;
read = null;
}

@Override
Expand Down
Expand Up @@ -102,6 +102,7 @@ public void close()
this.node = NO_ID;
this.keys = null;
this.values = null;
this.read = null;
}

@Override
Expand Down
Expand Up @@ -367,7 +367,7 @@ public boolean nodeDelete( long node ) throws AutoIndexingKernelException
}

ktx.locks().optimistic().acquireExclusive( ktx.lockTracer(), ResourceTypes.NODE, node );
if ( allStoreHolder.nodeExists( node ) )
if ( allStoreHolder.nodeExistsInStore( node ) )
{
autoIndexing.nodes().entityRemoved( this, node );
ktx.txState().nodeDoDelete( node );
Expand Down
Expand Up @@ -196,6 +196,7 @@ public void close()
propertiesState = null;
changedProperties = null;
stateValue = null;
read = null;
clear();
}

Expand Down
Expand Up @@ -25,7 +25,6 @@
import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor;
import org.neo4j.internal.kernel.api.Scan;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.io.pagecache.PageCursor;
Expand Down Expand Up @@ -165,7 +164,7 @@ public final Scan<org.neo4j.internal.kernel.api.NodeLabelIndexCursor> nodeLabelS
@Override
public final void allNodesScan( org.neo4j.internal.kernel.api.NodeCursor cursor )
{
((NodeCursor) cursor).scan(this);
((NodeCursor) cursor).scan( this );
}

@Override
Expand Down Expand Up @@ -319,52 +318,52 @@ public final void nodeExplicitIndexQuery(
org.neo4j.internal.kernel.api.NodeExplicitIndexCursor cursor, String index, String key, Object query ) throws KernelException
{
((NodeExplicitIndexCursor) cursor).setRead( this );
explicitIndex( (org.neo4j.kernel.impl.newapi.NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).query(
explicitIndex( (NodeExplicitIndexCursor) cursor, explicitNodeIndex( index ).query(
key, query instanceof Value ? ((Value) query).asObject() : query ) );
}

@Override
public void relationshipExplicitIndexGet(
RelationshipExplicitIndexCursor cursor,
org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor cursor,
String index,
String key,
Value value,
long source,
long target ) throws KernelException
{
((org.neo4j.kernel.impl.newapi.RelationshipExplicitIndexCursor) cursor).setRead( this );
((RelationshipExplicitIndexCursor) cursor).setRead( this );
explicitIndex(
(org.neo4j.kernel.impl.newapi.RelationshipExplicitIndexCursor) cursor,
(RelationshipExplicitIndexCursor) cursor,
explicitRelationshipIndex( index ).get( key, value.asObject(), source, target ) );
}

@Override
public void relationshipExplicitIndexQuery(
RelationshipExplicitIndexCursor cursor,
org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor cursor,
String index,
Object query,
long source,
long target ) throws KernelException
{
((org.neo4j.kernel.impl.newapi.RelationshipExplicitIndexCursor) cursor).setRead( this );
((RelationshipExplicitIndexCursor) cursor).setRead( this );
explicitIndex(
(org.neo4j.kernel.impl.newapi.RelationshipExplicitIndexCursor) cursor,
(RelationshipExplicitIndexCursor) cursor,
explicitRelationshipIndex( index )
.query( query instanceof Value ? ((Value) query).asObject() : query, source, target ) );
}

@Override
public void relationshipExplicitIndexQuery(
RelationshipExplicitIndexCursor cursor,
org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor cursor,
String index,
String key,
Object query,
long source,
long target ) throws KernelException
{
((org.neo4j.kernel.impl.newapi.RelationshipExplicitIndexCursor) cursor).setRead( this );
((RelationshipExplicitIndexCursor) cursor).setRead( this );
explicitIndex(
(org.neo4j.kernel.impl.newapi.RelationshipExplicitIndexCursor) cursor,
(RelationshipExplicitIndexCursor) cursor,
explicitRelationshipIndex( index ).query(
key, query instanceof Value ? ((Value) query).asObject() : query, source, target ) );
}
Expand Down
Expand Up @@ -115,6 +115,7 @@ public void close()
relationship = NO_ID;
score = 0;
expectedSize = 0;
read = null;
}

@Override
Expand Down
Expand Up @@ -159,6 +159,7 @@ public void close()
edgePage = null;
}
current = null;
read = null;
setId( NO_ID );
clear();
}
Expand Down
Expand Up @@ -111,6 +111,7 @@ public void close()
pageCursor.close();
pageCursor = null;
}
read = null;
reset();
}

Expand Down
Expand Up @@ -425,6 +425,7 @@ public void close()
pageCursor.close();
pageCursor = null;
}
read = null;
reset();
}

Expand Down
Expand Up @@ -343,8 +343,9 @@ private static class TestKernelTransaction extends KernelTransactionImplementati
mock( Pool.class ), Clocks.fakeClock(), CpuClock.NOT_AVAILABLE, HeapAllocation.NOT_AVAILABLE,
TransactionTracer.NULL,
LockTracer.NONE, PageCursorTracerSupplier.NULL,
mock( StorageEngine.class, RETURNS_MOCKS ), new CanWrite(), mock(Cursors.class), AutoIndexing.UNSUPPORTED, mock(
ExplicitIndexStore.class) );
mock( StorageEngine.class, RETURNS_MOCKS ), new CanWrite(), mock( Cursors.class ),
AutoIndexing.UNSUPPORTED, mock(
ExplicitIndexStore.class ) );

this.monitor = monitor;
}
Expand Down
Expand Up @@ -190,7 +190,7 @@ public void shouldAcquireEntityWriteLockBeforeDeletingNode()
// GIVEN
when( nodeCursor.next() ).thenReturn( true );
when( nodeCursor.labels() ).thenReturn( LabelSet.NONE );
when( allStoreHolder.nodeExists( 123 ) ).thenReturn( true );
when( allStoreHolder.nodeExistsInStore( 123 ) ).thenReturn( true );

// WHEN
operations.nodeDelete( 123 );
Expand Down

0 comments on commit 3d45cc2

Please sign in to comment.