Skip to content

Commit

Permalink
Use primitive lockingUniqueIndexSeek
Browse files Browse the repository at this point in the history
  • Loading branch information
sherfert committed Aug 14, 2018
1 parent b4a89f8 commit dea143e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 78 deletions.
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.kernel.impl.api.integrationtest;

import org.eclipse.collections.api.tuple.primitive.LongObjectPair;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -92,28 +91,6 @@ public void shouldFindMatchingNode() throws Exception
assertEquals( "Created node was not found", nodeId, foundId );
}

@Test
public void shouldFindMatchingNodeWithPropertyValue() throws Exception
{
// given
IndexReference index = createUniquenessConstraint( labelId, propertyId1 );
Value value = Values.of( "value" );
long nodeId = createNodeWithValue( value );

// when looking for it
Read read = newTransaction().dataRead();
int propertyId = index.properties()[0];
LongObjectPair<Value[]> result = read.lockingNodeUniqueIndexSeek( index, new int[]{0}, exact( propertyId, value ) );
long foundId = result.getOne();
Value[] propertyValues = result.getTwo();
commit();

// then
assertEquals( "Created node was not found", nodeId, foundId );
assertEquals( "Created node had wrong property value", value, propertyValues[0] );
assertEquals( "Created node had too many property values", 1, propertyValues.length);
}

@Test
public void shouldNotFindNonMatchingNode() throws Exception
{
Expand Down
Expand Up @@ -349,9 +349,9 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
if (queries.exists(q => q.value() == Values.NO_VALUE))
None
else {
val values = propertyIndicesWithValues.map(queries(_).value())
val index = transactionalContext.kernelTransaction.schemaRead().indexReferenceUnchecked(indexReference.schema())
val pair = reads().lockingNodeUniqueIndexSeek(index, propertyIndicesWithValues, queries: _*)
val (nodeId, values) = (pair.getOne, pair.getTwo())
val nodeId = reads().lockingNodeUniqueIndexSeek(index, queries: _*)
if (StatementConstants.NO_SUCH_NODE == nodeId) {
None
} else {
Expand Down
Expand Up @@ -19,10 +19,7 @@
*/
package org.neo4j.internal.kernel.api;

import org.eclipse.collections.api.tuple.primitive.LongObjectPair;

import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.values.storable.Value;

/**
* Defines the graph read operations of the Kernel.
Expand Down Expand Up @@ -58,24 +55,6 @@ void nodeIndexSeek( IndexReference index, NodeValueIndexCursor cursor, IndexOrde
long lockingNodeUniqueIndexSeek( IndexReference index, IndexQuery.ExactPredicate... predicates )
throws KernelException;

/**
* Returns node id of node found in unique index or -1 if no node was found. Also returns the properties
* of the node that the index provides, at the indices indicated by `propertyIndicesWithValues`.
*
* Note that this is a very special method and should be use with caution. It has special locking semantics in
* order to facilitate unique creation of nodes. If a node is found; a shared lock for the index entry will be
* held whereas if no node is found we will hold onto an exclusive lock until the close of the transaction.
*
* @param index {@link IndexReference} referencing index to query.
* {@link IndexReference referenced index}, or {@link IndexOrder#NONE}.
* @param propertyIndicesWithValues the indices of properties for which the index should retrieve values. This should be empty
* if the index cannot provide values, index 0 for a non-composite index, and more indices for a composite index.
* @param predicates Combination of {@link IndexQuery.ExactPredicate index queries} to run against referenced index.
*/
LongObjectPair<Value[]> lockingNodeUniqueIndexSeek( IndexReference index, int[] propertyIndicesWithValues,
IndexQuery.ExactPredicate... predicates )
throws KernelException;

/**
* Scan all values in an index.
*
Expand Down
Expand Up @@ -19,8 +19,6 @@
*/
package org.neo4j.internal.kernel.api.helpers;

import org.eclipse.collections.api.tuple.primitive.LongObjectPair;

import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.internal.kernel.api.IndexReference;
Expand All @@ -34,7 +32,6 @@
import org.neo4j.internal.kernel.api.RelationshipTraversalCursor;
import org.neo4j.internal.kernel.api.Scan;
import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.values.storable.Value;

public class StubRead implements Read
{
Expand All @@ -51,13 +48,6 @@ public long lockingNodeUniqueIndexSeek( IndexReference index,
throw new UnsupportedOperationException();
}

@Override
public LongObjectPair<Value[]> lockingNodeUniqueIndexSeek( IndexReference index, int[] propertyIndicesWithValues,
IndexQuery.ExactPredicate... predicates ) throws KernelException
{
throw new UnsupportedOperationException();
}

@Override
public void nodeIndexScan( IndexReference index, NodeValueIndexCursor cursor, IndexOrder indexOrder, boolean needsValues )
{
Expand Down
Expand Up @@ -19,9 +19,6 @@
*/
package org.neo4j.kernel.impl.newapi;

import org.eclipse.collections.api.tuple.primitive.LongObjectPair;
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples;

import java.util.Arrays;

import org.neo4j.internal.kernel.api.IndexOrder;
Expand Down Expand Up @@ -147,18 +144,8 @@ private IndexProgressor.NodeValueClient withFullValuePrecision( DefaultNodeValue
}

@Override
public final long lockingNodeUniqueIndexSeek(
IndexReference index,
IndexQuery.ExactPredicate... predicates )
public long lockingNodeUniqueIndexSeek( IndexReference index, IndexQuery.ExactPredicate... predicates )
throws IndexNotApplicableKernelException, IndexNotFoundKernelException, IndexBrokenKernelException
{
LongObjectPair<Value[]> pair = lockingNodeUniqueIndexSeek( index, new int[0], predicates );
return pair.getOne();
}

@Override
public LongObjectPair<Value[]> lockingNodeUniqueIndexSeek( IndexReference index, int[] propertyIndicesWithValues,
IndexQuery.ExactPredicate... predicates ) throws IndexNotApplicableKernelException, IndexNotFoundKernelException, IndexBrokenKernelException
{
assertIndexOnline( index );
assertPredicatesMatchSchema( index, predicates );
Expand Down Expand Up @@ -191,14 +178,7 @@ public LongObjectPair<Value[]> lockingNodeUniqueIndexSeek( IndexReference index,
}
}

Value[] values = new Value[propertyIndicesWithValues.length];
for ( int i = 0; i < propertyIndicesWithValues.length; i++ )
{
IndexQuery.ExactPredicate predicate = predicates[i];
values[i] = predicate.value();
}

return PrimitiveTuples.pair( cursor.nodeReference(), values );
return cursor.nodeReference();
}
}

Expand Down

0 comments on commit dea143e

Please sign in to comment.