Skip to content

Commit

Permalink
Break out store cursors from default cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and tinwelint committed Jun 11, 2018
1 parent 3f35219 commit 1a65ebc
Show file tree
Hide file tree
Showing 26 changed files with 1,954 additions and 1,345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.locks.LockSupport;
import java.util.function.BooleanSupplier;
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
import java.util.function.Supplier;
import javax.annotation.Nonnull;
Expand All @@ -55,6 +56,8 @@ public static <T> Predicate<T> alwaysTrue()
return x -> true;
}

public static LongPredicate alwaysFalseLong = x -> false;

public static <T> Predicate<T> alwaysFalse()
{
return x -> false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public interface NodeCursor extends Cursor

boolean hasLabel( int label );

boolean hasProperties();

void relationships( RelationshipGroupCursor cursor );

void allRelationships( RelationshipTraversalCursor relationships );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public interface RelationshipDataAccessor

int type();

boolean hasProperties();

void source( NodeCursor cursor );

void target( NodeCursor cursor );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,32 +872,40 @@ public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception
// Then
try ( Transaction tx = beginTransaction() )
{
try ( NodeCursor cursor = tx.cursors().allocateNodeCursor() )
try ( NodeCursor cursor = tx.cursors().allocateNodeCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
{
tx.dataRead().singleNode( node, cursor );
assertTrue( cursor.next() );
assertFalse( cursor.hasProperties() );
assertFalse( hasProperties( cursor, props ) );
tx.dataWrite().nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
stringValue( "foo" ) );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
}
}
}

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

@Test
public void hasPropertiesShouldSeeNewlyCreatedPropertiesOnNewlyCreatedNode() throws Exception
{
try ( Transaction tx = beginTransaction() )
{
long node = tx.dataWrite().nodeCreate();
try ( NodeCursor cursor = tx.cursors().allocateNodeCursor() )
try ( NodeCursor cursor = tx.cursors().allocateNodeCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
{
tx.dataRead().singleNode( node, cursor );
assertTrue( cursor.next() );
assertFalse( cursor.hasProperties() );
assertFalse( hasProperties( cursor, props ) );
tx.dataWrite().nodeSetProperty( node, tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
stringValue( "foo" ) );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
}
}
}
Expand All @@ -923,18 +931,19 @@ public void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception
// Then
try ( Transaction tx = beginTransaction() )
{
try ( NodeCursor cursor = tx.cursors().allocateNodeCursor() )
try ( NodeCursor cursor = tx.cursors().allocateNodeCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
{
tx.dataRead().singleNode( node, cursor );
assertTrue( cursor.next() );

assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
tx.dataWrite().nodeRemoveProperty( node, prop1 );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
tx.dataWrite().nodeRemoveProperty( node, prop2 );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
tx.dataWrite().nodeRemoveProperty( node, prop3 );
assertFalse( cursor.hasProperties() );
assertFalse( hasProperties( cursor, props ) );
}
}
}
Expand All @@ -958,7 +967,7 @@ public void propertyTypeShouldBeTxStateAware() throws Exception
{
tx.dataRead().singleNode( node, nodes );
assertTrue( nodes.next() );
assertFalse( nodes.hasProperties() );
assertFalse( hasProperties( nodes, properties ) );
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
tx.dataWrite().nodeSetProperty( node, prop, stringValue( "foo" ) );
nodes.properties( properties );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void shouldNotAccessNonExistentProperties()
// when
read.singleNode( bare, node );
assertTrue( "node by reference", node.next() );
assertFalse( "no properties", node.hasProperties() );
assertFalse( "no properties", hasProperties( node, props ) );

node.properties( props );
assertFalse( "no properties by direct method", props.next() );
Expand Down Expand Up @@ -219,7 +219,7 @@ public void shouldAccessAllNodeProperties()
// when
read.singleNode( allProps, node );
assertTrue( "node by reference", node.next() );
assertTrue( "has properties", node.hasProperties() );
assertTrue( "has properties", hasProperties( node, props ) );

node.properties( props );
Set<Object> values = new HashSet<>();
Expand Down Expand Up @@ -261,7 +261,7 @@ private void assertAccessSingleProperty( long nodeId, Object expectedValue )
// when
read.singleNode( nodeId, node );
assertTrue( "node by reference", node.next() );
assertTrue( "has properties", node.hasProperties() );
assertTrue( "has properties", hasProperties( node, props ) );

node.properties( props );
assertTrue( "has properties by direct method", props.next() );
Expand All @@ -275,6 +275,12 @@ private void assertAccessSingleProperty( long nodeId, Object expectedValue )
}
}

private boolean hasProperties( NodeCursor node, PropertyCursor props )
{
node.properties( props );
return props.next();
}

private static TypeSafeMatcher<int[]> intArray( int... content )
{
return new TypeSafeMatcher<int[]>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1289,15 +1289,16 @@ public void hasPropertiesShouldSeeNewlyCreatedProperties() throws Exception
// Then
try ( Transaction tx = beginTransaction() )
{
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
{
tx.dataRead().singleRelationship( relationship, cursor );
assertTrue( cursor.next() );
assertFalse( cursor.hasProperties() );
assertFalse( hasProperties( cursor, props ) );
tx.dataWrite().relationshipSetProperty( relationship,
tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
stringValue( "foo" ) );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
}
}
}
Expand All @@ -1310,15 +1311,16 @@ 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() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor() )
{
tx.dataRead().singleRelationship( relationship, cursor );
assertTrue( cursor.next() );
assertFalse( cursor.hasProperties() );
assertFalse( hasProperties( cursor, props ) );
tx.dataWrite().relationshipSetProperty( relationship,
tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" ),
stringValue( "foo" ) );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
}
}
}
Expand Down Expand Up @@ -1346,18 +1348,19 @@ public void hasPropertiesShouldSeeNewlyRemovedProperties() throws Exception
// Then
try ( Transaction tx = beginTransaction() )
{
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor() )
try ( RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor();
PropertyCursor props = tx.cursors().allocatePropertyCursor())
{
tx.dataRead().singleRelationship( relationship, cursor );
assertTrue( cursor.next() );

assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
tx.dataWrite().relationshipRemoveProperty( relationship, prop1 );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
tx.dataWrite().relationshipRemoveProperty( relationship, prop2 );
assertTrue( cursor.hasProperties() );
assertTrue( hasProperties( cursor, props ) );
tx.dataWrite().relationshipRemoveProperty( relationship, prop3 );
assertFalse( cursor.hasProperties() );
assertFalse( hasProperties( cursor, props ) );
}
}
}
Expand All @@ -1383,7 +1386,7 @@ public void propertyTypeShouldBeTxStateAware() throws Exception
{
tx.dataRead().singleRelationship( relationship, relationships );
assertTrue( relationships.next() );
assertFalse( relationships.hasProperties() );
assertFalse( hasProperties( relationships, properties ) );
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName( "prop" );
tx.dataWrite().relationshipSetProperty( relationship, prop, stringValue( "foo" ) );
relationships.properties( properties );
Expand All @@ -1403,6 +1406,12 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ public boolean hasLabel( int label )
return labels().contains( label );
}

@Override
public boolean hasProperties()
{
return (offset >= 0 && offset < nodes.size()) && !nodes.get( offset ).properties.isEmpty();
}

@Override
public void relationships( RelationshipGroupCursor cursor )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ public int type()
return store.get( chainId ).get( offset ).type;
}

@Override
public boolean hasProperties()
{
return false;
}

@Override
public void source( NodeCursor cursor )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,15 @@ long relationshipHighMark()
}

@Override
TextValue string( DefaultPropertyCursor cursor, long reference, PageCursor page )
TextValue string( StorePropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = properties.loadString( reference, cursor.buffer, page );
buffer.flip();
return Values.stringValue( UTF8.decode( buffer.array(), 0, buffer.limit() ) );
}

@Override
ArrayValue array( DefaultPropertyCursor cursor, long reference, PageCursor page )
ArrayValue array( StorePropertyCursor cursor, long reference, PageCursor page )
{
ByteBuffer buffer = cursor.buffer = properties.loadArray( reference, cursor.buffer, page );
buffer.flip();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public DefaultRelationshipTraversalCursor allocateRelationshipTraversalCursor()
{
if ( relationshipTraversalCursor == null )
{
return trace( new DefaultRelationshipTraversalCursor( new DefaultRelationshipGroupCursor( null ), this ) );
return trace( new DefaultRelationshipTraversalCursor( this ) );
}

try
Expand Down

0 comments on commit 1a65ebc

Please sign in to comment.