Skip to content

Commit

Permalink
Brings back removed kernel API dereferenced accessor methods
Browse files Browse the repository at this point in the history
Some of the reference encoding logic is split, so that most of it is
in the kernel code and only select parts remain as store cursor
responsibilities.
  • Loading branch information
tinwelint committed Jun 11, 2018
1 parent bc8fdc4 commit c798096
Show file tree
Hide file tree
Showing 27 changed files with 642 additions and 165 deletions.
Expand Up @@ -265,6 +265,48 @@ long lockingNodeUniqueIndexSeek( IndexReference index, IndexQuery.ExactPredicate

Scan<RelationshipScanCursor> relationshipTypeScan( int type );

/**
* @param nodeReference
* a reference from {@link NodeCursor#nodeReference()}.
* @param reference
* a reference from {@link NodeCursor#relationshipGroupReference()}.
* @param cursor
* the cursor to use for consuming the results.
*/
void relationshipGroups( long nodeReference, long reference, RelationshipGroupCursor cursor );

/**
* @param nodeReference
* a reference from {@link NodeCursor#nodeReference()}.
* @param reference
* a reference from {@link RelationshipGroupCursor#outgoingReference()},
* {@link RelationshipGroupCursor#incomingReference()},
* or {@link RelationshipGroupCursor#loopsReference()}.
* @param cursor
* the cursor to use for consuming the results.
*/
void relationships( long nodeReference, long reference, RelationshipTraversalCursor cursor );

/**
* @param nodeReference
* the owner of the properties.
* @param reference
* a reference from {@link NodeCursor#propertiesReference()}.
* @param cursor
* the cursor to use for consuming the results.
*/
void nodeProperties( long nodeReference, long reference, PropertyCursor cursor );

/**
* @param relationshipReference
* the owner of the properties.
* @param reference
* a reference from {@link RelationshipDataAccessor#propertiesReference()}.
* @param cursor
* the cursor to use for consuming the results.
*/
void relationshipProperties( long relationshipReference, long reference, PropertyCursor cursor );

/**
* Checks if a node was deleted in the current transaction
* @param node the node to check
Expand Down
Expand Up @@ -175,7 +175,7 @@ public void shouldNotAccessNonExistentProperties()
node.properties( props );
assertFalse( "no properties by direct method", props.next() );

node.properties( props );
read.nodeProperties( node.nodeReference(), node.propertiesReference(), props );
assertFalse( "no properties via property ref", props.next() );

assertFalse( "only one node", node.next() );
Expand Down Expand Up @@ -268,7 +268,7 @@ private void assertAccessSingleProperty( long nodeId, Object expectedValue )
assertEquals( "correct value", expectedValue, props.propertyValue() );
assertFalse( "single property", props.next() );

node.properties( props );
read.nodeProperties( node.nodeReference(), node.propertiesReference(), props );
assertTrue( "has properties via property ref", props.next() );
assertEquals( "correct value", expectedValue, props.propertyValue() );
assertFalse( "single property", props.next() );
Expand Down
Expand Up @@ -307,13 +307,25 @@ public void shouldTraverseDenseNodeWithoutGroupsWithDetachedReferences() throws
@Test
public void shouldTraverseSparseNodeViaGroups() throws Exception
{
traverseViaGroups( sparse( graphDb ) );
traverseViaGroups( sparse( graphDb ), false );
}

@Test
public void shouldTraverseDenseNodeViaGroups() throws Exception
{
traverseViaGroups( RelationshipTestSupport.dense( graphDb ) );
traverseViaGroups( RelationshipTestSupport.dense( graphDb ), false );
}

@Test
public void shouldTraverseSparseNodeViaGroupsWithDetachedReferences() throws Exception
{
traverseViaGroups( sparse( graphDb ), true );
}

@Test
public void shouldTraverseDenseNodeViaGroupsWithDetachedReferences() throws Exception
{
traverseViaGroups( RelationshipTestSupport.dense( graphDb ), true );
}

@Test
Expand Down Expand Up @@ -1130,7 +1142,7 @@ private void traverseWithoutGroups( RelationshipTestSupport.StartNode start, boo
assertTrue( "access node", node.next() );
if ( detached )
{
node.allRelationships( relationship );
tx.dataRead().relationships( start.id, node.allRelationshipsReference(), relationship );
}
else
{
Expand All @@ -1147,7 +1159,7 @@ private void traverseWithoutGroups( RelationshipTestSupport.StartNode start, boo
}
}

private void traverseViaGroups( RelationshipTestSupport.StartNode start ) throws Exception
private void traverseViaGroups( RelationshipTestSupport.StartNode start, boolean detached ) throws Exception
{
try ( Transaction tx = beginTransaction() )
{
Expand All @@ -1162,25 +1174,55 @@ private void traverseViaGroups( RelationshipTestSupport.StartNode start ) throws
// when
read.singleNode( start.id, node );
assertTrue( "access node", node.next() );
node.relationships( group );
if ( detached )
{
read.relationshipGroups( start.id, node.relationshipGroupReference(), group );
}
else
{
node.relationships( group );
}

while ( group.next() )
{
int type = group.type();
// outgoing
group.outgoing( relationship );
if ( detached )
{
read.relationships( start.id, group.outgoingReference(), relationship );
}
else
{
group.outgoing( relationship );
}
// then
RelationshipTestSupport.assertCount( tx, relationship, expectedCounts, type, OUTGOING );
RelationshipTestSupport
.assertCount( tx, relationship, expectedCounts, group.type(), OUTGOING );

// incoming
group.incoming( relationship );
if ( detached )
{
read.relationships( start.id, group.incomingReference(), relationship );
}
else
{
group.incoming( relationship );
}
// then
RelationshipTestSupport.assertCount( tx, relationship, expectedCounts, type, INCOMING );
RelationshipTestSupport
.assertCount( tx, relationship, expectedCounts, group.type(), INCOMING );

// loops
group.loops( relationship );
if ( detached )
{
read.relationships( start.id, group.loopsReference(), relationship );
}
else
{
group.loops( relationship );
}
// then
RelationshipTestSupport.assertCount( tx, relationship, expectedCounts, type, BOTH );
RelationshipTestSupport
.assertCount( tx, relationship, expectedCounts, group.type(), BOTH );
}
}
}
Expand Down Expand Up @@ -1247,16 +1289,15 @@ public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception
// Then
try ( Transaction tx = beginTransaction() )
{
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
{
tx.dataRead().singleRelationship( relationship, cursor );
assertTrue( cursor.next() );
assertFalse( hasProperties( cursor, props ) );
assertFalse( hasProperties( cursor, tx ) );
tx.dataWrite().relationshipSetProperty( relationship,
tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
stringValue( "foo" ) );
assertTrue( hasProperties( cursor, props ) );
assertTrue( hasProperties( cursor, tx ) );
}
}
}
Expand All @@ -1269,16 +1310,15 @@ public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedRelationsh
Write write = tx.dataWrite();
int token = tx.tokenWrite().relationshipTypeGetOrCreateForName( "R" );
long relationship = write.relationshipCreate( write.nodeCreate(), token, write.nodeCreate() );
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
{
tx.dataRead().singleRelationship( relationship, cursor );
assertTrue( cursor.next() );
assertFalse( hasProperties( cursor, props ) );
assertFalse( hasProperties( cursor, tx ) );
tx.dataWrite().relationshipSetProperty( relationship,
tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
stringValue( "foo" ) );
assertTrue( hasProperties( cursor, props ) );
assertTrue( hasProperties( cursor, tx ) );
}
}
}
Expand Down Expand Up @@ -1306,19 +1346,18 @@ public void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception
// Then
try ( Transaction tx = beginTransaction() )
{
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
{
tx.dataRead().singleRelationship( relationship, cursor );
assertTrue( cursor.next() );

assertTrue( hasProperties( cursor, props ) );
assertTrue( hasProperties( cursor, tx ) );
tx.dataWrite().relationshipRemoveProperty( relationship, prop1 );
assertTrue( hasProperties( cursor, props ) );
assertTrue( hasProperties( cursor, tx ) );
tx.dataWrite().relationshipRemoveProperty( relationship, prop2 );
assertTrue( hasProperties( cursor, props ) );
assertTrue( hasProperties( cursor, tx ) );
tx.dataWrite().relationshipRemoveProperty( relationship, prop3 );
assertFalse( hasProperties( cursor, props ) );
assertFalse( hasProperties( cursor, tx ) );
}
}
}
Expand All @@ -1344,7 +1383,7 @@ public void propertyTypeShouldBeTxStateAware() throws Exception
{
tx.dataRead().singleRelationship( relationship, relationships );
assertTrue( relationships.next() );
assertFalse( hasProperties( relationships, properties ) );
assertFalse( hasProperties( relationships, tx ) );
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
tx.dataWrite().relationshipSetProperty( relationship, prop, stringValue( "foo" ) );
relationships.properties( properties );
Expand All @@ -1355,6 +1394,15 @@ public void propertyTypeShouldBeTxStateAware() throws Exception
}
}

private boolean hasProperties( RelationshipScanCursor cursor, Transaction tx )
{
try ( PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor() )
{
cursor.properties( propertyCursor );
return propertyCursor.next();
}
}

private void relateNTimes( int nRelationshipsInStore, int type, long n1, long n2, Transaction tx )
throws KernelException
{
Expand All @@ -1364,12 +1412,6 @@ private void relateNTimes( int nRelationshipsInStore, int type, long n1, long n2
}
}

private boolean hasProperties( RelationshipScanCursor cursor, PropertyCursor props )
{
cursor.properties( props );
return props.next();
}

private void assertCountRelationships(
RelationshipScanCursor relationship, int expectedCount, long sourceNode, int type, long targetNode )
{
Expand Down

0 comments on commit c798096

Please sign in to comment.