Skip to content

Commit

Permalink
Remove Guard abstraction. Use plain assertOpen transaction check inst…
Browse files Browse the repository at this point in the history
…ead.

Remove Guard abstraction that was a leftover from previous pattern when it
was a Guard that was used to mark transaction as terminated.
  • Loading branch information
MishaDemianenko committed May 22, 2018
1 parent 0544a33 commit bfef3cf
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 284 deletions.
Expand Up @@ -24,16 +24,12 @@ import java.util.function.Predicate


import org.eclipse.collections.api.iterator.LongIterator import org.eclipse.collections.api.iterator.LongIterator
import org.neo4j.collection.{PrimitiveLongResourceIterator, RawIterator} import org.neo4j.collection.{PrimitiveLongResourceIterator, RawIterator}
import org.neo4j.cypher.InternalException
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.planner.v3_5.spi.{IdempotentResult, IndexDescriptor} import org.neo4j.cypher.internal.planner.v3_5.spi.{IdempotentResult, IndexDescriptor}
import org.neo4j.cypher.internal.runtime._ import org.neo4j.cypher.internal.runtime._
import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor
import org.neo4j.cypher.internal.runtime.interpreted.commands.convert.DirectionConverter.toGraphDb import org.neo4j.cypher.internal.runtime.interpreted.commands.convert.DirectionConverter.toGraphDb
import org.neo4j.cypher.internal.runtime.interpreted.commands.expressions.{OnlyDirectionExpander, TypeAndDirectionExpander} import org.neo4j.cypher.internal.runtime.interpreted.commands.expressions.{OnlyDirectionExpander, TypeAndDirectionExpander}
import org.opencypher.v9_0.util.{EntityNotFoundException, FailedIndexException}
import org.opencypher.v9_0.expressions.SemanticDirection
import org.opencypher.v9_0.expressions.SemanticDirection.{BOTH, INCOMING, OUTGOING}
import org.neo4j.cypher.internal.v3_5.logical.plans._ import org.neo4j.cypher.internal.v3_5.logical.plans._
import org.neo4j.graphalgo.impl.path.ShortestPath import org.neo4j.graphalgo.impl.path.ShortestPath
import org.neo4j.graphalgo.impl.path.ShortestPath.ShortestPathPredicate import org.neo4j.graphalgo.impl.path.ShortestPath.ShortestPathPredicate
Expand All @@ -51,9 +47,8 @@ import org.neo4j.kernel.api._
import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException} import org.neo4j.kernel.api.exceptions.schema.{AlreadyConstrainedException, AlreadyIndexedException}
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory import org.neo4j.kernel.api.schema.SchemaDescriptorFactory
import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory import org.neo4j.kernel.api.schema.constaints.ConstraintDescriptorFactory
import org.neo4j.kernel.guard.TerminationGuard
import org.neo4j.kernel.impl.api.RelationshipVisitor import org.neo4j.kernel.impl.api.RelationshipVisitor
import org.neo4j.kernel.impl.api.store.{RelationshipIterator} import org.neo4j.kernel.impl.api.store.RelationshipIterator
import org.neo4j.kernel.impl.core.{EmbeddedProxySPI, ThreadToStatementContextBridge} import org.neo4j.kernel.impl.core.{EmbeddedProxySPI, ThreadToStatementContextBridge}
import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker
import org.neo4j.kernel.impl.query.Neo4jTransactionalContext import org.neo4j.kernel.impl.query.Neo4jTransactionalContext
Expand All @@ -62,6 +57,9 @@ import org.neo4j.kernel.impl.util.ValueUtils.{fromNodeProxy, fromRelationshipPro
import org.neo4j.values.storable.{TextValue, Value, Values, _} import org.neo4j.values.storable.{TextValue, Value, Values, _}
import org.neo4j.values.virtual.{ListValue, NodeValue, RelationshipValue, VirtualValues} import org.neo4j.values.virtual.{ListValue, NodeValue, RelationshipValue, VirtualValues}
import org.neo4j.values.{AnyValue, ValueMapper} import org.neo4j.values.{AnyValue, ValueMapper}
import org.opencypher.v9_0.expressions.SemanticDirection
import org.opencypher.v9_0.expressions.SemanticDirection.{BOTH, INCOMING, OUTGOING}
import org.opencypher.v9_0.util.{EntityNotFoundException, FailedIndexException}


import scala.collection.Iterator import scala.collection.Iterator
import scala.collection.JavaConverters._ import scala.collection.JavaConverters._
Expand All @@ -88,13 +86,12 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
getDependencyResolver. getDependencyResolver.
provideDependency(classOf[ThreadToStatementContextBridge]). provideDependency(classOf[ThreadToStatementContextBridge]).
get get
val guard = new TerminationGuard
val locker = new PropertyContainerLocker val locker = new PropertyContainerLocker
val query = transactionalContext.tc.executingQuery() val query = transactionalContext.tc.executingQuery()


val context = transactionalContext.tc.asInstanceOf[Neo4jTransactionalContext] val context = transactionalContext.tc.asInstanceOf[Neo4jTransactionalContext]
val newTx = transactionalContext.graph.beginTransaction(context.transactionType, context.securityContext) val newTx = transactionalContext.graph.beginTransaction(context.transactionType, context.securityContext)
val neo4jTransactionalContext = context.copyFrom(context.graph, guard, statementProvider, locker, newTx, val neo4jTransactionalContext = context.copyFrom(context.graph, statementProvider, locker, newTx,
statementProvider.get(), query) statementProvider.get(), query)
new TransactionBoundQueryContext(TransactionalContextWrapper(neo4jTransactionalContext)) new TransactionBoundQueryContext(TransactionalContextWrapper(neo4jTransactionalContext))
} }
Expand Down
Expand Up @@ -27,8 +27,6 @@ import org.mockito.Mockito._
import org.neo4j.cypher.internal.javacompat import org.neo4j.cypher.internal.javacompat
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor import org.neo4j.cypher.internal.runtime.interpreted.TransactionBoundQueryContext.IndexSearchMonitor
import org.opencypher.v9_0.util.test_helpers.CypherFunSuite
import org.opencypher.v9_0.expressions.SemanticDirection
import org.neo4j.graphdb._ import org.neo4j.graphdb._
import org.neo4j.graphdb.config.Setting import org.neo4j.graphdb.config.Setting
import org.neo4j.graphdb.factory.GraphDatabaseSettings import org.neo4j.graphdb.factory.GraphDatabaseSettings
Expand All @@ -50,6 +48,8 @@ import org.neo4j.kernel.impl.query.{Neo4jTransactionalContext, Neo4jTransactiona
import org.neo4j.storageengine.api.StorageReader import org.neo4j.storageengine.api.StorageReader
import org.neo4j.test.TestGraphDatabaseFactory import org.neo4j.test.TestGraphDatabaseFactory
import org.neo4j.values.virtual.VirtualValues.EMPTY_MAP import org.neo4j.values.virtual.VirtualValues.EMPTY_MAP
import org.opencypher.v9_0.expressions.SemanticDirection
import org.opencypher.v9_0.util.test_helpers.CypherFunSuite


import scala.collection.JavaConverters._ import scala.collection.JavaConverters._


Expand Down Expand Up @@ -91,7 +91,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {
val transaction = mock[KernelTransaction] val transaction = mock[KernelTransaction]
when(transaction.cursors()).thenReturn(new DefaultCursors()) when(transaction.cursors()).thenReturn(new DefaultCursors())
when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction) when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction)
val tc = new Neo4jTransactionalContext(graph, null, bridge, locker, outerTx, statement,null, null) val tc = new Neo4jTransactionalContext(graph, bridge, locker, outerTx, statement,null, null)
val transactionalContext = TransactionalContextWrapper(tc) val transactionalContext = TransactionalContextWrapper(tc)
val context = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor) val context = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor)
// WHEN // WHEN
Expand All @@ -115,7 +115,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {
when(transaction.acquireStatement()).thenReturn(statement) when(transaction.acquireStatement()).thenReturn(statement)
when(transaction.cursors()).thenReturn(new DefaultCursors()) when(transaction.cursors()).thenReturn(new DefaultCursors())
when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction) when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction)
val tc = new Neo4jTransactionalContext(graph, null, bridge, locker, outerTx, statement,null, null) val tc = new Neo4jTransactionalContext(graph, bridge, locker, outerTx, statement,null, null)
val transactionalContext = TransactionalContextWrapper(tc) val transactionalContext = TransactionalContextWrapper(tc)
val context = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor) val context = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor)
// WHEN // WHEN
Expand Down Expand Up @@ -218,7 +218,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {
when(transaction.acquireStatement()).thenReturn(statement) when(transaction.acquireStatement()).thenReturn(statement)
when(transaction.cursors()).thenReturn(new DefaultCursors()) when(transaction.cursors()).thenReturn(new DefaultCursors())
when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction) when(bridge.getKernelTransactionBoundToThisThread(true)).thenReturn(transaction)
val tc = new Neo4jTransactionalContext(graph, null, bridge, locker, outerTx, statement, null, null) val tc = new Neo4jTransactionalContext(graph, bridge, locker, outerTx, statement, null, null)
val transactionalContext = TransactionalContextWrapper(tc) val transactionalContext = TransactionalContextWrapper(tc)
val context = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor) val context = new TransactionBoundQueryContext(transactionalContext)(indexSearchMonitor)
val resource1 = mock[AutoCloseable] val resource1 = mock[AutoCloseable]
Expand Down
32 changes: 0 additions & 32 deletions community/kernel/src/main/java/org/neo4j/kernel/guard/Guard.java

This file was deleted.

This file was deleted.

Expand Up @@ -40,8 +40,6 @@
import org.neo4j.kernel.api.explicitindex.AutoIndexing; import org.neo4j.kernel.api.explicitindex.AutoIndexing;
import org.neo4j.kernel.builtinprocs.SpecialBuiltInProcedures; import org.neo4j.kernel.builtinprocs.SpecialBuiltInProcedures;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.guard.Guard;
import org.neo4j.kernel.guard.TerminationGuard;
import org.neo4j.kernel.impl.api.NonTransactionalTokenNameLookup; import org.neo4j.kernel.impl.api.NonTransactionalTokenNameLookup;
import org.neo4j.kernel.impl.api.SchemaWriteGuard; import org.neo4j.kernel.impl.api.SchemaWriteGuard;
import org.neo4j.kernel.impl.api.dbms.NonTransactionalDbmsOperations; import org.neo4j.kernel.impl.api.dbms.NonTransactionalDbmsOperations;
Expand Down Expand Up @@ -103,8 +101,6 @@ public class DataSourceModule


public final AutoIndexing autoIndexing; public final AutoIndexing autoIndexing;


public final Guard guard;

public DataSourceModule( final PlatformModule platformModule, EditionModule editionModule, public DataSourceModule( final PlatformModule platformModule, EditionModule editionModule,
Supplier<QueryExecutionEngine> queryExecutionEngineSupplier ) Supplier<QueryExecutionEngine> queryExecutionEngineSupplier )
{ {
Expand Down Expand Up @@ -136,8 +132,6 @@ public DataSourceModule( final PlatformModule platformModule, EditionModule edit


SchemaWriteGuard schemaWriteGuard = deps.satisfyDependency( editionModule.schemaWriteGuard ); SchemaWriteGuard schemaWriteGuard = deps.satisfyDependency( editionModule.schemaWriteGuard );


guard = createGuard( deps );

DatabasePanicEventGenerator databasePanicEventGenerator = deps.satisfyDependency( DatabasePanicEventGenerator databasePanicEventGenerator = deps.satisfyDependency(
new DatabasePanicEventGenerator( platformModule.eventHandlers ) ); new DatabasePanicEventGenerator( platformModule.eventHandlers ) );


Expand Down Expand Up @@ -206,18 +200,6 @@ public DataSourceModule( final PlatformModule platformModule, EditionModule edit
procedures.registerComponent( GraphDatabaseService.class, gdsFactory::apply, true ); procedures.registerComponent( GraphDatabaseService.class, gdsFactory::apply, true );
} }


private Guard createGuard( Dependencies deps )
{
TerminationGuard guard = createGuard();
deps.satisfyDependency( guard );
return guard;
}

protected TerminationGuard createGuard()
{
return new TerminationGuard();
}

private Procedures setupProcedures( PlatformModule platform, EditionModule editionModule ) private Procedures setupProcedures( PlatformModule platform, EditionModule editionModule )
{ {
File pluginDir = platform.config.get( GraphDatabaseSettings.plugin_dir ); File pluginDir = platform.config.get( GraphDatabaseSettings.plugin_dir );
Expand All @@ -242,9 +224,8 @@ private Procedures setupProcedures( PlatformModule platform, EditionModule editi
Log proceduresLog = platform.logging.getUserLog( Procedures.class ); Log proceduresLog = platform.logging.getUserLog( Procedures.class );
procedures.registerComponent( Log.class, ctx -> proceduresLog, true ); procedures.registerComponent( Log.class, ctx -> proceduresLog, true );


Guard guard = platform.dependencies.resolveDependency( Guard.class );
procedures.registerComponent( ProcedureTransaction.class, new ProcedureTransactionProvider(), true ); procedures.registerComponent( ProcedureTransaction.class, new ProcedureTransactionProvider(), true );
procedures.registerComponent( org.neo4j.procedure.TerminationGuard.class, new TerminationGuardProvider( guard ), true ); procedures.registerComponent( org.neo4j.procedure.TerminationGuard.class, new TerminationGuardProvider(), true );


// Below components are not public API, but are made available for internal // Below components are not public API, but are made available for internal
// procedures to call, and to provide temporary workarounds for the following // procedures to call, and to provide temporary workarounds for the following
Expand Down
Expand Up @@ -82,7 +82,6 @@
import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.explicitindex.AutoIndexing; import org.neo4j.kernel.api.explicitindex.AutoIndexing;
import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.guard.Guard;
import org.neo4j.kernel.impl.api.TokenAccess; import org.neo4j.kernel.impl.api.TokenAccess;
import org.neo4j.kernel.impl.core.EmbeddedProxySPI; import org.neo4j.kernel.impl.core.EmbeddedProxySPI;
import org.neo4j.kernel.impl.core.GraphPropertiesProxy; import org.neo4j.kernel.impl.core.GraphPropertiesProxy;
Expand Down Expand Up @@ -200,7 +199,7 @@ public GraphDatabaseFacade()
/** /**
* Create a new Core API facade, backed by the given SPI and using pre-resolved dependencies * Create a new Core API facade, backed by the given SPI and using pre-resolved dependencies
*/ */
public void init( EditionModule editionModule, SPI spi, Guard guard, ThreadToStatementContextBridge txBridge, Config config, public void init( EditionModule editionModule, SPI spi, ThreadToStatementContextBridge txBridge, Config config,
RelationshipTypeTokenHolder relationshipTypeTokenHolder ) RelationshipTypeTokenHolder relationshipTypeTokenHolder )
{ {
this.editionModule = editionModule; this.editionModule = editionModule;
Expand All @@ -224,7 +223,7 @@ public void init( EditionModule editionModule, SPI spi, Guard guard, ThreadToSta
nodeAutoIndexer, relAutoIndexer ); nodeAutoIndexer, relAutoIndexer );
} ); } );


this.contextFactory = Neo4jTransactionalContextFactory.create( spi, guard, txBridge, locker ); this.contextFactory = Neo4jTransactionalContextFactory.create( spi, txBridge, locker );
} }


@Override @Override
Expand Down
Expand Up @@ -180,7 +180,6 @@ public GraphDatabaseFacade initFacade( File storeDir, Config config, final Depen
graphDatabaseFacade.init( graphDatabaseFacade.init(
edition, edition,
spi, spi,
dataSource.guard,
dataSource.threadToTransactionBridge, dataSource.threadToTransactionBridge,
platform.config, platform.config,
edition.relationshipTypeTokenHolder edition.relationshipTypeTokenHolder
Expand Down
Expand Up @@ -82,7 +82,6 @@ public GraphDatabaseService apply( Context context ) throws ProcedureException
urlValidator, urlValidator,
securityContext securityContext
), ),
dataSource.guard,
dataSource.threadToTransactionBridge, dataSource.threadToTransactionBridge,
platform.config, platform.config,
relationshipTypeTokenHolder relationshipTypeTokenHolder
Expand Down
Expand Up @@ -22,20 +22,12 @@
import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.proc.Context; import org.neo4j.kernel.api.proc.Context;
import org.neo4j.kernel.guard.Guard;
import org.neo4j.procedure.TerminationGuard; import org.neo4j.procedure.TerminationGuard;


import static org.neo4j.kernel.api.proc.Context.KERNEL_TRANSACTION; import static org.neo4j.kernel.api.proc.Context.KERNEL_TRANSACTION;


public class TerminationGuardProvider implements ComponentRegistry.Provider<TerminationGuard> public class TerminationGuardProvider implements ComponentRegistry.Provider<TerminationGuard>
{ {
private final Guard guard;

public TerminationGuardProvider( Guard guard )
{
this.guard = guard;
}

@Override @Override
public TerminationGuard apply( Context ctx ) throws ProcedureException public TerminationGuard apply( Context ctx ) throws ProcedureException
{ {
Expand All @@ -55,7 +47,7 @@ private class TransactionTerminationGuard implements TerminationGuard
@Override @Override
public void check() public void check()
{ {
guard.check( ktx ); ktx.assertOpen();
} }
} }
} }
Expand Up @@ -33,7 +33,6 @@
import org.neo4j.kernel.api.dbms.DbmsOperations; import org.neo4j.kernel.api.dbms.DbmsOperations;
import org.neo4j.kernel.api.query.ExecutingQuery; import org.neo4j.kernel.api.query.ExecutingQuery;
import org.neo4j.kernel.api.txstate.TxStateHolder; import org.neo4j.kernel.api.txstate.TxStateHolder;
import org.neo4j.kernel.guard.Guard;
import org.neo4j.kernel.impl.api.KernelTransactionImplementation; import org.neo4j.kernel.impl.api.KernelTransactionImplementation;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.coreapi.InternalTransaction; import org.neo4j.kernel.impl.coreapi.InternalTransaction;
Expand All @@ -43,7 +42,6 @@
public class Neo4jTransactionalContext implements TransactionalContext public class Neo4jTransactionalContext implements TransactionalContext
{ {
private final GraphDatabaseQueryService graph; private final GraphDatabaseQueryService graph;
private final Guard guard;
private final ThreadToStatementContextBridge txBridge; private final ThreadToStatementContextBridge txBridge;
private final PropertyContainerLocker locker; private final PropertyContainerLocker locker;


Expand All @@ -66,17 +64,15 @@ public class Neo4jTransactionalContext implements TransactionalContext


public Neo4jTransactionalContext( public Neo4jTransactionalContext(
GraphDatabaseQueryService graph, GraphDatabaseQueryService graph,
Guard guard,
ThreadToStatementContextBridge txBridge, ThreadToStatementContextBridge txBridge,
PropertyContainerLocker locker, PropertyContainerLocker locker,
InternalTransaction initialTransaction, InternalTransaction initialTransaction,
Statement intitialStatement, Statement initialStatement,
ExecutingQuery executingQuery, ExecutingQuery executingQuery,
Kernel kernel Kernel kernel
) )
{ {
this.graph = graph; this.graph = graph;
this.guard = guard;
this.txBridge = txBridge; this.txBridge = txBridge;
this.locker = locker; this.locker = locker;
this.transactionType = initialTransaction.transactionType(); this.transactionType = initialTransaction.transactionType();
Expand All @@ -85,7 +81,7 @@ public Neo4jTransactionalContext(


this.transaction = initialTransaction; this.transaction = initialTransaction;
this.kernelTransaction = txBridge.getKernelTransactionBoundToThisThread( true ); this.kernelTransaction = txBridge.getKernelTransactionBoundToThisThread( true );
this.statement = intitialStatement; this.statement = initialStatement;
this.kernel = kernel; this.kernel = kernel;
} }


Expand Down Expand Up @@ -243,13 +239,6 @@ public TransactionalContext getOrBeginNewIfClosed()
return this; return this;
} }


public TransactionalContext beginInNewThread()
{
InternalTransaction newTx = graph.beginTransaction( transactionType, securityContext );
return new Neo4jTransactionalContext( graph, guard, txBridge, locker, newTx, txBridge.get(),
executingQuery, kernel );
}

private void checkNotTerminated() private void checkNotTerminated()
{ {
InternalTransaction currentTransaction = transaction; InternalTransaction currentTransaction = transaction;
Expand Down Expand Up @@ -283,7 +272,7 @@ public Statement statement()
@Override @Override
public void check() public void check()
{ {
guard.check( kernelTransaction() ); kernelTransaction().assertOpen();
} }


@Override @Override
Expand Down Expand Up @@ -332,13 +321,12 @@ private void collectTransactionExecutionStatistic()
} }


public Neo4jTransactionalContext copyFrom( GraphDatabaseQueryService graph, public Neo4jTransactionalContext copyFrom( GraphDatabaseQueryService graph,
Guard guard,
ThreadToStatementContextBridge txBridge, PropertyContainerLocker locker, ThreadToStatementContextBridge txBridge, PropertyContainerLocker locker,
InternalTransaction initialTransaction, InternalTransaction initialTransaction,
Statement initialStatement, Statement initialStatement,
ExecutingQuery executingQuery ) ExecutingQuery executingQuery )
{ {
return new Neo4jTransactionalContext( graph, guard, txBridge, locker, initialTransaction, return new Neo4jTransactionalContext( graph, txBridge, locker, initialTransaction,
initialStatement, executingQuery, kernel ); initialStatement, executingQuery, kernel );
} }


Expand Down

0 comments on commit bfef3cf

Please sign in to comment.