Skip to content

Commit

Permalink
Thread safe counts
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Dec 4, 2017
1 parent fbe7782 commit 2eb4aaa
Showing 1 changed file with 11 additions and 9 deletions.
Expand Up @@ -19,6 +19,8 @@
*/ */
package org.neo4j.unsafe.impl.batchimport; package org.neo4j.unsafe.impl.batchimport;


import java.util.concurrent.atomic.LongAdder;

import org.neo4j.kernel.impl.store.record.NodeRecord; import org.neo4j.kernel.impl.store.record.NodeRecord;
import org.neo4j.kernel.impl.store.record.PrimitiveRecord; import org.neo4j.kernel.impl.store.record.PrimitiveRecord;
import org.neo4j.kernel.impl.store.record.RelationshipRecord; import org.neo4j.kernel.impl.store.record.RelationshipRecord;
Expand All @@ -28,20 +30,20 @@
*/ */
public class CountingStoreUpdateMonitor implements EntityStoreUpdaterStep.Monitor public class CountingStoreUpdateMonitor implements EntityStoreUpdaterStep.Monitor
{ {
private long nodes; private final LongAdder nodes = new LongAdder();
private long relationships; private final LongAdder relationships = new LongAdder();
private long properties; private final LongAdder properties = new LongAdder();


@Override @Override
public void entitiesWritten( Class<? extends PrimitiveRecord> type, long count ) public void entitiesWritten( Class<? extends PrimitiveRecord> type, long count )
{ {
if ( type.equals( NodeRecord.class ) ) if ( type.equals( NodeRecord.class ) )
{ {
nodes += count; nodes.add( count );
} }
else if ( type.equals( RelationshipRecord.class ) ) else if ( type.equals( RelationshipRecord.class ) )
{ {
relationships += count; relationships.add( count );
} }
else else
{ {
Expand All @@ -52,21 +54,21 @@ else if ( type.equals( RelationshipRecord.class ) )
@Override @Override
public void propertiesWritten( long count ) public void propertiesWritten( long count )
{ {
properties += count; properties.add( count );
} }


public long propertiesWritten() public long propertiesWritten()
{ {
return properties; return properties.sum();
} }


public long nodesWritten() public long nodesWritten()
{ {
return nodes; return nodes.sum();
} }


public long relationshipsWritten() public long relationshipsWritten()
{ {
return relationships; return relationships.sum();
} }
} }

0 comments on commit 2eb4aaa

Please sign in to comment.