Skip to content

Commit

Permalink
Uses RecordCursor in ReadNodeRecordsByCacheStep
Browse files Browse the repository at this point in the history
for more efficient reading of records.
  • Loading branch information
tinwelint committed Sep 5, 2016
1 parent fd58f78 commit 2ba46eb
Showing 1 changed file with 20 additions and 3 deletions.
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.unsafe.impl.batchimport; package org.neo4j.unsafe.impl.batchimport;


import org.neo4j.kernel.impl.store.NodeStore; import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.RecordCursor;
import org.neo4j.kernel.impl.store.record.NodeRecord; import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.RecordLoad; import org.neo4j.kernel.impl.store.record.RecordLoad;
import org.neo4j.unsafe.impl.batchimport.cache.ByteArray; import org.neo4j.unsafe.impl.batchimport.cache.ByteArray;
Expand All @@ -40,16 +41,30 @@ public class ReadNodeRecordsByCacheStep extends AbstractStep<NodeRecord[]>
private final boolean denseNodes; private final boolean denseNodes;
private final NodeRelationshipCache cache; private final NodeRelationshipCache cache;
private final int batchSize; private final int batchSize;
private final NodeStore nodeStore; private final RecordCursor<NodeRecord> recordCursor;


public ReadNodeRecordsByCacheStep( StageControl control, Configuration config, public ReadNodeRecordsByCacheStep( StageControl control, Configuration config,
NodeStore nodeStore, NodeRelationshipCache cache, boolean denseNodes ) NodeStore nodeStore, NodeRelationshipCache cache, boolean denseNodes )
{ {
super( control, ">", config ); super( control, ">", config );
this.nodeStore = nodeStore;
this.cache = cache; this.cache = cache;
this.denseNodes = denseNodes; this.denseNodes = denseNodes;
this.batchSize = config.batchSize(); this.batchSize = config.batchSize();
this.recordCursor = nodeStore.newRecordCursor( nodeStore.newRecord() );
}

@Override
public void start( int orderingGuarantees )
{
super.start( orderingGuarantees );
recordCursor.acquire( 0, RecordLoad.CHECK );
}

@Override
public void close() throws Exception
{
recordCursor.close();
super.close();
} }


@Override @Override
Expand Down Expand Up @@ -80,7 +95,9 @@ private class NodeVisitor implements NodeChangeVisitor, AutoCloseable
@Override @Override
public void change( long nodeId, ByteArray array ) public void change( long nodeId, ByteArray array )
{ {
batch[cursor++] = nodeStore.getRecord( nodeId, nodeStore.newRecord(), RecordLoad.CHECK ); boolean inUse = recordCursor.next( nodeId );
assert inUse;
batch[cursor++] = recordCursor.get().clone();
if ( cursor == batchSize ) if ( cursor == batchSize )
{ {
send(); send();
Expand Down

0 comments on commit 2ba46eb

Please sign in to comment.