Skip to content

Commit

Permalink
Replaced PrimitiveLongObjectMap
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Koval committed May 8, 2018
1 parent 733d8b9 commit 815d2cb
Show file tree
Hide file tree
Showing 59 changed files with 297 additions and 1,303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.{Primitive, PrimitiveLongObjectMap}
import org.eclipse.collections.api.map.primitive.MutableLongObjectMap
import org.neo4j.collection.primitive.Primitive
import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext
import org.neo4j.cypher.internal.util.v3_5.InternalException
import org.neo4j.cypher.internal.util.v3_5.attribution.Id
Expand Down Expand Up @@ -83,7 +84,7 @@ case class PruningVarLengthExpandPipe(source: Pipe,
val pathLength: Int,
val queryState: QueryState,
val row: ExecutionContext,
val expandMap: PrimitiveLongObjectMap[NodeState],
val expandMap: MutableLongObjectMap[NodeState],
val prevLocalRelIndex: Int,
val prevNodeState: NodeState ) {

Expand Down Expand Up @@ -295,11 +296,11 @@ case class PruningVarLengthExpandPipe(source: Pipe,
else executionContextFactory.copyWith(inputRow, self.toName, endNode)
}

def push( node: VirtualNodeValue,
pathLength: Int,
expandMap: PrimitiveLongObjectMap[NodeState],
prevLocalRelIndex: Int,
prevNodeState: NodeState ): VirtualNodeValue = {
def push(node: VirtualNodeValue,
pathLength: Int,
expandMap: MutableLongObjectMap[NodeState],
prevLocalRelIndex: Int,
prevNodeState: NodeState): VirtualNodeValue = {
depth += 1
nodeState(depth) =
new PruningDFS(this, node, path, pathLength, queryState, inputRow, expandMap, prevLocalRelIndex, prevNodeState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
*/
package org.neo4j.cypher.internal.runtime.interpreted.pipes

import org.neo4j.collection.primitive.{Primitive, PrimitiveLongObjectMap}
import org.eclipse.collections.api.map.primitive.MutableLongObjectMap
import org.neo4j.collection.primitive.Primitive
import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext
import org.neo4j.cypher.internal.util.v3_5.InternalException
import org.neo4j.cypher.internal.util.v3_5.attribution.Id
import org.neo4j.cypher.internal.v3_5.expressions.SemanticDirection
import org.neo4j.values.storable.{Value, Values}
import org.neo4j.values.virtual.{RelationshipValue, NodeReference, NodeValue}
import org.neo4j.values.virtual.{NodeReference, NodeValue, RelationshipValue}

/**
* This implementation of pruning-var-expand is no longer used in production, but is used to testing purposes.
Expand Down Expand Up @@ -88,7 +89,7 @@ case class LegacyPruningVarLengthExpandPipe(source: Pipe,
val pathLength: Int,
val state: QueryState,
row: ExecutionContext,
expandMap: PrimitiveLongObjectMap[FullExpandDepths]
expandMap: MutableLongObjectMap[FullExpandDepths]
) extends State with Expandable with CheckPath {

private var rels: Iterator[RelationshipValue] = _
Expand Down Expand Up @@ -183,7 +184,7 @@ case class LegacyPruningVarLengthExpandPipe(source: Pipe,
val pathLength: Int,
val state: QueryState,
row: ExecutionContext,
expandMap: PrimitiveLongObjectMap[FullExpandDepths],
expandMap: MutableLongObjectMap[FullExpandDepths],
updateMinFullExpandDepth: Int => Unit) extends State with Expandable with CheckPath {

import FullExpandDepths.UNINITIALIZED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ public interface IndexPopulator

/**
* Closes and deletes this index.
*
* @throws IOException on I/O error.
*/
void drop() throws IOException;
void drop();

/**
* Called when initially populating an index over existing data. Guaranteed to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class AbstractDelegatingIndexProxy implements IndexProxy
protected abstract IndexProxy getDelegate();

@Override
public void start() throws IOException
public void start()
{
getDelegate().start();
}
Expand All @@ -57,7 +57,7 @@ public IndexUpdater newUpdater( IndexUpdateMode mode )
}

@Override
public void drop() throws IOException
public void drop()
{
getDelegate().drop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ContractCheckingIndexProxy( IndexProxy delegate, boolean started )
}

@Override
public void start() throws IOException
public void start()
{
if ( state.compareAndSet( State.INIT, State.STARTING ) )
{
Expand Down Expand Up @@ -133,7 +133,7 @@ public void force( IOLimiter ioLimiter ) throws IOException
}

@Override
public void drop() throws IOException
public void drop()
{
if ( state.compareAndSet( State.INIT, State.CLOSED ) )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FailedIndexProxy extends AbstractSwallowingIndexProxy
}

@Override
public void drop() throws IOException
public void drop()
{
indexCountsRemover.remove();
String message = "FailedIndexProxy#drop index on " + indexUserDescription + " dropped due to:\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public FlippableIndexProxy()
}

@Override
public void start() throws IOException
public void start()
{
lock.readLock().lock();
try
Expand Down Expand Up @@ -103,7 +103,7 @@ public IndexUpdater newUpdater( IndexUpdateMode mode )
}

@Override
public void drop() throws IOException
public void drop()
{
lock.readLock().lock();
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@
*/
package org.neo4j.kernel.impl.api.index;

import org.eclipse.collections.api.block.procedure.primitive.LongObjectProcedure;
import org.eclipse.collections.api.iterator.IntIterator;
import org.eclipse.collections.api.iterator.LongIterator;
import org.eclipse.collections.api.map.primitive.LongObjectMap;
import org.eclipse.collections.api.map.primitive.MutableIntObjectMap;
import org.eclipse.collections.api.map.primitive.MutableLongObjectMap;
import org.eclipse.collections.api.map.primitive.MutableObjectLongMap;
import org.eclipse.collections.api.set.primitive.IntSet;
import org.eclipse.collections.impl.block.factory.Functions;
import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap;
import org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap;
import org.eclipse.collections.impl.map.mutable.primitive.ObjectLongHashMap;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongObjectMap;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;

/**
Expand All @@ -46,26 +50,26 @@
*/
public final class IndexMap implements Cloneable
{
private final PrimitiveLongObjectMap<IndexProxy> indexesById;
private final MutableLongObjectMap<IndexProxy> indexesById;
private final Map<SchemaDescriptor,IndexProxy> indexesByDescriptor;
private final Map<SchemaDescriptor,Long> indexIdsByDescriptor;
private final MutableObjectLongMap<SchemaDescriptor> indexIdsByDescriptor;
private final MutableIntObjectMap<Set<SchemaDescriptor>> descriptorsByLabel;
private final MutableIntObjectMap<Set<SchemaDescriptor>> descriptorsByProperty;

public IndexMap()
{
this( Primitive.longObjectMap(), new HashMap<>(), new HashMap<>() );
this( Primitive.longObjectMap(), new HashMap<>(), new ObjectLongHashMap<>() );
}

IndexMap( PrimitiveLongObjectMap<IndexProxy> indexesById )
IndexMap( MutableLongObjectMap<IndexProxy> indexesById )
{
this( indexesById, indexesByDescriptor( indexesById ), indexIdsByDescriptor( indexesById ) );
}

private IndexMap(
PrimitiveLongObjectMap<IndexProxy> indexesById,
MutableLongObjectMap<IndexProxy> indexesById,
Map<SchemaDescriptor,IndexProxy> indexesByDescriptor,
Map<SchemaDescriptor,Long> indexIdsByDescriptor )
MutableObjectLongMap<SchemaDescriptor> indexIdsByDescriptor )
{
this.indexesById = indexesById;
this.indexesByDescriptor = indexesByDescriptor;
Expand Down Expand Up @@ -122,13 +126,9 @@ public IndexProxy removeIndexProxy( long indexId )
return removedProxy;
}

public void forEachIndexProxy( BiConsumer<Long, IndexProxy> consumer )
void forEachIndexProxy( LongObjectProcedure<IndexProxy> consumer )
{
indexesById.visitEntries( ( key, indexProxy ) ->
{
consumer.accept( key, indexProxy);
return false;
} );
indexesById.forEachKeyValue( consumer );
}

public Iterable<IndexProxy> getAllIndexProxies()
Expand Down Expand Up @@ -169,8 +169,7 @@ public Set<SchemaDescriptor> getRelatedIndexes(
@Override
public IndexMap clone()
{
return new IndexMap( clonePrimitiveMap( indexesById ), cloneMap( indexesByDescriptor ),
cloneMap( indexIdsByDescriptor ) );
return new IndexMap( LongObjectHashMap.newMap( indexesById ), cloneMap( indexesByDescriptor ), new ObjectLongHashMap<>( indexIdsByDescriptor ) );
}

public Iterator<SchemaDescriptor> descriptors()
Expand All @@ -180,7 +179,7 @@ public Iterator<SchemaDescriptor> descriptors()

public LongIterator indexIds()
{
return indexesById.longIterator();
return indexesById.keySet().longIterator();
}

public int size()
Expand All @@ -197,11 +196,6 @@ private <K, V> Map<K, V> cloneMap( Map<K, V> map )
return shallowCopy;
}

private PrimitiveLongObjectMap<IndexProxy> clonePrimitiveMap( PrimitiveLongObjectMap<IndexProxy> indexesById )
{
return PrimitiveLongCollections.copy( indexesById );
}

private void addDescriptorToLookups( SchemaDescriptor schema )
{
addToLookup( schema.keyId(), schema, descriptorsByLabel );
Expand Down Expand Up @@ -239,23 +233,18 @@ private void removeFromLookup(
}
}

private static Map<SchemaDescriptor, IndexProxy> indexesByDescriptor( PrimitiveLongObjectMap<IndexProxy> indexesById )
private static Map<SchemaDescriptor, IndexProxy> indexesByDescriptor( LongObjectMap<IndexProxy> indexesById )
{
Map<SchemaDescriptor, IndexProxy> map = new HashMap<>();
for ( IndexProxy proxy : indexesById.values() )
{
map.put( proxy.schema(), proxy );
}
return map;
return indexesById.toMap( IndexProxy::schema, Functions.identity() );
}

private static Map<SchemaDescriptor, Long> indexIdsByDescriptor( PrimitiveLongObjectMap<IndexProxy> indexesById )
private static MutableObjectLongMap<SchemaDescriptor> indexIdsByDescriptor( LongObjectMap<IndexProxy> indexesById )
{
Map<SchemaDescriptor, Long> map = new HashMap<>();
indexesById.visitEntries( ( key, indexProxy ) ->
final MutableObjectLongMap<SchemaDescriptor> map = new ObjectLongHashMap<>( indexesById.size() );
indexesById.forEachKeyValue( ( id, indexProxy ) ->
{
map.put( indexProxy.schema(), key );
return false;
map.put( indexProxy.schema(), id );

} );
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
*/
public interface IndexProxy extends SchemaDescriptorSupplier
{
void start() throws IOException;
void start();

IndexUpdater newUpdater( IndexUpdateMode mode );

/**
* Drop index.
* Must close the context as well.
*/
void drop() throws IOException;
void drop();

/**
* Close this index context.
Expand Down

0 comments on commit 815d2cb

Please sign in to comment.