Skip to content

Commit

Permalink
Replaced PrimitiveIntSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed May 8, 2018
1 parent 9cb5030 commit 230ee93
Show file tree
Hide file tree
Showing 52 changed files with 237 additions and 717 deletions.
Expand Up @@ -19,10 +19,11 @@
*/
package org.neo4j.consistency.checking;

import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.Arrays;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.store.RecordAccess;
import org.neo4j.kernel.impl.store.record.PrimitiveRecord;
Expand All @@ -34,7 +35,7 @@ public class ChainCheck<RECORD extends PrimitiveRecord, REPORT extends Consisten
implements ComparativeRecordChecker<RECORD, PropertyRecord, REPORT>
{
private static final int MAX_BLOCK_PER_RECORD_COUNT = 4;
private final PrimitiveIntSet keys = Primitive.intSet();
private final MutableIntSet keys = new IntHashSet();

@Override
public void checkReference( RECORD record, PropertyRecord property, CheckerEngine<RECORD, REPORT> engine,
Expand Down
Expand Up @@ -19,11 +19,12 @@
*/
package org.neo4j.consistency.checking;

import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.Iterator;
import java.util.function.Function;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.consistency.checking.full.MandatoryProperties;
import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.store.RecordAccess;
Expand Down Expand Up @@ -56,7 +57,8 @@ public void checkConsistency( RECORD record, CheckerEngine<RECORD, REPORT> engin
engine.report().propertyNotFirstInChain( firstProp );
}

try ( PrimitiveIntSet keys = Primitive.intSet();
final MutableIntSet keys = new IntHashSet();
try (
MandatoryProperties.Check<RECORD,REPORT> mandatory = mandatoryProperties.apply( record ) )
{
checkChainItem( firstProp, engine, keys, mandatory );
Expand All @@ -71,7 +73,7 @@ public void checkConsistency( RECORD record, CheckerEngine<RECORD, REPORT> engin
}

private void checkChainItem( PropertyRecord property, CheckerEngine<RECORD,REPORT> engine,
PrimitiveIntSet keys, MandatoryProperties.Check<RECORD,REPORT> mandatory )
MutableIntSet keys, MandatoryProperties.Check<RECORD,REPORT> mandatory )
{
if ( !property.inUse() )
{
Expand Down
Expand Up @@ -20,13 +20,15 @@
package org.neo4j.consistency.checking.full;

import org.eclipse.collections.api.iterator.IntIterator;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.Arrays;
import java.util.function.Function;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntObjectMap;
import org.neo4j.collection.primitive.PrimitiveIntSet;

import org.neo4j.consistency.RecordType;
import org.neo4j.consistency.report.ConsistencyReport;
import org.neo4j.consistency.report.ConsistencyReporter;
Expand Down Expand Up @@ -87,7 +89,7 @@ public Function<NodeRecord,Check<NodeRecord,ConsistencyReport.NodeConsistencyRep
{
return node ->
{
PrimitiveIntSet keys = null;
MutableIntSet keys = null;
for ( long labelId : NodeLabelReader.getListOfLabels( node, storeAccess.getNodeDynamicLabelStore() ) )
{
// labelId _is_ actually an int. A technical detail in the store format has these come in a long[]
Expand All @@ -96,7 +98,7 @@ public Function<NodeRecord,Check<NodeRecord,ConsistencyReport.NodeConsistencyRep
{
if ( keys == null )
{
keys = Primitive.intSet( 16 );
keys = new IntHashSet( 16 );
}
for ( int key : propertyKeys )
{
Expand All @@ -119,7 +121,7 @@ public Function<NodeRecord,Check<NodeRecord,ConsistencyReport.NodeConsistencyRep
int[] propertyKeys = relationships.get( relationship.getType() );
if ( propertyKeys != null )
{
PrimitiveIntSet keys = Primitive.intSet( propertyKeys.length );
final MutableIntSet keys = new IntHashSet( propertyKeys.length );
for ( int key : propertyKeys )
{
keys.add( key );
Expand Down Expand Up @@ -191,13 +193,13 @@ private static class RealCheck<RECORD extends PrimitiveRecord,REPORT extends Con
implements Check<RECORD,REPORT>
{
private final RECORD record;
private final PrimitiveIntSet mandatoryKeys;
private final MutableIntSet mandatoryKeys;
private final Class<REPORT> reportClass;
private final ConsistencyReporter reporter;
private final RecordType recordType;

RealCheck( RECORD record, Class<REPORT> reportClass, ConsistencyReporter reporter, RecordType recordType,
PrimitiveIntSet mandatoryKeys )
MutableIntSet mandatoryKeys )
{
this.record = record;
this.reportClass = reportClass;
Expand Down
Expand Up @@ -20,6 +20,8 @@
package org.neo4j.consistency.checking.full;

import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -28,7 +30,7 @@

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntObjectMap;
import org.neo4j.collection.primitive.PrimitiveIntSet;

import org.neo4j.consistency.checking.ChainCheck;
import org.neo4j.consistency.checking.CheckerEngine;
import org.neo4j.consistency.checking.RecordCheck;
Expand Down Expand Up @@ -177,7 +179,7 @@ private void checkProperty( NodeRecord record,
engine.report().propertyNotFirstInChain( firstProp );
}

PrimitiveIntSet keys = Primitive.intSet();
final MutableIntSet keys = new IntHashSet();
for ( PropertyRecord property : props )
{
if ( !property.inUse() )
Expand Down
Expand Up @@ -20,12 +20,13 @@
package org.neo4j.io.pagecache.impl.muninn;

import org.eclipse.collections.api.iterator.IntIterator;
import org.eclipse.collections.api.set.primitive.IntSet;
import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.Arrays;
import java.util.function.Consumer;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.io.pagecache.PageSwapper;

import static org.neo4j.helpers.Numbers.safeCastIntToShort;
Expand All @@ -47,7 +48,7 @@ final class SwapperSet
private static final SwapperMapping TOMBSTONE = new SwapperMapping( 0, null );
private static final int MAX_SWAPPER_ID = Short.MAX_VALUE;
private volatile SwapperMapping[] swapperMappings = new SwapperMapping[] { SENTINEL };
private final PrimitiveIntSet free = Primitive.intSet();
private final MutableIntSet free = new IntHashSet();
private final Object vacuumLock = new Object();
private int freeCounter; // Used in `free`; Guarded by `this`

Expand Down Expand Up @@ -151,15 +152,15 @@ synchronized boolean free( int id )
* This is done with careful synchronisation such that allocating and freeing of ids is allowed to mostly proceed
* concurrently.
*/
void vacuum( Consumer<PrimitiveIntSet> evictAllLoadedPagesCallback )
void vacuum( Consumer<IntSet> evictAllLoadedPagesCallback )
{
// We do this complicated locking to avoid blocking allocate() and free() as much as possible, while still only
// allow a single thread to do vacuum at a time, and at the same time have consistent locking around the
// set of free ids.
synchronized ( vacuumLock )
{
// Collect currently free ids.
PrimitiveIntSet freeIds = Primitive.intSet();
final MutableIntSet freeIds = new IntHashSet();
SwapperMapping[] swapperMappings = this.swapperMappings;
for ( int id = 0; id < swapperMappings.length; id++ )
{
Expand Down Expand Up @@ -192,7 +193,7 @@ void vacuum( Consumer<PrimitiveIntSet> evictAllLoadedPagesCallback )
}
synchronized ( free )
{
free.addAll( freeIds.intIterator() );
free.addAll( freeIds );
}
}
}
Expand Down
Expand Up @@ -19,14 +19,14 @@
*/
package org.neo4j.io.pagecache.impl.muninn;

import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.io.pagecache.PageSwapper;
import org.neo4j.io.pagecache.tracing.DummyPageSwapper;

Expand Down Expand Up @@ -85,14 +85,14 @@ public void doubleFreeMustThrow()
public void freedIdsMustNotBeReusedBeforeVacuum()
{
PageSwapper swapper = new DummyPageSwapper( "a", 42 );
PrimitiveIntSet ids = Primitive.intSet( 10_000 );
MutableIntSet ids = new IntHashSet( 10_000 );
for ( int i = 0; i < 10_000; i++ )
{
allocateFreeAndAssertNotReused( swapper, ids, i );
}
}

private void allocateFreeAndAssertNotReused( PageSwapper swapper, PrimitiveIntSet ids, int i )
private void allocateFreeAndAssertNotReused( PageSwapper swapper, MutableIntSet ids, int i )
{
int id = set.allocate( swapper );
set.free( id );
Expand All @@ -106,21 +106,20 @@ private void allocateFreeAndAssertNotReused( PageSwapper swapper, PrimitiveIntSe
@Test
public void freedAllocationsMustBecomeAvailableAfterVacuum()
{
PrimitiveIntSet allocated = Primitive.intSet();
PrimitiveIntSet freed = Primitive.intSet();
PrimitiveIntSet vacuumed = Primitive.intSet();
PrimitiveIntSet reused = Primitive.intSet();
MutableIntSet allocated = new IntHashSet();
MutableIntSet freed = new IntHashSet();
MutableIntSet vacuumed = new IntHashSet();
MutableIntSet reused = new IntHashSet();
PageSwapper swapper = new DummyPageSwapper( "a", 42 );

allocateAndAddTenThousand( allocated, swapper );

allocated.visitKeys( id ->
allocated.forEach( id ->
{
set.free( id );
freed.add( id );
return false;
} );
set.vacuum( swapperIds -> vacuumed.addAll( swapperIds.intIterator() ) );
set.vacuum( vacuumed::addAll );

allocateAndAddTenThousand( reused, swapper );

Expand All @@ -129,15 +128,15 @@ public void freedAllocationsMustBecomeAvailableAfterVacuum()
assertThat( allocated, is( equalTo( reused ) ) );
}

private void allocateAndAddTenThousand( PrimitiveIntSet allocated, PageSwapper swapper )
private void allocateAndAddTenThousand( MutableIntSet allocated, PageSwapper swapper )
{
for ( int i = 0; i < 10_000; i++ )
{
allocateAndAdd( allocated, swapper );
}
}

private void allocateAndAdd( PrimitiveIntSet allocated, PageSwapper swapper )
private void allocateAndAdd( MutableIntSet allocated, PageSwapper swapper )
{
int id = set.allocate( swapper );
allocated.add( id );
Expand All @@ -151,8 +150,8 @@ public void vacuumMustNotDustOffAnyIdsWhenNoneHaveBeenFreed()
{
set.allocate( swapper );
}
PrimitiveIntSet vacuumedIds = Primitive.intSet();
set.vacuum( swapperIds -> vacuumedIds.addAll( swapperIds.intIterator() ) );
MutableIntSet vacuumedIds = new IntHashSet();
set.vacuum( vacuumedIds::addAll );
if ( !vacuumedIds.isEmpty() )
{
throw new AssertionError( "Vacuum found id " + vacuumedIds + " when it should have found nothing" );
Expand Down
Expand Up @@ -19,10 +19,11 @@
*/
package org.neo4j.kernel.api.txstate;

import org.eclipse.collections.api.set.primitive.IntSet;

import java.util.Set;
import java.util.function.IntConsumer;

import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.collection.primitive.PrimitiveIntVisitor;
import org.neo4j.cursor.Cursor;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException;
Expand Down Expand Up @@ -72,11 +73,10 @@ public void visitDeletedNode( long id )

private void decrementCountForLabelsAndRelationships( NodeItem node )
{
PrimitiveIntSet labelIds = node.labels();
labelIds.visitKeys( labelId ->
final IntSet labelIds = node.labels();
labelIds.forEach( labelId ->
{
counts.incrementNodeCount( labelId, -1 );
return false;
} );

storeLayer.degrees( statement, node,
Expand Down Expand Up @@ -133,10 +133,10 @@ public void visitNodeLabelChanges( long id, final Set<Integer> added, final Set<
super.visitNodeLabelChanges( id, added, removed );
}

private void updateRelationshipsCountsFromDegrees( PrimitiveIntSet labels, int type, long outgoing,
private void updateRelationshipsCountsFromDegrees( IntSet labels, int type, long outgoing,
long incoming )
{
labels.visitKeys( label -> updateRelationshipsCountsFromDegrees( type, label, outgoing, incoming ) );
labels.forEach( label -> updateRelationshipsCountsFromDegrees( type, label, outgoing, incoming ) );
}

private boolean updateRelationshipsCountsFromDegrees( int type, int label, long outgoing, long incoming )
Expand All @@ -157,9 +157,9 @@ private void updateRelationshipCount( long startNode, int type, long endNode, in
visitLabels( endNode, labelId -> updateRelationshipsCountsFromDegrees( type, labelId, 0, delta ) );
}

private void visitLabels( long nodeId, PrimitiveIntVisitor<RuntimeException> visitor )
private void visitLabels( long nodeId, IntConsumer visitor )
{
nodeCursor( statement, nodeId ).forAll( node -> node.labels().visitKeys( visitor ) );
nodeCursor( statement, nodeId ).forAll( node -> node.labels().forEach( visitor::accept ) );
}

private Cursor<NodeItem> nodeCursor( StorageStatement statement, long nodeId )
Expand Down
Expand Up @@ -19,17 +19,18 @@
*/
package org.neo4j.kernel.impl.api.cursor;

import org.eclipse.collections.api.set.primitive.MutableIntSet;
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet;

import java.util.function.Consumer;

import org.neo4j.collection.primitive.PrimitiveIntSet;
import org.neo4j.cursor.Cursor;
import org.neo4j.kernel.api.StatementConstants;
import org.neo4j.kernel.api.txstate.TransactionState;
import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.storageengine.api.NodeItem;
import org.neo4j.storageengine.api.txstate.NodeState;

import static org.neo4j.collection.primitive.Primitive.intSet;
import static org.neo4j.kernel.impl.locking.LockService.NO_LOCK;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_PROPERTY;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
Expand Down Expand Up @@ -116,9 +117,9 @@ public long id()
}

@Override
public PrimitiveIntSet labels()
public MutableIntSet labels()
{
return state.augmentLabels( nodeIsAddedInThisTx ? intSet() : this.cursor.get().labels(), nodeState );
return state.augmentLabels( nodeIsAddedInThisTx ? new IntHashSet() : this.cursor.get().labels(), nodeState );
}

@Override
Expand Down

0 comments on commit 230ee93

Please sign in to comment.