Skip to content

Commit

Permalink
Avoid producing tons of state maps for single node cursor
Browse files Browse the repository at this point in the history
Remember state of already defined nodes only for case of nodes iteration
and do not do that if cursor created to go over single node.
  • Loading branch information
MishaDemianenko committed Jan 12, 2018
1 parent 03b5247 commit 436902e
Showing 1 changed file with 14 additions and 5 deletions.
Expand Up @@ -34,6 +34,7 @@
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;

import static java.util.Collections.emptySet;
import static org.neo4j.kernel.impl.newapi.References.setDirectFlag;
import static org.neo4j.kernel.impl.newapi.References.setGroupFlag;

Expand Down Expand Up @@ -73,7 +74,7 @@ void scan( Read read )
this.highMark = read.nodeHighMark();
this.read = read;
this.hasChanges = HasChanges.MAYBE;
this.addedNodes = null;
this.addedNodes = emptySet();
}

void single( long reference, Read read )
Expand All @@ -91,7 +92,7 @@ void single( long reference, Read read )
this.highMark = NO_ID;
this.read = read;
this.hasChanges = HasChanges.MAYBE;
this.addedNodes = null;
this.addedNodes = emptySet();
}

@Override
Expand Down Expand Up @@ -188,7 +189,7 @@ public boolean next()
TransactionState txs = hasChanges ? read.txState() : null;
do
{
if ( hasChanges && addedNodes.contains( next ) )
if ( hasChanges && containsNode( txs ) )
{
setId( next++ );
setInUse( true );
Expand Down Expand Up @@ -233,6 +234,11 @@ else if ( next < 0 )
return true;
}

private boolean containsNode( TransactionState txs )
{
return isSingle() ? txs.nodeIsAddedInThisTx( next ) : addedNodes.contains( next );
}

@Override
public boolean shouldRetry()
{
Expand All @@ -255,7 +261,7 @@ public void close()
labelCursor = null;
}
hasChanges = HasChanges.MAYBE;
addedNodes = null;
addedNodes = emptySet();
reset();
}

Expand All @@ -277,7 +283,10 @@ private boolean hasChanges()
boolean changes = read.hasTxStateWithChanges();
if ( changes )
{
addedNodes = read.txState().addedAndRemovedNodes().getAddedSnapshot();
if ( !isSingle() )
{
addedNodes = read.txState().addedAndRemovedNodes().getAddedSnapshot();
}
hasChanges = HasChanges.YES;
}
else
Expand Down

0 comments on commit 436902e

Please sign in to comment.