Skip to content

Commit

Permalink
Clean up statement timeout mechanism and property.
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Aug 22, 2016
1 parent d162703 commit 08cd588
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.cypher.internal.spi.v3_0

import java.net.URL
import java.time.Clock

import org.mockito.Mockito._
import org.neo4j.cypher.internal.compiler.v3_0.helpers.DynamicIterable
Expand Down Expand Up @@ -57,7 +56,7 @@ class TransactionBoundQueryContextTest extends CypherFunSuite {
outerTx = mock[InternalTransaction]
val kernelTransaction = mock[KernelTransactionImplementation]
when(kernelTransaction.mode()).thenReturn(AccessMode.Static.FULL)
statement = new KernelStatement(kernelTransaction, null, null, null, new Procedures(), Clock.systemUTC, 1L)
statement = new KernelStatement(kernelTransaction, null, null, null, new Procedures() )
}

override def afterEach() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public TimeoutGuard( Clock clock, final Log log )
@Override
public void check( KernelStatement statement )
{
check( getMaxStatementCompletionTime( statement ), "Statement timeout." );
check( statement.getTransaction() );
}

Expand All @@ -60,12 +59,6 @@ private void check( long maxCompletionTime, String timeoutDescription )
}
}


private static long getMaxStatementCompletionTime( KernelStatement statement )
{
return statement.startTime() + statement.timeout();
}

private static long getMaxTransactionCompletionTime( KernelTransactionImplementation transaction )
{
return transaction.startTime() + transaction.timeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
package org.neo4j.kernel.impl.api;

import java.time.Clock;

import org.neo4j.graphdb.NotInTransactionException;
import org.neo4j.graphdb.TransactionTerminatedException;
import org.neo4j.graphdb.security.AuthorizationViolationException;
Expand Down Expand Up @@ -61,24 +59,18 @@ public class KernelStatement implements TxStateHolder, Statement
{
private final TxStateHolder txStateHolder;
private final StorageStatement storeStatement;
private Clock clock;
private final KernelTransactionImplementation transaction;
private final OperationsFacade facade;
private StatementLocks statementLocks;
private int referenceCount;
private long startTimeMillis;
private long timeoutMillis;

public KernelStatement( KernelTransactionImplementation transaction,
TxStateHolder txStateHolder,
StatementOperationParts operations, StorageStatement storeStatement, Procedures procedures, Clock clock,
Long timeoutMillis )
StatementOperationParts operations, StorageStatement storeStatement, Procedures procedures )
{
this.transaction = transaction;
this.txStateHolder = txStateHolder;
this.storeStatement = storeStatement;
this.clock = clock;
this.timeoutMillis = timeoutMillis;
this.facade = new OperationsFacade( transaction, this, operations, procedures );
}

Expand Down Expand Up @@ -182,7 +174,6 @@ final void acquire()
{
if ( referenceCount++ == 0 )
{
startTimeMillis = clock.millis();
storeStatement.acquire();
}
}
Expand All @@ -207,16 +198,6 @@ public StorageStatement getStoreStatement()
return storeStatement;
}

public long startTime()
{
return startTimeMillis;
}

public long timeout()
{
return timeoutMillis;
}

public KernelTransactionImplementation getTransaction()
{
return transaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public KernelTransactionImplementation( StatementOperationParts operations,
Clock clock,
TransactionTracer tracer,
StorageEngine storageEngine,
boolean txTerminationAwareLocks, long statementTimeout )
boolean txTerminationAwareLocks )
{
this.operations = operations;
this.schemaWriteGuard = schemaWriteGuard;
Expand All @@ -202,7 +202,7 @@ public KernelTransactionImplementation( StatementOperationParts operations,
this.clock = clock;
this.tracer = tracer;
this.storageStatement = storeLayer.newStatement();
this.currentStatement = new KernelStatement( this, this, operations, storageStatement, procedures, clock, statementTimeout );
this.currentStatement = new KernelStatement( this, this, operations, storageStatement, procedures );
this.txTerminationAwareLocks = txTerminationAwareLocks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.neo4j.function.Factory;
import org.neo4j.graphdb.DatabaseShutdownException;
import org.neo4j.graphdb.config.Setting;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.KernelTransactionHandle;
import org.neo4j.kernel.api.exceptions.Status;
Expand Down Expand Up @@ -75,7 +74,6 @@ public class KernelTransactions extends LifecycleAdapter

private final StatementLocksFactory statementLocksFactory;
private final boolean txTerminationAwareLocks;
private final long statementTimeout;
private final ConstraintIndexCreator constraintIndexCreator;
private final StatementOperationParts statementOperations;
private final SchemaWriteGuard schemaWriteGuard;
Expand Down Expand Up @@ -127,7 +125,6 @@ public KernelTransactions( StatementLocksFactory statementLocksFactory,
{
this.statementLocksFactory = statementLocksFactory;
this.txTerminationAwareLocks = config.get( tx_termination_aware_locks );
this.statementTimeout = config.get( GraphDatabaseSettings.statement_timeout );
this.constraintIndexCreator = constraintIndexCreator;
this.statementOperations = statementOperations;
this.schemaWriteGuard = schemaWriteGuard;
Expand Down Expand Up @@ -157,7 +154,7 @@ public KernelTransactionImplementation newInstance()
statementOperations, schemaWriteGuard, hooks, constraintIndexCreator, procedures,
transactionHeaderInformationFactory, transactionCommitProcess, transactionMonitor,
legacyIndexTxStateSupplier, localTxPool, clock, tracers.transactionTracer,
storageEngine, txTerminationAwareLocks, statementTimeout );
storageEngine, txTerminationAwareLocks );

allTransactions.add( tx );
return tx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static Instances kernelTransactionWithInternals( AccessMode accessMode )
mock( Pool.class ),
Clock.systemUTC(),
TransactionTracer.NULL,
storageEngine, false, 1L );
storageEngine, false );

StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import org.junit.Test;

import java.time.Clock;

import org.neo4j.graphdb.TransactionTerminatedException;
import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.security.AccessMode;
Expand All @@ -42,8 +40,7 @@ public void shouldThrowTerminateExceptionWhenTransactionTerminated() throws Exce
when( transaction.getReasonIfTerminated() ).thenReturn( Status.Transaction.Terminated );
when( transaction.mode() ).thenReturn( AccessMode.Static.FULL );

KernelStatement statement = new KernelStatement(
transaction, null, null, mock( StorageStatement.class ), null, Clock.systemUTC(), 1L );
KernelStatement statement = new KernelStatement( transaction, null, null, mock( StorageStatement.class ), null );
statement.acquire();

statement.readOperations().nodeExists( 0 );
Expand All @@ -55,7 +52,7 @@ public void shouldReleaseStorageStatementWhenForceClosed() throws Exception
// given
StorageStatement storeStatement = mock( StorageStatement.class );
KernelStatement statement = new KernelStatement( mock( KernelTransactionImplementation.class ),
null, null, storeStatement, new Procedures(), Clock.systemUTC(), 1L );
null, null, storeStatement, new Procedures() );
statement.acquire();

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,39 +610,6 @@ public void transactionStartTime()
assertEquals( "Transaction start time should be the same as clock time.", startTime, transaction.startTime() );
}

@Test
public void statementStartTimeAssignedOnFirstAcquisition()
{
KernelTransactionImplementation transaction = newTransaction( AccessMode.Static.FULL );
long startTime = clock.forward( 17, TimeUnit.SECONDS ).millis();
KernelStatement kernelStatement = transaction.acquireStatement();

assertEquals( "Statement start time assigned during first acquisition.", startTime,
kernelStatement.startTime() );

clock.forward( 1, TimeUnit.SECONDS ).millis();
kernelStatement = transaction.acquireStatement();
assertEquals( "Statement start time assigned during first acquisition.", startTime,
kernelStatement.startTime() );

clock.forward( 2, TimeUnit.SECONDS ).millis();
kernelStatement = transaction.acquireStatement();
assertEquals( "Statement start time assigned during first acquisition.", startTime,
kernelStatement.startTime() );

clock.forward( 3, TimeUnit.SECONDS ).millis();
kernelStatement = transaction.acquireStatement();
assertEquals( "Statement start time assigned during first acquisition.", startTime,
kernelStatement.startTime() );
}

@Test
public void statementDefaultTimeout()
{
KernelTransactionImplementation transaction = newTransaction( AccessMode.Static.FULL );
assertEquals( "Statement should have default timeout.", DEFAULT_STATEMENT_TIMEOUT, transaction.acquireStatement().timeout() );
}

@Test
public void markForTerminationWithCorrectReuseCount() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ private static class TestKernelTransaction extends KernelTransactionImplementati
mock( ConstraintIndexCreator.class ), new Procedures(), TransactionHeaderInformationFactory.DEFAULT,
mock( TransactionCommitProcess.class ), monitor, () -> mock( LegacyIndexTransactionState.class ),
mock( Pool.class ), new FakeClock(), TransactionTracer.NULL,
mock( StorageEngine.class, RETURNS_MOCKS ), true, 1L );
mock( StorageEngine.class, RETURNS_MOCKS ), true );

this.monitor = monitor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public class KernelTransactionTestBase
protected final FakeClock clock = new FakeClock();
protected final Pool<KernelTransactionImplementation> txPool = mock( Pool.class );
private final long defaultTransactionTimeoutMillis = GraphDatabaseSettings.transaction_timeout.from( Config.defaults() );
protected static final long DEFAULT_STATEMENT_TIMEOUT = 1000L;


@Before
public void before()
Expand Down Expand Up @@ -123,7 +121,7 @@ public KernelTransactionImplementation newNotInitializedTransaction( boolean txT
{
return new KernelTransactionImplementation( null, schemaWriteGuard, hooks, null, null, headerInformationFactory,
commitProcess, transactionMonitor, legacyIndexStateSupplier, txPool, clock, TransactionTracer.NULL,
storageEngine, txTerminationAwareLocks, DEFAULT_STATEMENT_TIMEOUT );
storageEngine, txTerminationAwareLocks );
}

public class CapturingCommitProcess implements TransactionCommitProcess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.Test;
import org.mockito.InOrder;

import java.time.Clock;
import java.util.Collections;
import java.util.Iterator;
import java.util.function.Function;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class LockingStatementOperationsTest
private final KernelTransactionImplementation transaction = mock( KernelTransactionImplementation.class );
private final TxState txState = new TxState();
private final KernelStatement state = new KernelStatement( transaction, new SimpleTxStateHolder( txState ),
null, mock( StorageStatement.class ), new Procedures(), Clock.systemUTC(), 1L );
null, mock( StorageStatement.class ), new Procedures() );
private final SchemaStateOperations schemaStateOps;

public LockingStatementOperationsTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import org.junit.Test;

import java.time.Clock;

import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.storageengine.api.StorageStatement;

Expand Down Expand Up @@ -71,7 +69,6 @@ public void shouldReleaseStoreStatementWhenForceClosingStatements() throws Excep
private KernelStatement getKernelStatement( KernelTransactionImplementation transaction,
StorageStatement storageStatement )
{
return new KernelStatement( transaction, null, null, storageStatement, new Procedures(),
Clock.systemUTC(), 1L );
return new KernelStatement( transaction, null, null, storageStatement, new Procedures() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.After;
import org.junit.Before;

import java.time.Clock;
import java.util.Map;

import org.neo4j.graphdb.DependencyResolver;
Expand Down Expand Up @@ -69,8 +68,7 @@ public void before()
db = (GraphDatabaseAPI) createGraphDatabase();
DependencyResolver resolver = db.getDependencyResolver();
this.disk = resolver.resolveDependency( StorageEngine.class ).storeReadLayer();
this.state = new KernelStatement( null, null, null, disk.newStatement(), new Procedures(), Clock.systemUTC(),
1L );
this.state = new KernelStatement( null, null, null, disk.newStatement(), new Procedures() );
}

protected GraphDatabaseService createGraphDatabase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ private Map<Setting<?>,String> getSettingsMap()
boltConnector.encryption_level, GraphDatabaseSettings.BoltConnector.EncryptionLevel.DISABLED.name(),
GraphDatabaseSettings.execution_guard_enabled, Settings.TRUE,
GraphDatabaseSettings.transaction_timeout, "2s",
GraphDatabaseSettings.auth_enabled, "false",
GraphDatabaseSettings.statement_timeout, "100s" );
GraphDatabaseSettings.auth_enabled, "false" );
}


Expand Down

0 comments on commit 08cd588

Please sign in to comment.