Skip to content

Commit

Permalink
NodeCursor must be stable
Browse files Browse the repository at this point in the history
For queries like `MATCH () CREATE ()` we need the cursor to be stable and
only check the initial tx state.
  • Loading branch information
pontusmelke committed Dec 6, 2017
1 parent b3eedf4 commit 55d031a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Expand Up @@ -317,7 +317,6 @@ public long getId()
throw new UnsupportedOperationException( "id not defined" );
}


@Override
public boolean hasPropertyChanges()
{
Expand Down
Expand Up @@ -43,6 +43,14 @@ class NodeCursor extends NodeRecord implements org.neo4j.internal.kernel.api.Nod
private PageCursor pageCursor;
private long next;
private long highMark;
private HasChanges hasChanges = HasChanges.MAYBE;

private enum HasChanges
{
MAYBE,
YES,
NO
}

NodeCursor()
{
Expand All @@ -66,6 +74,8 @@ void scan( Read read )
{
labelCursor = read.labelCursor();
}
this.labelCursor = read.labelCursor();
this.hasChanges = HasChanges.MAYBE;
}

void single( long reference, Read read )
Expand All @@ -86,6 +96,7 @@ void single( long reference, Read read )
{
labelCursor = read.labelCursor();
}
this.hasChanges = HasChanges.MAYBE;
}

@Override
Expand All @@ -97,7 +108,7 @@ public long nodeReference()
@Override
public LabelSet labels()
{
if ( read.hasTxStateWithChanges() )
if ( hasChanges() )
{
TransactionState txState = read.txState();
if ( txState.nodeIsAddedInThisTx( nodeReference() ) )
Expand Down Expand Up @@ -178,7 +189,7 @@ public long propertiesReference()
//so we can retrieve it later in the property cursor.
long propertiesReference = getNextProp();

if ( read.hasTxStateWithChanges() )
if ( hasChanges() )
{
TransactionState txState = read.txState();
NodeState nodeState = txState.getNodeState( nodeReference() );
Expand Down Expand Up @@ -215,8 +226,8 @@ public boolean next()
return false;
}
// Check tx state
boolean hasChanges = hasChanges();

boolean hasChanges = read.hasTxStateWithChanges();
TransactionState txs = hasChanges ? read.txState() : null;
do
{
Expand Down Expand Up @@ -285,6 +296,8 @@ public void close()
labelCursor.close();
labelCursor = null;
}
hasChanges = HasChanges.MAYBE;

reset();
}

Expand All @@ -294,6 +307,34 @@ public boolean isClosed()
return pageCursor == null;
}

/**
* NodeCursor should only see changes that are there from the beginning
* otherwise it will not be stable.
*/
private boolean hasChanges()
{
switch ( hasChanges )
{
case MAYBE:
boolean changes = read.hasTxStateWithChanges();
if ( changes )
{
hasChanges = HasChanges.YES;
}
else
{
hasChanges = HasChanges.NO;
}
return changes;
case YES:
return true;
case NO:
return false;
default:
throw new IllegalStateException( "Style guide, why are you making me do this" );
}
}

private void reset()
{
next = NO_ID;
Expand Down

0 comments on commit 55d031a

Please sign in to comment.