Search in sources :

Example 1 with StatementLocks

use of org.neo4j.kernel.impl.locking.StatementLocks in project neo4j by neo4j.

the class KernelTransactions method newInstance.

public KernelTransaction newInstance(KernelTransaction.Type type, SecurityContext securityContext, long timeout) {
    assertCurrentThreadIsNotBlockingNewTransactions();
    SecurityContext frozenSecurityContext = securityContext.freeze();
    try {
        while (!newTransactionsLock.readLock().tryLock(1, TimeUnit.SECONDS)) {
            assertRunning();
        }
        try {
            assertRunning();
            TransactionId lastCommittedTransaction = transactionIdStore.getLastCommittedTransaction();
            KernelTransactionImplementation tx = localTxPool.acquire();
            StatementLocks statementLocks = statementLocksFactory.newInstance();
            tx.initialize(lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, frozenSecurityContext, timeout);
            return tx;
        } finally {
            newTransactionsLock.readLock().unlock();
        }
    } catch (InterruptedException ie) {
        Thread.interrupted();
        throw new TransactionFailureException("Fail to start new transaction.", ie);
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) TransactionId(org.neo4j.kernel.impl.store.TransactionId)

Example 2 with StatementLocks

use of org.neo4j.kernel.impl.locking.StatementLocks in project neo4j by neo4j.

the class NeoStoreDataSourceRule method getDataSource.

public NeoStoreDataSource getDataSource(File storeDir, FileSystemAbstraction fs, IdGeneratorFactory idGeneratorFactory, IdTypeConfigurationProvider idConfigurationProvider, PageCache pageCache, Config config, DatabaseHealth databaseHealth, LogService logService) {
    if (dataSource != null) {
        dataSource.stop();
        dataSource.shutdown();
    }
    StatementLocksFactory locksFactory = mock(StatementLocksFactory.class);
    StatementLocks statementLocks = mock(StatementLocks.class);
    Locks.Client locks = mock(Locks.Client.class);
    when(statementLocks.optimistic()).thenReturn(locks);
    when(statementLocks.pessimistic()).thenReturn(locks);
    when(locksFactory.newInstance()).thenReturn(statementLocks);
    JobScheduler jobScheduler = mock(JobScheduler.class, RETURNS_MOCKS);
    Monitors monitors = new Monitors();
    LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDir, fs, pageCache, config, logService);
    SystemNanoClock clock = Clocks.nanoClock();
    dataSource = new NeoStoreDataSource(storeDir, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, idConfigurationProvider, logService, mock(JobScheduler.class, RETURNS_MOCKS), mock(TokenNameLookup.class), dependencyResolverForNoIndexProvider(labelScanStoreProvider), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), locksFactory, mock(SchemaWriteGuard.class), mock(TransactionEventHandlers.class), IndexingService.NO_MONITOR, fs, mock(TransactionMonitor.class), databaseHealth, mock(PhysicalLogFile.Monitor.class), TransactionHeaderInformationFactory.DEFAULT, new StartupStatisticsProvider(), null, new CommunityCommitProcessFactory(), mock(InternalAutoIndexing.class), pageCache, new StandardConstraintSemantics(), monitors, new Tracers("null", NullLog.getInstance(), monitors, jobScheduler), mock(Procedures.class), IOLimiter.unlimited(), new AvailabilityGuard(clock, NullLog.getInstance()), clock, new CanWrite(), new StoreCopyCheckPointMutex());
    return dataSource;
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) Locks(org.neo4j.kernel.impl.locking.Locks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) StartupStatisticsProvider(org.neo4j.kernel.impl.core.StartupStatisticsProvider) CanWrite(org.neo4j.kernel.impl.factory.CanWrite) SystemNanoClock(org.neo4j.time.SystemNanoClock) StatementLocksFactory(org.neo4j.kernel.impl.locking.StatementLocksFactory) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) Monitors(org.neo4j.kernel.monitoring.Monitors) StoreCopyCheckPointMutex(org.neo4j.kernel.impl.transaction.log.checkpoint.StoreCopyCheckPointMutex) CommunityCommitProcessFactory(org.neo4j.kernel.impl.factory.CommunityCommitProcessFactory) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Tracers(org.neo4j.kernel.monitoring.tracing.Tracers)

Example 3 with StatementLocks

use of org.neo4j.kernel.impl.locking.StatementLocks in project neo4j by neo4j.

the class KernelTransactionTestBase method newTransaction.

public KernelTransactionImplementation newTransaction(long lastTransactionIdWhenStarted, SecurityContext securityContext, Locks.Client locks, long transactionTimeout) {
    KernelTransactionImplementation tx = newNotInitializedTransaction();
    StatementLocks statementLocks = new SimpleStatementLocks(locks);
    tx.initialize(lastTransactionIdWhenStarted, BASE_TX_COMMIT_TIMESTAMP, statementLocks, Type.implicit, securityContext, transactionTimeout);
    return tx;
}
Also used : SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks)

Example 4 with StatementLocks

use of org.neo4j.kernel.impl.locking.StatementLocks in project neo4j by neo4j.

the class TimeoutGuardTest method getKernelStatement.

private KernelStatement getKernelStatement(long transactionTimeout) {
    KernelTransactionImplementation transaction = newNotInitializedTransaction();
    StatementLocks statementLocks = mock(StatementLocks.class);
    transaction.initialize(1L, 2L, statementLocks, KernelTransaction.Type.implicit, AUTH_DISABLED, transactionTimeout);
    return transaction.acquireStatement();
}
Also used : KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks)

Example 5 with StatementLocks

use of org.neo4j.kernel.impl.locking.StatementLocks in project neo4j by neo4j.

the class KernelTransactionFactory method kernelTransactionWithInternals.

static Instances kernelTransactionWithInternals(SecurityContext securityContext) {
    TransactionHeaderInformation headerInformation = new TransactionHeaderInformation(-1, -1, new byte[0]);
    TransactionHeaderInformationFactory headerInformationFactory = mock(TransactionHeaderInformationFactory.class);
    when(headerInformationFactory.create()).thenReturn(headerInformation);
    StorageEngine storageEngine = mock(StorageEngine.class);
    StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
    StorageStatement storageStatement = mock(StorageStatement.class);
    when(storeReadLayer.newStatement()).thenReturn(storageStatement);
    when(storageEngine.storeReadLayer()).thenReturn(storeReadLayer);
    KernelTransactionImplementation transaction = new KernelTransactionImplementation(mock(StatementOperationContainer.class), mock(SchemaWriteGuard.class), new TransactionHooks(), mock(ConstraintIndexCreator.class), new Procedures(), headerInformationFactory, mock(TransactionRepresentationCommitProcess.class), mock(TransactionMonitor.class), mock(Supplier.class), mock(Pool.class), Clocks.systemClock(), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite());
    StatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
    transaction.initialize(0, 0, statementLocks, KernelTransaction.Type.implicit, securityContext, 0L);
    return new Instances(transaction, storageEngine, storeReadLayer, storageStatement);
}
Also used : StorageStatement(org.neo4j.storageengine.api.StorageStatement) TransactionHeaderInformation(org.neo4j.kernel.impl.api.TransactionHeaderInformation) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) TransactionHooks(org.neo4j.kernel.impl.api.TransactionHooks) Procedures(org.neo4j.kernel.impl.proc.Procedures) TransactionHeaderInformationFactory(org.neo4j.kernel.impl.transaction.TransactionHeaderInformationFactory) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StatementOperationContainer(org.neo4j.kernel.impl.api.StatementOperationContainer) CanWrite(org.neo4j.kernel.impl.factory.CanWrite) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaWriteGuard(org.neo4j.kernel.impl.api.SchemaWriteGuard) NoOpClient(org.neo4j.kernel.impl.locking.NoOpClient) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) TransactionRepresentationCommitProcess(org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) StatementLocks(org.neo4j.kernel.impl.locking.StatementLocks) PageCursorTracerSupplier(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier) Supplier(java.util.function.Supplier) Pool(org.neo4j.collection.pool.Pool) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) TransactionMonitor(org.neo4j.kernel.impl.transaction.TransactionMonitor)

Aggregations

StatementLocks (org.neo4j.kernel.impl.locking.StatementLocks)6 SimpleStatementLocks (org.neo4j.kernel.impl.locking.SimpleStatementLocks)3 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)2 CanWrite (org.neo4j.kernel.impl.factory.CanWrite)2 Locks (org.neo4j.kernel.impl.locking.Locks)2 StatementLocksFactory (org.neo4j.kernel.impl.locking.StatementLocksFactory)2 Supplier (java.util.function.Supplier)1 Test (org.junit.Test)1 Pool (org.neo4j.collection.pool.Pool)1 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)1 PageCursorTracerSupplier (org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier)1 AvailabilityGuard (org.neo4j.kernel.AvailabilityGuard)1 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)1 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)1 SchemaWriteGuard (org.neo4j.kernel.impl.api.SchemaWriteGuard)1 StatementOperationContainer (org.neo4j.kernel.impl.api.StatementOperationContainer)1 TransactionHeaderInformation (org.neo4j.kernel.impl.api.TransactionHeaderInformation)1 TransactionHooks (org.neo4j.kernel.impl.api.TransactionHooks)1 TransactionRepresentationCommitProcess (org.neo4j.kernel.impl.api.TransactionRepresentationCommitProcess)1 LabelScanStoreProvider (org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider)1