Skip to content

Commit

Permalink
Extract interface to relationship/group store cursors
Browse files Browse the repository at this point in the history
and simplifies implementations by avoiding lots of complexity
introduced by RelationshipReferenceEncoding.
  • Loading branch information
tinwelint committed Jun 11, 2018
1 parent d938e2b commit 4023dc1
Show file tree
Hide file tree
Showing 43 changed files with 588 additions and 1,047 deletions.
Expand Up @@ -265,38 +265,6 @@ long lockingNodeUniqueIndexSeek( IndexReference index, IndexQuery.ExactPredicate


Scan<RelationshipScanCursor> relationshipTypeScan( int type ); 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 );

/** /**
* Checks if a node was deleted in the current transaction * Checks if a node was deleted in the current transaction
* @param node the node to check * @param node the node to check
Expand All @@ -311,16 +279,6 @@ long lockingNodeUniqueIndexSeek( IndexReference index, IndexQuery.ExactPredicate
*/ */
boolean relationshipDeletedInTransaction( long relationship ); boolean relationshipDeletedInTransaction( long relationship );


/**
* @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 );

void graphProperties( PropertyCursor cursor ); void graphProperties( PropertyCursor cursor );


// hints to the page cache about data we will be accessing in the future: // hints to the page cache about data we will be accessing in the future:
Expand Down
Expand Up @@ -19,13 +19,13 @@
*/ */
package org.neo4j.internal.kernel.api; package org.neo4j.internal.kernel.api;


import java.util.HashSet;
import java.util.Set;

import org.hamcrest.Description; import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher; import org.hamcrest.TypeSafeMatcher;
import org.junit.Test; import org.junit.Test;


import java.util.HashSet;
import java.util.Set;

import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void shouldNotAccessNonExistentProperties()
node.properties( props ); node.properties( props );
assertFalse( "no properties by direct method", props.next() ); assertFalse( "no properties by direct method", props.next() );


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


assertFalse( "only one node", node.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() ); assertEquals( "correct value", expectedValue, props.propertyValue() );
assertFalse( "single property", props.next() ); assertFalse( "single property", props.next() );


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


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

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

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


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


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


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


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


// loops // loops
if ( detached ) group.loops( relationship );
{
read.relationships( start.id, group.loopsReference(), relationship );
}
else
{
group.loops( relationship );
}
// then // then
RelationshipTestSupport RelationshipTestSupport.assertCount( tx, relationship, expectedCounts, type, BOTH );
.assertCount( tx, relationship, expectedCounts, group.type(), BOTH );
} }
} }
} }
Expand Down
Expand Up @@ -250,56 +250,30 @@ public void shouldHaveBeenAbleToCreateDenseAndSparseNodes()
@Test @Test
public void shouldTraverseSparseNodeViaGroups() throws Exception public void shouldTraverseSparseNodeViaGroups() throws Exception
{ {
traverseViaGroups( sparse, false ); traverseViaGroups( sparse );
} }


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

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

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


@Test @Test
public void shouldTraverseSparseNodeWithoutGroups() throws Exception public void shouldTraverseSparseNodeWithoutGroups() throws Exception
{ {
Assume.assumeTrue( supportsSparseNodes() && supportsDirectTraversal() ); Assume.assumeTrue( supportsSparseNodes() && supportsDirectTraversal() );
traverseWithoutGroups( sparse, false ); traverseWithoutGroups( sparse );
} }


@Test @Test
public void shouldTraverseDenseNodeWithoutGroups() throws Exception public void shouldTraverseDenseNodeWithoutGroups() throws Exception
{ {
Assume.assumeTrue( supportsDirectTraversal() ); Assume.assumeTrue( supportsDirectTraversal() );
traverseWithoutGroups( dense, false ); traverseWithoutGroups( dense );
}

@Test
public void shouldTraverseSparseNodeWithoutGroupsWithDetachedReferences() throws Exception
{
Assume.assumeTrue( supportsSparseNodes() );
traverseWithoutGroups( sparse, true );
}

@Test
public void shouldTraverseDenseNodeWithoutGroupsWithDetachedReferences() throws Exception
{
Assume.assumeTrue( supportsDirectTraversal() );
traverseWithoutGroups( dense, true );
} }


private void traverseViaGroups( RelationshipTestSupport.StartNode start, boolean detached ) throws KernelException private void traverseViaGroups( RelationshipTestSupport.StartNode start ) throws KernelException
{ {
// given // given
Map<String,Integer> expectedCounts = start.expectedCounts(); Map<String,Integer> expectedCounts = start.expectedCounts();
Expand All @@ -311,57 +285,30 @@ private void traverseViaGroups( RelationshipTestSupport.StartNode start, boolean
// when // when
read.singleNode( start.id, node ); read.singleNode( start.id, node );
assertTrue( "access node", node.next() ); assertTrue( "access node", node.next() );
if ( detached ) node.relationships( group );
{
read.relationshipGroups( start.id, node.relationshipGroupReference(), group );
}
else
{
node.relationships( group );
}


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


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


// loops // loops
if ( detached ) group.loops( relationship );
{
read.relationships( start.id, group.loopsReference(), relationship );
}
else
{
group.loops( relationship );
}
// then // then
assertCount( tx, relationship, expectedCounts, group.type(), BOTH ); assertCount( tx, relationship, expectedCounts, group.type(), BOTH );
} }
} }
} }


private void traverseWithoutGroups( RelationshipTestSupport.StartNode start, boolean detached ) private void traverseWithoutGroups( RelationshipTestSupport.StartNode start )
throws KernelException throws KernelException
{ {
// given // given
Expand All @@ -371,15 +318,7 @@ private void traverseWithoutGroups( RelationshipTestSupport.StartNode start, boo
// when // when
read.singleNode( start.id, node ); read.singleNode( start.id, node );
assertTrue( "access node", node.next() ); assertTrue( "access node", node.next() );

node.allRelationships( relationship );
if ( detached )
{
read.relationships( start.id, node.allRelationshipsReference(), relationship );
}
else
{
node.allRelationships( relationship );
}


Map<String,Integer> counts = count( tx, relationship ); Map<String,Integer> counts = count( tx, relationship );


Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.neo4j.internal.kernel.api.NodeValueIndexCursor; import org.neo4j.internal.kernel.api.NodeValueIndexCursor;
import org.neo4j.internal.kernel.api.PropertyCursor; import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.Read; import org.neo4j.internal.kernel.api.Read;
import org.neo4j.internal.kernel.api.RelationshipGroupCursor;
import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.RelationshipScanCursor;
import org.neo4j.internal.kernel.api.RelationshipTraversalCursor; import org.neo4j.internal.kernel.api.RelationshipTraversalCursor;
import org.neo4j.internal.kernel.api.Scan; import org.neo4j.internal.kernel.api.Scan;
Expand Down Expand Up @@ -175,24 +174,6 @@ public Scan<RelationshipScanCursor> relationshipTypeScan( int type )
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override
public void relationshipGroups( long nodeReference, long reference, RelationshipGroupCursor cursor )
{
throw new UnsupportedOperationException();
}

@Override
public void relationships( long nodeReference, long reference, RelationshipTraversalCursor cursor )
{
throw new UnsupportedOperationException();
}

@Override
public void nodeProperties( long nodeReference, long reference, PropertyCursor cursor )
{
throw new UnsupportedOperationException();
}

@Override @Override
public boolean nodeDeletedInTransaction( long node ) public boolean nodeDeletedInTransaction( long node )
{ {
Expand All @@ -205,12 +186,6 @@ public boolean relationshipDeletedInTransaction( long relationship )
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override
public void relationshipProperties( long relationshipReference, long reference, PropertyCursor cursor )
{
throw new UnsupportedOperationException();
}

@Override @Override
public void graphProperties( PropertyCursor cursor ) public void graphProperties( PropertyCursor cursor )
{ {
Expand Down

0 comments on commit 4023dc1

Please sign in to comment.