Skip to content

Commit

Permalink
Merge pull request #10495 from pontusmelke/3.4-tx-awareness
Browse files Browse the repository at this point in the history
Reads tx aware and more writing
  • Loading branch information
fickludd committed Dec 4, 2017
2 parents e066959 + e1243a2 commit 4cae0cb
Show file tree
Hide file tree
Showing 119 changed files with 2,562 additions and 579 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import org.neo4j.internal.kernel.api.IndexQuery
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.{exceptions, _}
import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.values.storable.Values
Expand Down Expand Up @@ -300,7 +300,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
override def next(): Int = try {
inner.next()
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
case _: exceptions.EntityNotFoundException => null.asInstanceOf[Int]
}
}
} catch {
Expand All @@ -310,25 +310,25 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
def getProperty(id: Long, propertyKeyId: Int): Any = try {
tc.statement.readOperations().nodeGetProperty(id, propertyKeyId).asObject()
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
case _: exceptions.EntityNotFoundException => null.asInstanceOf[Int]
}

def hasProperty(id: Long, propertyKey: Int): Boolean = try {
tc.statement.readOperations().nodeHasProperty(id, propertyKey)
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => false
case _: exceptions.EntityNotFoundException => false
}

def removeProperty(id: Long, propertyKeyId: Int): Unit = try {
tc.statement.dataWriteOperations().nodeRemoveProperty(id, propertyKeyId)
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => //ignore
case _: exceptions.EntityNotFoundException => //ignore
}

def setProperty(id: Long, propertyKeyId: Int, value: Any): Unit = try {
tc.statement.dataWriteOperations().nodeSetProperty(id, propertyKeyId, Values.of(value))
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => //ignore
case _: exceptions.EntityNotFoundException => //ignore
}

override def getById(id: Long) = try {
Expand Down Expand Up @@ -370,7 +370,7 @@ final class TransactionBoundQueryContext(tc: TransactionalContextWrapper)
override def next(): Int = try {
inner.next()
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => null.asInstanceOf[Int]
case _: exceptions.EntityNotFoundException => null.asInstanceOf[Int]
}
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import java.util.function.Predicate
import org.neo4j.collection.RawIterator
import org.neo4j.collection.primitive.PrimitiveLongIterator
import org.neo4j.collection.primitive.base.Empty.EMPTY_PRIMITIVE_LONG_COLLECTION
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.compiler.v3_1.MinMaxOrdering.{BY_NUMBER, BY_STRING, BY_VALUE}
import org.neo4j.cypher.internal.compiler.v3_1._
import org.neo4j.cypher.internal.compiler.v3_1.ast.convert.commands.DirectionConverter.toGraphDb
Expand All @@ -39,7 +40,6 @@ import org.neo4j.cypher.internal.frontend.v3_1.{Bound, EntityNotFoundException,
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.runtime.interpreted.BeansAPIRelationshipIterator
import org.neo4j.cypher.internal.spi.v3_1.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.{InternalException, internal}
import org.neo4j.graphalgo.impl.path.ShortestPath
import org.neo4j.graphalgo.impl.path.ShortestPath.ShortestPathPredicate
import org.neo4j.graphdb.RelationshipType._
Expand All @@ -48,15 +48,15 @@ import org.neo4j.graphdb.security.URLAccessValidationError
import org.neo4j.graphdb.traversal.{Evaluators, TraversalDescription, Uniqueness}
import org.neo4j.internal.kernel.api.IndexQuery
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api._
import org.neo4j.kernel.api.dbms.DbmsOperations
import org.neo4j.kernel.api.exceptions.ProcedureException
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.{QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.{exceptions, _}
import org.neo4j.kernel.impl.core.NodeManager
import org.neo4j.kernel.impl.locking.ResourceTypes
import org.neo4j.values.storable.Values
Expand Down Expand Up @@ -111,7 +111,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
override def getLabelsForNode(node: Long) = try {
JavaConversionSupport.asScala(txContext.statement.readOperations().nodeGetLabels(node))
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: exceptions.EntityNotFoundException =>
if (nodeOps.isDeletedInThisTx(node))
throw new EntityNotFoundException(s"Node with id $node has been deleted in this transaction", e)
else
Expand Down Expand Up @@ -307,7 +307,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
override def getProperty(id: Long, propertyKeyId: Int): Any = try {
txContext.statement.readOperations().nodeGetProperty(id, propertyKeyId).asObject()
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id))
throw new EntityNotFoundException(s"Node with id $id has been deleted in this transaction", e)
else
Expand Down Expand Up @@ -382,7 +382,7 @@ final class TransactionBoundQueryContext(txContext: TransactionalContextWrapper)
override def getProperty(id: Long, propertyKeyId: Int): Any = try {
txContext.statement.readOperations().relationshipGetProperty(id, propertyKeyId).asObject()
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id))
throw new EntityNotFoundException(s"Relationship with id $id has been deleted in this transaction", e)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.neo4j.cypher.internal.runtime.interpreted

import org.neo4j.collection.primitive.{PrimitiveIntIterator, PrimitiveLongIterator}
import org.neo4j.cypher.internal.util.v3_4.EntityNotFoundException
import org.neo4j.kernel.api

object JavaConversionSupport {

Expand All @@ -44,7 +45,7 @@ object JavaConversionSupport {
try {
_next = Some(f(more()))
} catch {
case _: org.neo4j.kernel.api.exceptions.EntityNotFoundException => // IGNORE
case _: api.exceptions.EntityNotFoundException => // IGNORE
case _: EntityNotFoundException => // IGNORE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ import org.neo4j.graphdb.security.URLAccessValidationError
import org.neo4j.graphdb.traversal.{Evaluators, TraversalDescription, Uniqueness}
import org.neo4j.internal.kernel.api.IndexQuery
import org.neo4j.kernel.GraphDatabaseQueryService
import org.neo4j.kernel.api._
import org.neo4j.kernel.api.exceptions.ProcedureException
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.index.InternalIndexState
import org.neo4j.kernel.api.proc.CallableUserAggregationFunction.Aggregator
import org.neo4j.kernel.api.proc.{QualifiedName => KernelQualifiedName}
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.api.{exceptions, _}
import org.neo4j.kernel.guard.TerminationGuard
import org.neo4j.kernel.impl.api.RelationshipVisitor
import org.neo4j.kernel.impl.api.store.RelationshipIterator
Expand Down Expand Up @@ -134,7 +134,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
override def getLabelsForNode(node: Long) = try {
JavaConversionSupport.asScala(transactionalContext.statement.readOperations().nodeGetLabels(node))
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: exceptions.EntityNotFoundException =>
if (nodeOps.isDeletedInThisTx(node))
throw new EntityNotFoundException(s"Node with id $node has been deleted in this transaction", e)
else
Expand Down Expand Up @@ -391,7 +391,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
override def getProperty(id: Long, propertyKeyId: Int): Value = try {
transactionalContext.statement.readOperations().nodeGetProperty(id, propertyKeyId)
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id))
throw new EntityNotFoundException(s"Node with id $id has been deleted in this transaction", e)
else
Expand Down Expand Up @@ -481,7 +481,7 @@ final class TransactionBoundQueryContext(val transactionalContext: Transactional
override def getProperty(id: Long, propertyKeyId: Int): Value = try {
transactionalContext.statement.readOperations().relationshipGetProperty(id, propertyKeyId)
} catch {
case e: org.neo4j.kernel.api.exceptions.EntityNotFoundException =>
case e: exceptions.EntityNotFoundException =>
if (isDeletedInThisTx(id))
throw new EntityNotFoundException(s"Relationship with id $id has been deleted in this transaction", e)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,131 @@
import java.util.Map;

import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.explicitindex.ExplicitIndexNotFoundKernelException;

/**
* Operations for creating and modifying explicit indexes.
*/
public interface ExplicitIndexWrite
{
/**
* Adds node to explicit index.
*
* @param indexName The name of the index
* @param node The id of the node to add
* @param key The key to associate with the node
* @param value The value to associate with the node an key
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void nodeAddToExplicitIndex( String indexName, long node, String key, Object value )
throws KernelException;

/**
* Removes a node from an explicit index
*
* @param indexName The name of the index
* @param node The id of the node to remove
* @param key The key associated with the node
* @param value The value associated with the node and key
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void nodeRemoveFromExplicitIndex( String indexName, long node, String key, Object value )
throws ExplicitIndexNotFoundKernelException;

/**
* Removes a node from an explicit index
*
* @param indexName The name of the index
* @param node The id of the node to remove
* @param key The key associated with the node
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void nodeRemoveFromExplicitIndex( String indexName, long node, String key ) throws
ExplicitIndexNotFoundKernelException;

/**
* Removes a given node from an explicit index
*
* @param indexName The name of the index from which the node is to be removed.
* @param node The node id of the node to remove
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void nodeRemoveFromExplicitIndex( String indexName, long node ) throws ExplicitIndexNotFoundKernelException;

/**
* Adds relationship to explicit index.
*
* @param indexName The name of the index
* @param relationship The id of the relationship to add
* @param key The key to associate with the relationship
* @param value The value to associate with the relationship and key
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void relationshipAddToExplicitIndex( String indexName, long relationship, String key, Object value )
throws KernelException;

/**
* Removes relationship from explicit index.
*
* @param indexName The name of the index
* @param relationship The id of the relationship to remove
* @param key The key associated with the relationship
* @param value The value associated with the relationship and key
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void relationshipRemoveFromExplicitIndex( String indexName, long relationship, String key, Object value )
throws KernelException;

/**
* Removes relationship to explicit index.
*
* @param indexName The name of the index
* @param relationship The id of the relationship to remove
* @param key The key associated with the relationship
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void nodeRemoveFromExplicitIndex( String indexName, long node ) throws KernelException;
void relationshipRemoveFromExplicitIndex( String indexName, long relationship, String key )
throws KernelException;

/**
* Removes relationship to explicit index.
*
* @param indexName The name of the index
* @param relationship The id of the relationship to remove
* @throws ExplicitIndexNotFoundKernelException If there is no explicit index with the given name
*/
void relationshipRemoveFromExplicitIndex( String indexName, long relationship )
throws KernelException;

/**
* Creates an explicit index in a separate transaction if not yet available.
*
* @param indexName The name of the index to create.
* @param customConfig The configuration of the explicit index.
*/
void nodeExplicitIndexCreateLazily( String indexName, Map<String,String> customConfig );

/**
* Creates an explicit index.
*
* @param indexName The name of the index to create.
* @param customConfig The configuration of the explicit index.
*/
void nodeExplicitIndexCreate( String indexName, Map<String,String> customConfig );

/**
* Creates an explicit index in a separate transaction if not yet available.
*
* @param indexName The name of the index to create.
* @param customConfig The configuration of the explicit index.
*/
void relationshipExplicitIndexCreateLazily( String indexName, Map<String,String> customConfig );

/**
* Creates an explicit index.
*
* @param indexName The name of the index to create.
* @param customConfig The configuration of the explicit index.
*/
void nodeExplicitIndexCreateLazily( String indexName, Map<String, String> customConfig );
void relationshipExplicitIndexCreate( String indexName, Map<String,String> customConfig );
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,6 @@
*/
public interface PropertyCursor extends Cursor
{
/**
* Find the first property with a key greater than or equal to the provided key.
* <p>
* Note that the default implementation of this method (and most likely any sane use of this method - regardless of
* implementation) assumes that properties are ordered by the key.
*
* @param propertyKey
* the property key to search for.
* @return {@code true} if a matching property was found, {@code false} if all properties within reach of this
* cursor were exhausted without finding a matching property.
*/
default boolean seek( int propertyKey )
{
while ( next() )
{
if ( propertyKey < propertyKey() )
{
return true;
}
}
return false;
}

int propertyKey();

ValueGroup propertyType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.internal.kernel.api;

import org.neo4j.internal.kernel.api.exceptions.KernelException;
import org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException;

/**
* Token creation and lookup.
Expand Down Expand Up @@ -74,4 +75,13 @@ public interface Token
* @return the property key id, or NO_TOKEN
*/
int propertyKey( String name );

/**
* Returns the name of a property given its property key id
*
* @param propertyKeyId The id of the property
* @return The name of the key
* @throws PropertyKeyIdNotFoundKernelException if no key is associated with the id
*/
String propertyKeyGetName( int propertyKeyId ) throws PropertyKeyIdNotFoundKernelException;
}

0 comments on commit 4cae0cb

Please sign in to comment.