void acquireSharedLock( ResourceType resource, long resourceId ) { ktx.statementLocks().optimistic().acquireShared( ktx.lockTracer(), resource, resourceId ); }
@Override public String toString() { String lockSessionId = statementLocks == null ? "statementLocks == null" : String.valueOf( statementLocks.pessimistic().getLockSessionId() ); return "KernelTransaction[" + lockSessionId + "]"; }
@Override public ExecutingQuery startQueryExecution( KernelStatement statement, ClientConnectionInfo clientConnection, String queryText, MapValue queryParameters ) { long queryId = lastQueryId.incrementAndGet(); Thread thread = Thread.currentThread(); long threadId = thread.getId(); String threadName = thread.getName(); ExecutingQuery executingQuery = new ExecutingQuery( queryId, clientConnection, statement.username(), queryText, queryParameters, statement.getTransaction().getMetaData(), () -> statement.locks().activeLockCount(), statement.getPageCursorTracer(), threadId, threadName, clock, cpuClockRef.get(), heapAllocationRef.get() ); registerExecutingQuery( statement, executingQuery ); return executingQuery; }
@Test public void loadSimpleStatementLocksFactoryWhenNoServices() { Locks locks = mock( Locks.class ); Locks.Client locksClient = mock( Client.class ); when( locks.newClient() ).thenReturn( locksClient ); StatementLocksFactorySelector loader = newLoader( locks ); StatementLocksFactory factory = loader.select(); StatementLocks statementLocks = factory.newInstance(); assertThat( factory, instanceOf( SimpleStatementLocksFactory.class ) ); assertThat( statementLocks, instanceOf( SimpleStatementLocks.class ) ); assertSame( locksClient, statementLocks.optimistic() ); assertSame( locksClient, statementLocks.pessimistic() ); }
statementLocks.prepareForCommit( currentStatement.lockTracer() ); Locks.Client commitLocks = statementLocks.pessimistic();
/** * This method will be invoked by concurrent threads for inspecting the locks held by this transaction. * <p> * The fact that {@link #statementLocks} is a volatile fields, grants us enough of a read barrier to get a good * enough snapshot of the lock state (as long as the underlying methods give us such guarantees). * * @return the locks held by this transaction. */ public Stream<? extends ActiveLock> activeLocks() { StatementLocks locks = this.statementLocks; return locks == null ? Stream.empty() : locks.activeLocks(); }
private boolean markForTerminationIfPossible( Status reason ) { if ( canBeTerminated() ) { failure = true; terminationReason = reason; if ( statementLocks != null ) { statementLocks.stop(); } transactionMonitor.transactionTerminated( hasTxStateWithChanges() ); return true; } return false; }
try statementLocks.close(); statementLocks = null; terminationReason = null;
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 );
statementLocks.prepareForCommit( currentStatement.lockTracer() ); Locks.Client commitLocks = statementLocks.pessimistic();
/** * This method will be invoked by concurrent threads for inspecting the locks held by this transaction. * <p> * The fact that {@link #statementLocks} is a volatile fields, grants us enough of a read barrier to get a good * enough snapshot of the lock state (as long as the underlying methods give us such guarantees). * * @return the locks held by this transaction. */ public Stream<? extends ActiveLock> activeLocks() { StatementLocks locks = this.statementLocks; return locks == null ? Stream.empty() : locks.activeLocks(); }
private boolean markForTerminationIfPossible( Status reason ) { if ( canBeTerminated() ) { failure = true; terminationReason = reason; if ( statementLocks != null ) { statementLocks.stop(); } transactionMonitor.transactionTerminated( hasTxStateWithChanges() ); return true; } return false; }
try statementLocks.close(); statementLocks = null; terminationReason = null;
private void sharedSchemaLock( ResourceType type, int tokenId ) { ktx.statementLocks().optimistic().acquireShared( ktx.lockTracer(), type, tokenId ); }
private void releaseExclusiveLock( ResourceTypes types, long... ids ) { ktx.statementLocks().pessimistic().releaseExclusive( types, ids ); }
@Override public ExecutingQuery startQueryExecution( KernelStatement statement, ClientConnectionInfo clientConnection, String queryText, MapValue queryParameters ) { long queryId = lastQueryId.incrementAndGet(); Thread thread = Thread.currentThread(); long threadId = thread.getId(); String threadName = thread.getName(); ExecutingQuery executingQuery = new ExecutingQuery( queryId, clientConnection, statement.username(), queryText, queryParameters, statement.getTransaction().getMetaData(), () -> statement.locks().activeLockCount(), statement.getPageCursorTracer(), threadId, threadName, clock, cpuClockRef.get(), heapAllocationRef.get() ); registerExecutingQuery( statement, executingQuery ); return executingQuery; }
private void exclusiveOptimisticLock( ResourceType resource, long resourceId ) { ktx.statementLocks().optimistic().acquireExclusive( ktx.lockTracer(), resource, resourceId ); }
private void releaseSharedLock( ResourceTypes types, long... ids ) { ktx.statementLocks().pessimistic().releaseShared( types, ids ); }
/** * Assuming that the nodeCursor have been initialized to the node that labels are retrieved from */ private void acquireSharedNodeLabelLocks() { ktx.statementLocks().optimistic().acquireShared( ktx.lockTracer(), ResourceTypes.LABEL, nodeCursor.labels().all() ); }
private void acquireSharedLock( ResourceTypes types, long... ids ) { ktx.statementLocks().pessimistic().acquireShared( ktx.lockTracer(), types, ids ); }