use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class BuiltInDbmsProcedures method terminateTransaction.
private TransactionMarkForTerminationResult terminateTransaction(Map<String, KernelTransactionHandle> handles, String transactionId) {
KernelTransactionHandle handle = handles.get(transactionId);
String currentUser = securityContext.subject().username();
if (handle == null) {
return new TransactionMarkForTerminationFailedResult(transactionId, currentUser);
}
if (handle.isClosing()) {
return new TransactionMarkForTerminationFailedResult(transactionId, currentUser, "Unable to kill closing transactions.");
}
log.debug("User %s terminated transaction %s.", currentUser, transactionId);
handle.markForTermination(Status.Transaction.Terminated);
return new TransactionMarkForTerminationResult(transactionId, handle.subject().username());
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class TransactionDependenciesResolver method evaluateDirectDependencies.
private static void evaluateDirectDependencies(Map<KernelTransactionHandle, Set<KernelTransactionHandle>> directDependencies, Map<KernelTransactionHandle, List<ActiveLock>> handleLocksMap, KernelTransactionHandle txHandle, QuerySnapshot querySnapshot) {
List<ActiveLock> waitingOnLocks = querySnapshot.waitingLocks();
for (ActiveLock activeLock : waitingOnLocks) {
for (Map.Entry<KernelTransactionHandle, List<ActiveLock>> handleListEntry : handleLocksMap.entrySet()) {
KernelTransactionHandle kernelTransactionHandle = handleListEntry.getKey();
if (!kernelTransactionHandle.equals(txHandle)) {
if (isBlocked(activeLock, handleListEntry.getValue())) {
Set<KernelTransactionHandle> kernelTransactionHandles = directDependencies.computeIfAbsent(txHandle, handle -> new HashSet<>());
kernelTransactionHandles.add(kernelTransactionHandle);
}
}
}
}
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class TransactionDependenciesResolver method describeBlockingTransactions.
String describeBlockingTransactions(KernelTransactionHandle handle) {
Set<KernelTransactionHandle> allBlockers = new TreeSet<>(Comparator.comparingLong(KernelTransactionHandle::getUserTransactionId));
Set<KernelTransactionHandle> handles = directDependencies.get(handle);
if (handles != null) {
Deque<KernelTransactionHandle> blockerQueue = new ArrayDeque<>(handles);
while (!blockerQueue.isEmpty()) {
KernelTransactionHandle transactionHandle = blockerQueue.pop();
if (allBlockers.add(transactionHandle)) {
Set<KernelTransactionHandle> transactionHandleSet = directDependencies.get(transactionHandle);
if (transactionHandleSet != null) {
blockerQueue.addAll(transactionHandleSet);
}
}
}
}
return describe(allBlockers);
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class TransactionDependenciesResolver method initDirectDependencies.
private Map<KernelTransactionHandle, Set<KernelTransactionHandle>> initDirectDependencies() {
Map<KernelTransactionHandle, Set<KernelTransactionHandle>> directDependencies = new HashMap<>();
Map<KernelTransactionHandle, List<ActiveLock>> transactionLocksMap = handleSnapshotsMap.keySet().stream().collect(toMap(identity(), getTransactionLocks()));
for (Map.Entry<KernelTransactionHandle, Optional<QuerySnapshot>> entry : handleSnapshotsMap.entrySet()) {
Optional<QuerySnapshot> snapshot = entry.getValue();
if (snapshot.isPresent()) {
KernelTransactionHandle txHandle = entry.getKey();
evaluateDirectDependencies(directDependencies, transactionLocksMap, txHandle, snapshot.get());
}
}
return directDependencies;
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class BoltV3TransportIT method shouldSetTxMetadata.
@ParameterizedTest(name = "{0}")
@MethodSource("argumentsProvider")
public void shouldSetTxMetadata(Class<? extends TransportConnection> connectionClass) throws Exception {
init(connectionClass);
// Given
negotiateBoltV3();
Map<String, Object> txMetadata = map("who-is-your-boss", "Molly-mostly-white");
Map<String, Object> msgMetadata = map("tx_metadata", txMetadata);
MapValue meta = asMapValue(msgMetadata);
connection.send(util.chunk(new BeginMessage(meta, List.of(), null, AccessMode.WRITE, txMetadata), new RunMessage("RETURN 1"), PullAllMessage.INSTANCE));
// When
assertThat(connection).satisfies(util.eventuallyReceives(msgSuccess(), msgSuccess(), msgRecord(eqRecord(longEquals(1L))), msgSuccess()));
// Then
GraphDatabaseAPI gdb = (GraphDatabaseAPI) server.graphDatabaseService();
Set<KernelTransactionHandle> txHandles = gdb.getDependencyResolver().resolveDependency(KernelTransactions.class).activeTransactions();
assertThat(txHandles.size()).isEqualTo(1);
for (KernelTransactionHandle txHandle : txHandles) {
assertThat(txHandle.getMetaData()).isEqualTo(txMetadata);
}
connection.send(util.chunk(ROLLBACK_MESSAGE));
}
Aggregations