Skip to content

Commit

Permalink
One node and property cursor per allocation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Dec 7, 2017
1 parent c7a4583 commit f2c3efe
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.util.Optional;

import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.exceptions.TransactionFailureException;
Expand Down Expand Up @@ -96,6 +98,10 @@ interface CloseListener
*/
Statement acquireStatement();

NodeCursor nodeCursor();

PropertyCursor propertyCursor();

/**
* Closes this transaction, committing its changes if {@link #success()} has been called and neither
* {@link #failure()} nor {@link #markForTermination(Status)} has been called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.neo4j.internal.kernel.api.CursorFactory;
import org.neo4j.internal.kernel.api.ExplicitIndexRead;
import org.neo4j.internal.kernel.api.ExplicitIndexWrite;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.SchemaWrite;
Expand Down Expand Up @@ -367,6 +369,18 @@ public KernelStatement acquireStatement()
return currentStatement;
}

@Override
public NodeCursor nodeCursor()
{
return operations.nodeCursor();
}

@Override
public PropertyCursor propertyCursor()
{
return operations.propertyCursor();
}

ExecutingQueryList executingQueries()
{
return currentStatement.executingQueryList();
Expand Down
158 changes: 55 additions & 103 deletions community/kernel/src/main/java/org/neo4j/kernel/impl/core/NodeProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Objects;

import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.cursor.Cursor;
import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
Expand All @@ -39,7 +38,6 @@
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.internal.kernel.api.CursorFactory;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Token;
Expand Down Expand Up @@ -355,42 +353,35 @@ public Object getProperty( String key, Object defaultValue )
{
return defaultValue;
}
CursorFactory cursors = transaction.cursors();
try ( NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor properties = cursors.allocatePropertyCursor()
)
NodeCursor nodes = transaction.nodeCursor();
PropertyCursor properties = transaction.propertyCursor();
transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{

transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{
throw new NotFoundException( new EntityNotFoundException( EntityType.NODE, nodeId ) );
}
nodes.properties( properties );
while ( properties.next() )
throw new NotFoundException( new EntityNotFoundException( EntityType.NODE, nodeId ) );
}
nodes.properties( properties );
while ( properties.next() )
{
if ( propertyKey == properties.propertyKey() )
{
if ( propertyKey == properties.propertyKey() )
{
Value value = properties.propertyValue();
return value == Values.NO_VALUE ? defaultValue : value.asObjectCopy();
}
Value value = properties.propertyValue();
return value == Values.NO_VALUE ? defaultValue : value.asObjectCopy();
}
return defaultValue;
}
return defaultValue;
}
}

@Override
public Iterable<String> getPropertyKeys()
{
KernelTransaction transaction = actions.kernelTransaction();
CursorFactory cursors = transaction.cursors();
List<String> keys = new ArrayList<>();
try ( NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor properties = cursors.allocatePropertyCursor();
Statement ignore = actions.statement()
)
try ( Statement ignore = actions.statement() )
{
NodeCursor nodes = transaction.nodeCursor();
PropertyCursor properties = transaction.propertyCursor();
transaction.dataRead().singleNode( nodeId, nodes );
TokenRead token = transaction.tokenRead();
if ( !nodes.next() )
Expand Down Expand Up @@ -423,7 +414,6 @@ public Map<String,Object> getProperties( String... keys )
try ( Statement ignore = actions.statement() )
{
KernelTransaction transaction = actions.kernelTransaction();
CursorFactory cursors = transaction.cursors();
int itemsToReturn = keys.length;
Map<String,Object> properties = new HashMap<>( itemsToReturn );
TokenRead token = transaction.tokenRead();
Expand All @@ -440,30 +430,29 @@ public Map<String,Object> getProperties( String... keys )
}
propertyIds[i] = token.propertyKey( key );
}
try ( NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor propertyCursor = cursors.allocatePropertyCursor() )

NodeCursor nodes = transaction.nodeCursor();
PropertyCursor propertyCursor = transaction.propertyCursor();
transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{
transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{
throw new NotFoundException( new EntityNotFoundException( EntityType.NODE, nodeId ) );
}
nodes.properties( propertyCursor );
int propertiesToFind = itemsToReturn;
while (propertiesToFind > 0 && propertyCursor.next() )
throw new NotFoundException( new EntityNotFoundException( EntityType.NODE, nodeId ) );
}
nodes.properties( propertyCursor );
int propertiesToFind = itemsToReturn;
while ( propertiesToFind > 0 && propertyCursor.next() )
{
//Do a linear check if this is a property we are interested in.
for ( int i = 0; i < itemsToReturn; i++ )
{
//Do a linear check if this is a property we are interested in.
for ( int i = 0; i < itemsToReturn; i++ )
int propertyId = propertyIds[i];
int currentKey = propertyCursor.propertyKey();
if ( propertyId == currentKey )
{
int propertyId = propertyIds[i];
int currentKey = propertyCursor.propertyKey();
if ( propertyId == currentKey )
{
properties.put( keys[i],
propertyCursor.propertyValue().asObjectCopy() );
propertiesToFind--;
break;
}
properties.put( keys[i],
propertyCursor.propertyValue().asObjectCopy() );
propertiesToFind--;
break;
}
}
}
Expand All @@ -475,14 +464,13 @@ public Map<String,Object> getProperties( String... keys )
public Map<String,Object> getAllProperties()
{
KernelTransaction transaction = actions.kernelTransaction();
CursorFactory cursors = transaction.cursors();
Map<String,Object> properties = new HashMap<>();

try ( Statement ignore = actions.statement();
NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor propertyCursor = cursors.allocatePropertyCursor() )
try ( Statement ignore = actions.statement() )
{
TokenRead token = transaction.tokenRead();
PropertyCursor propertyCursor = transaction.propertyCursor();
NodeCursor nodes = transaction.nodeCursor();
transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{
Expand Down Expand Up @@ -510,17 +498,15 @@ public Object getProperty( String key ) throws NotFoundException
throw new IllegalArgumentException( "(null) property key is not allowed" );
}
KernelTransaction transaction = actions.kernelTransaction();
CursorFactory cursors = transaction.cursors();
try ( NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor properties = cursors.allocatePropertyCursor();
Statement ignore = actions.statement()
)
int propertyKey = transaction.tokenRead().propertyKey( key );
if ( propertyKey == KeyReadOperations.NO_SUCH_PROPERTY_KEY )
{
throw new NotFoundException( format( "No such property, '%s'.", key ) );
}
NodeCursor nodes = transaction.nodeCursor();
PropertyCursor properties = transaction.propertyCursor();
try ( Statement ignore = actions.statement())
{
int propertyKey = transaction.tokenRead().propertyKey( key );
if ( propertyKey == KeyReadOperations.NO_SUCH_PROPERTY_KEY )
{
throw new NotFoundException( format( "No such property, '%s'.", key ) );
}
transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{
Expand All @@ -541,38 +527,6 @@ public Object getProperty( String key ) throws NotFoundException
}
throw new NotFoundException( format( "No such property, '%s'.", key ) );
}

// if ( null == key )
// {
// throw new IllegalArgumentException( "(null) property key is not allowed" );
// }
//
// try ( Statement statement = actions.statement() )
// {
// try
// {
// int propertyKeyId = statement.readOperations().propertyKeyGetForName( key );
// if ( propertyKeyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY )
// {
// throw new NotFoundException( format( "No such property, '%s'.", key ) );
// }
//
// Value value = statement.readOperations().nodeGetProperty( nodeId, propertyKeyId );
//
// if ( value == Values.NO_VALUE )
// {
// throw new PropertyNotFoundException( propertyKeyId, EntityType.NODE, nodeId );
// }
//
// return value.asObjectCopy();
//
// }
// catch ( EntityNotFoundException | PropertyNotFoundException e )
// {
// throw new NotFoundException(
// e.getUserMessage( new StatementTokenNameLookup( statement.readOperations() ) ), e );
// }
// }
}

@Override
Expand All @@ -583,17 +537,15 @@ public boolean hasProperty( String key )
return false;
}
KernelTransaction transaction = actions.kernelTransaction();
CursorFactory cursors = transaction.cursors();
try ( NodeCursor nodes = cursors.allocateNodeCursor();
PropertyCursor properties = cursors.allocatePropertyCursor();
Statement ignore = actions.statement()
)
int propertyKey = transaction.tokenRead().propertyKey( key );
if ( propertyKey == KeyReadOperations.NO_SUCH_PROPERTY_KEY )
{
int propertyKey = transaction.tokenRead().propertyKey( key );
if ( propertyKey == KeyReadOperations.NO_SUCH_PROPERTY_KEY )
{
return false;
}
return false;
}
try ( Statement ignore = actions.statement() )
{
NodeCursor nodes = transaction.nodeCursor();
PropertyCursor properties = transaction.propertyCursor();
transaction.dataRead().singleNode( nodeId, nodes );
if ( !nodes.next() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public ResourceIterable<Node> getAllNodes()
{
Statement statement = spi.currentStatement();
KernelTransaction ktx = spi.currentTransaction();
NodeCursor cursor = ktx.cursors().allocateNodeCursor();
NodeCursor cursor = ktx.nodeCursor();
ktx.dataRead().allNodesScan( cursor );
return new PrefetchingResourceIterator<Node>()
{
Expand All @@ -485,7 +485,6 @@ protected Node fetchNextOrNull()
public void close()
{
statement.close();
cursor.close();
}
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.kernel.impl.newapi;

import java.util.Map;
import java.util.Optional;

import org.neo4j.graphdb.TransactionTerminatedException;
import org.neo4j.internal.kernel.api.CapableIndexReference;
Expand Down Expand Up @@ -666,4 +665,14 @@ private void acquireSharedLabelLock( int labelId )
{
ktx.locks().optimistic().acquireShared( ktx.lockTracer(), ResourceTypes.LABEL, labelId );
}

public NodeCursor nodeCursor()
{
return nodeCursor;
}

public PropertyCursor propertyCursor()
{
return propertyCursor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.neo4j.internal.kernel.api.ExplicitIndexRead;
import org.neo4j.internal.kernel.api.ExplicitIndexWrite;
import org.neo4j.internal.kernel.api.Locks;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.SchemaWrite;
Expand Down Expand Up @@ -54,6 +56,18 @@ public Statement acquireStatement()
return new StubStatement( readOperations );
}

@Override
public NodeCursor nodeCursor()
{
throw new UnsupportedOperationException( "not implemented" );
}

@Override
public PropertyCursor propertyCursor()
{
throw new UnsupportedOperationException( "not implemented" );
}

@Override
public void success()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.neo4j.internal.kernel.api.ExplicitIndexRead;
import org.neo4j.internal.kernel.api.ExplicitIndexWrite;
import org.neo4j.internal.kernel.api.Locks;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.SchemaWrite;
Expand Down Expand Up @@ -461,6 +463,18 @@ public Statement acquireStatement()
return remember( mockedState() );
}

@Override
public NodeCursor nodeCursor()
{
throw new UnsupportedOperationException( "not implemented" );
}

@Override
public PropertyCursor propertyCursor()
{
throw new UnsupportedOperationException( "not implemented" );
}

private Statement remember( KernelStatement mockedState )
{
statements.add( mockedState );
Expand Down

0 comments on commit f2c3efe

Please sign in to comment.