Skip to content

Commit

Permalink
Remove most usages of InwardKernel
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd authored and SaschaPeukert committed Apr 6, 2018
1 parent 8a96ad5 commit 6516dc6
Show file tree
Hide file tree
Showing 47 changed files with 481 additions and 462 deletions.
Expand Up @@ -19,7 +19,7 @@
*/ */
package org.neo4j.internal.kernel.api; package org.neo4j.internal.kernel.api;


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


/** /**
* A Session is used to gain * A Session is used to gain
Expand All @@ -31,15 +31,15 @@ public interface Session extends AutoCloseable
* *
* @return The new transaction * @return The new transaction
*/ */
Transaction beginTransaction() throws KernelException; Transaction beginTransaction() throws TransactionFailureException;


/** /**
* Begin new transaction. * Begin new transaction.
* *
* @param type The type of transaction * @param type The type of transaction
* @return The new transaction * @return The new transaction
*/ */
Transaction beginTransaction( Transaction.Type type ) throws KernelException; Transaction beginTransaction( Transaction.Type type ) throws TransactionFailureException;


@Override @Override
void close(); void close();
Expand Down
Expand Up @@ -19,7 +19,11 @@
*/ */
package org.neo4j.internal.kernel.api; package org.neo4j.internal.kernel.api;


import java.util.Optional;

import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException; import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.api.exceptions.Status;


/** /**
* A transaction with the graph database. * A transaction with the graph database.
Expand Down Expand Up @@ -132,4 +136,47 @@ enum Type
* @return statistics about the execution * @return statistics about the execution
*/ */
ExecutionStatistics executionStatistics(); ExecutionStatistics executionStatistics();

/**
* Closes this transaction, committing its changes if {@link #success()} has been called and neither
* {@link #failure()} nor {@link #markForTermination(Status)} has been called.
* Otherwise its changes will be rolled back.
*
* @return id of the committed transaction or {@link #ROLLBACK} if transaction was rolled back or
* {@link #READ_ONLY} if transaction was read-only.
*/
long closeTransaction() throws TransactionFailureException;

/**
* Closes this transaction, committing its changes if {@link #success()} has been called and neither
* {@link #failure()} nor {@link #markForTermination(Status)} has been called.
* Otherwise its changes will be rolled back.
*/
@Override
default void close() throws TransactionFailureException
{
closeTransaction();
}

/**
* @return {@code true} if the transaction is still open, i.e. if {@link #close()} hasn't been called yet.
*/
boolean isOpen();

/**
* @return {@link Status} if {@link #markForTermination(Status)} has been invoked, otherwise empty optional.
*/
Optional<Status> getReasonIfTerminated();

/**
* @return true if transaction was terminated, otherwise false
*/
boolean isTerminated();

/**
* Marks this transaction for termination, such that it cannot commit successfully and will try to be
* terminated by having other methods throw a specific termination exception, as to sooner reach the assumed
* point where {@link #close()} will be invoked.
*/
void markForTermination( Status reason );
} }
Expand Up @@ -34,6 +34,7 @@
import org.neo4j.graphdb.ResourceIterator; import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector; import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector;
import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.TokenNameLookup; import org.neo4j.internal.kernel.api.TokenNameLookup;
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.IOLimiter; import org.neo4j.io.pagecache.IOLimiter;
Expand All @@ -51,7 +52,7 @@
import org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations; import org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementOperations;
import org.neo4j.kernel.impl.api.DatabaseSchemaState; import org.neo4j.kernel.impl.api.DatabaseSchemaState;
import org.neo4j.kernel.impl.api.ExplicitIndexProviderLookup; import org.neo4j.kernel.impl.api.ExplicitIndexProviderLookup;
import org.neo4j.kernel.impl.api.Kernel; import org.neo4j.kernel.impl.api.KernelImpl;
import org.neo4j.kernel.impl.api.KernelTransactionMonitorScheduler; import org.neo4j.kernel.impl.api.KernelTransactionMonitorScheduler;
import org.neo4j.kernel.impl.api.KernelTransactionTimeoutMonitor; import org.neo4j.kernel.impl.api.KernelTransactionTimeoutMonitor;
import org.neo4j.kernel.impl.api.KernelTransactions; import org.neo4j.kernel.impl.api.KernelTransactions;
Expand Down Expand Up @@ -670,7 +671,7 @@ private NeoStoreKernelModule buildKernel( LogFiles logFiles, TransactionAppender
* This is used by explicit indexes and constraint indexes whenever a transaction is to be spawned * This is used by explicit indexes and constraint indexes whenever a transaction is to be spawned
* from within an existing transaction. It smells, and we should look over alternatives when time permits. * from within an existing transaction. It smells, and we should look over alternatives when time permits.
*/ */
Supplier<InwardKernel> kernelProvider = () -> kernelModule.kernelAPI(); Supplier<Kernel> kernelProvider = () -> kernelModule.kernelAPI();


ConstraintIndexCreator constraintIndexCreator = new ConstraintIndexCreator( kernelProvider, indexingService, ConstraintIndexCreator constraintIndexCreator = new ConstraintIndexCreator( kernelProvider, indexingService,
propertyAccessor ); propertyAccessor );
Expand All @@ -695,7 +696,7 @@ private NeoStoreKernelModule buildKernel( LogFiles logFiles, TransactionAppender


buildTransactionMonitor( kernelTransactions, clock, config ); buildTransactionMonitor( kernelTransactions, clock, config );


final Kernel kernel = new Kernel( kernelTransactions, hooks, databaseHealth, transactionMonitor, procedures, final KernelImpl kernel = new KernelImpl( kernelTransactions, hooks, databaseHealth, transactionMonitor, procedures,
config, storageEngine ); config, storageEngine );


kernel.registerTransactionHook( transactionEventHandlers ); kernel.registerTransactionHook( transactionEventHandlers );
Expand Down
Expand Up @@ -19,8 +19,7 @@
*/ */
package org.neo4j.kernel; package org.neo4j.kernel;


import org.neo4j.kernel.api.InwardKernel; import org.neo4j.kernel.impl.api.KernelImpl;
import org.neo4j.kernel.impl.api.Kernel;
import org.neo4j.kernel.impl.api.KernelTransactions; import org.neo4j.kernel.impl.api.KernelTransactions;
import org.neo4j.kernel.impl.api.TransactionCommitProcess; import org.neo4j.kernel.impl.api.TransactionCommitProcess;
import org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing; import org.neo4j.kernel.impl.transaction.state.NeoStoreFileListing;
Expand All @@ -29,11 +28,11 @@
class NeoStoreKernelModule class NeoStoreKernelModule
{ {
private final TransactionCommitProcess transactionCommitProcess; private final TransactionCommitProcess transactionCommitProcess;
private final Kernel kernel; private final KernelImpl kernel;
private final KernelTransactions kernelTransactions; private final KernelTransactions kernelTransactions;
private final NeoStoreFileListing fileListing; private final NeoStoreFileListing fileListing;


NeoStoreKernelModule( TransactionCommitProcess transactionCommitProcess, Kernel kernel, NeoStoreKernelModule( TransactionCommitProcess transactionCommitProcess, KernelImpl kernel,
KernelTransactions kernelTransactions, NeoStoreFileListing fileListing ) KernelTransactions kernelTransactions, NeoStoreFileListing fileListing )
{ {
this.transactionCommitProcess = transactionCommitProcess; this.transactionCommitProcess = transactionCommitProcess;
Expand All @@ -42,7 +41,7 @@ class NeoStoreKernelModule
this.fileListing = fileListing; this.fileListing = fileListing;
} }


public InwardKernel kernelAPI() public KernelImpl kernelAPI()
{ {
return kernel; return kernel;
} }
Expand Down
Expand Up @@ -19,18 +19,14 @@
*/ */
package org.neo4j.kernel.api; package org.neo4j.kernel.api;


import java.util.Optional;

import org.neo4j.internal.kernel.api.NodeCursor; import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.PropertyCursor; import org.neo4j.internal.kernel.api.PropertyCursor;
import org.neo4j.internal.kernel.api.RelationshipScanCursor; import org.neo4j.internal.kernel.api.RelationshipScanCursor;
import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.security.LoginContext; import org.neo4j.internal.kernel.api.security.LoginContext;
import org.neo4j.internal.kernel.api.security.SecurityContext; import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.kernel.impl.api.ClockContext; import org.neo4j.kernel.impl.api.ClockContext;
import org.neo4j.kernel.impl.api.Kernel; import org.neo4j.kernel.impl.api.KernelImpl;


/** /**
* Represents a transaction of changes to the underlying graph. * Represents a transaction of changes to the underlying graph.
Expand Down Expand Up @@ -101,54 +97,11 @@ interface CloseListener
*/ */
Statement acquireStatement(); Statement acquireStatement();


/**
* Closes this transaction, committing its changes if {@link #success()} has been called and neither
* {@link #failure()} nor {@link #markForTermination(Status)} has been called.
* Otherwise its changes will be rolled back.
*
* @return id of the committed transaction or {@link #ROLLBACK} if transaction was rolled back or
* {@link #READ_ONLY} if transaction was read-only.
*/
long closeTransaction() throws TransactionFailureException;

/**
* Closes this transaction, committing its changes if {@link #success()} has been called and neither
* {@link #failure()} nor {@link #markForTermination(Status)} has been called.
* Otherwise its changes will be rolled back.
*/
@Override
default void close() throws TransactionFailureException
{
closeTransaction();
}

/**
* @return {@code true} if the transaction is still open, i.e. if {@link #close()} hasn't been called yet.
*/
boolean isOpen();

/** /**
* @return the security context this transaction is currently executing in. * @return the security context this transaction is currently executing in.
*/ */
SecurityContext securityContext(); SecurityContext securityContext();


/**
* @return {@link Status} if {@link #markForTermination(Status)} has been invoked, otherwise empty optional.
*/
Optional<Status> getReasonIfTerminated();

/**
* @return true if transaction was terminated, otherwise false
*/
boolean isTerminated();

/**
* Marks this transaction for termination, such that it cannot commit successfully and will try to be
* terminated by having other methods throw a specific termination exception, as to sooner reach the assumed
* point where {@link #close()} will be invoked.
*/
void markForTermination( Status reason );

/** /**
* @return The timestamp of the last transaction that was committed to the store when this transaction started. * @return The timestamp of the last transaction that was committed to the store when this transaction started.
*/ */
Expand All @@ -161,7 +114,7 @@ default void close() throws TransactionFailureException


/** /**
* @return start time of this transaction, i.e. basically {@link System#currentTimeMillis()} when user called * @return start time of this transaction, i.e. basically {@link System#currentTimeMillis()} when user called
* {@link Kernel#newTransaction(Type, LoginContext)}. * {@link org.neo4j.internal.kernel.api.Session#beginTransaction(Type)}.
*/ */
long startTime(); long startTime();


Expand Down
Expand Up @@ -23,11 +23,9 @@
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;


import org.neo4j.internal.kernel.api.security.LoginContext;
import org.neo4j.internal.kernel.api.security.SecurityContext; import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.exceptions.Status; import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.query.ExecutingQuery; import org.neo4j.kernel.api.query.ExecutingQuery;
import org.neo4j.kernel.impl.api.Kernel;
import org.neo4j.kernel.impl.api.TransactionExecutionStatistic; import org.neo4j.kernel.impl.api.TransactionExecutionStatistic;
import org.neo4j.kernel.impl.locking.ActiveLock; import org.neo4j.kernel.impl.locking.ActiveLock;


Expand All @@ -52,7 +50,7 @@ public interface KernelTransactionHandle


/** /**
* The start time of the underlying transaction. I.e. basically {@link System#currentTimeMillis()} when user * The start time of the underlying transaction. I.e. basically {@link System#currentTimeMillis()} when user
* called {@link Kernel#newTransaction(KernelTransaction.Type, LoginContext)}. * called {@link org.neo4j.internal.kernel.api.Session#beginTransaction(KernelTransaction.Type)}.
* *
* @return the transaction start time. * @return the transaction start time.
*/ */
Expand Down
Expand Up @@ -63,7 +63,7 @@
import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Value;


/** /**
* Defines all types of read operations that can be done from the {@link InwardKernel}. * Defines all types of read operations that can be done.
*/ */
public interface ReadOperations public interface ReadOperations
{ {
Expand Down
Expand Up @@ -23,13 +23,12 @@
import org.neo4j.internal.kernel.api.exceptions.ProcedureException; import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.internal.kernel.api.procs.QualifiedName; import org.neo4j.internal.kernel.api.procs.QualifiedName;
import org.neo4j.internal.kernel.api.security.SecurityContext; import org.neo4j.internal.kernel.api.security.SecurityContext;
import org.neo4j.kernel.api.InwardKernel;
import org.neo4j.kernel.api.ResourceTracker; import org.neo4j.kernel.api.ResourceTracker;
import org.neo4j.values.AnyValue; import org.neo4j.values.AnyValue;


/** /**
* Defines all types of system-oriented operations - i.e. those which do not read from or * Defines all types of system-oriented operations - i.e. those which do not read from or
* write to the graph - that can be done from the {@link InwardKernel}. * write to the graph - that can be done.
* An example of this is changing a user's password * An example of this is changing a user's password
*/ */
public interface DbmsOperations public interface DbmsOperations
Expand Down
Expand Up @@ -159,6 +159,5 @@ public static Iterator<SchemaIndexDescriptor> sortByType( Iterator<SchemaIndexDe
return Iterators.concat( return Iterators.concat(
Iterators.filter( GENERAL, materialized.iterator() ), Iterators.filter( GENERAL, materialized.iterator() ),
Iterators.filter( UNIQUE, materialized.iterator() ) ); Iterators.filter( UNIQUE, materialized.iterator() ) );

} }
} }
Expand Up @@ -66,7 +66,7 @@
* finally {@link org.neo4j.storageengine.api.StoreReadLayer} will read the current committed state from * finally {@link org.neo4j.storageengine.api.StoreReadLayer} will read the current committed state from
* the stores or caches. * the stores or caches.
*/ */
public class Kernel extends LifecycleAdapter implements InwardKernel public class KernelImpl extends LifecycleAdapter implements InwardKernel
{ {
private final KernelTransactions transactions; private final KernelTransactions transactions;
private final TransactionHooks hooks; private final TransactionHooks hooks;
Expand All @@ -77,7 +77,7 @@ public class Kernel extends LifecycleAdapter implements InwardKernel


private final NewKernel newKernel; private final NewKernel newKernel;


public Kernel( KernelTransactions transactionFactory, TransactionHooks hooks, DatabaseHealth health, public KernelImpl( KernelTransactions transactionFactory, TransactionHooks hooks, DatabaseHealth health,
TransactionMonitor transactionMonitor, Procedures procedures, Config config, StorageEngine engine ) TransactionMonitor transactionMonitor, Procedures procedures, Config config, StorageEngine engine )
{ {
this.transactions = transactionFactory; this.transactions = transactionFactory;
Expand Down
Expand Up @@ -23,13 +23,15 @@
import java.util.function.Supplier; import java.util.function.Supplier;


import org.neo4j.internal.kernel.api.CapableIndexReference; import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.SchemaRead; import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.Session;
import org.neo4j.internal.kernel.api.TokenRead; import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException;
import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.internal.kernel.api.schema.SchemaDescriptor; import org.neo4j.internal.kernel.api.schema.SchemaDescriptor;
import org.neo4j.kernel.api.InwardKernel;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.SilentTokenNameLookup; import org.neo4j.kernel.api.SilentTokenNameLookup;
import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.Statement;
Expand Down Expand Up @@ -66,10 +68,10 @@
public class ConstraintIndexCreator public class ConstraintIndexCreator
{ {
private final IndexingService indexingService; private final IndexingService indexingService;
private final Supplier<InwardKernel> kernelSupplier; private final Supplier<Kernel> kernelSupplier;
private final PropertyAccessor propertyAccessor; private final PropertyAccessor propertyAccessor;


public ConstraintIndexCreator( Supplier<InwardKernel> kernelSupplier, IndexingService indexingService, public ConstraintIndexCreator( Supplier<Kernel> kernelSupplier, IndexingService indexingService,
PropertyAccessor propertyAccessor ) PropertyAccessor propertyAccessor )
{ {
this.kernelSupplier = kernelSupplier; this.kernelSupplier = kernelSupplier;
Expand Down Expand Up @@ -297,9 +299,9 @@ private void releaseLabelLock( Client locks, int labelId )
public void dropUniquenessConstraintIndex( SchemaIndexDescriptor descriptor ) public void dropUniquenessConstraintIndex( SchemaIndexDescriptor descriptor )
throws TransactionFailureException throws TransactionFailureException
{ {
try ( KernelTransaction transaction = try ( Session session = kernelSupplier.get().beginSession( AUTH_DISABLED );
kernelSupplier.get().newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); Transaction transaction = session.beginTransaction( Transaction.Type.implicit );
Statement ignore = transaction.acquireStatement() ) Statement ignore = ((KernelTransaction)transaction).acquireStatement() )
{ {
((KernelTransactionImplementation) transaction).txState().indexDoDrop( descriptor ); ((KernelTransactionImplementation) transaction).txState().indexDoDrop( descriptor );
transaction.success(); transaction.success();
Expand Down Expand Up @@ -399,9 +401,9 @@ private CapableIndexReference getOrCreateUniquenessConstraintIndex( SchemaRead s


public SchemaIndexDescriptor createConstraintIndex( final SchemaDescriptor schema ) public SchemaIndexDescriptor createConstraintIndex( final SchemaDescriptor schema )
{ {
try ( KernelTransaction transaction = try ( Session session = kernelSupplier.get().beginSession( AUTH_DISABLED );
kernelSupplier.get().newTransaction( KernelTransaction.Type.implicit, AUTH_DISABLED ); Transaction transaction = session.beginTransaction( Transaction.Type.implicit );
Statement ignore = transaction.acquireStatement() ) Statement ignore = ((KernelTransaction)transaction).acquireStatement() )
{ {
SchemaIndexDescriptor index = SchemaIndexDescriptorFactory.uniqueForSchema( schema ); SchemaIndexDescriptor index = SchemaIndexDescriptorFactory.uniqueForSchema( schema );
((KernelTransactionImplementation) transaction).txState().indexRuleDoAdd( index ); ((KernelTransactionImplementation) transaction).txState().indexRuleDoAdd( index );
Expand Down
Expand Up @@ -21,22 +21,22 @@


import java.util.function.Supplier; import java.util.function.Supplier;


import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException; import org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException;
import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException; import org.neo4j.internal.kernel.api.exceptions.schema.TooManyLabelsException;
import org.neo4j.kernel.api.InwardKernel;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory; import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdType; import org.neo4j.kernel.impl.store.id.IdType;


public class DefaultLabelIdCreator extends IsolatedTransactionTokenCreator public class DefaultLabelIdCreator extends IsolatedTransactionTokenCreator
{ {
public DefaultLabelIdCreator( Supplier<InwardKernel> kernelSupplier, IdGeneratorFactory idGeneratorFactory ) public DefaultLabelIdCreator( Supplier<Kernel> kernelSupplier, IdGeneratorFactory idGeneratorFactory )
{ {
super( kernelSupplier, idGeneratorFactory ); super( kernelSupplier, idGeneratorFactory );
} }


@Override @Override
protected int createKey( KernelTransaction transaction, String name ) throws IllegalTokenNameException, TooManyLabelsException protected int createKey( Transaction transaction, String name ) throws IllegalTokenNameException, TooManyLabelsException
{ {
int id = (int) idGeneratorFactory.get( IdType.LABEL_TOKEN ).nextId(); int id = (int) idGeneratorFactory.get( IdType.LABEL_TOKEN ).nextId();
transaction.tokenWrite().labelCreateForName( name, id ); transaction.tokenWrite().labelCreateForName( name, id );
Expand Down

0 comments on commit 6516dc6

Please sign in to comment.