use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class KernelTransactionTimeoutMonitorTest method terminateExpiredTransactions.
@Test
void terminateExpiredTransactions() {
Set<KernelTransactionHandle> transactions = new HashSet<>();
KernelTransactionImplementation tx1 = prepareTxMock(3, 1, 3);
KernelTransactionImplementation tx2 = prepareTxMock(4, 1, 8);
KernelTransactionImplementationHandle handle1 = new KernelTransactionImplementationHandle(tx1, fakeClock);
KernelTransactionImplementationHandle handle2 = new KernelTransactionImplementationHandle(tx2, fakeClock);
transactions.add(handle1);
transactions.add(handle2);
when(kernelTransactions.activeTransactions()).thenReturn(transactions);
KernelTransactionMonitor transactionMonitor = buildTransactionMonitor();
fakeClock.forward(3, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx1, never()).markForTermination(Status.Transaction.TransactionTimedOut);
verify(tx2, never()).markForTermination(Status.Transaction.TransactionTimedOut);
assertThat(logProvider).doesNotContainMessage("timeout");
fakeClock.forward(2, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx1).markForTermination(EXPECTED_REUSE_COUNT, Status.Transaction.TransactionTimedOut);
verify(tx2, never()).markForTermination(Status.Transaction.TransactionTimedOut);
assertThat(logProvider).containsMessages("timeout");
logProvider.clear();
fakeClock.forward(10, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx2).markForTermination(EXPECTED_REUSE_COUNT, Status.Transaction.TransactionTimedOut);
assertThat(logProvider).containsMessages("timeout");
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class KernelTransactionTimeoutMonitorTest method skipTransactionWithoutTimeout.
@Test
void skipTransactionWithoutTimeout() {
Set<KernelTransactionHandle> transactions = new HashSet<>();
KernelTransactionImplementation tx1 = prepareTxMock(7, 3, 0);
KernelTransactionImplementation tx2 = prepareTxMock(8, 4, 0);
KernelTransactionImplementationHandle handle1 = new KernelTransactionImplementationHandle(tx1, fakeClock);
KernelTransactionImplementationHandle handle2 = new KernelTransactionImplementationHandle(tx2, fakeClock);
transactions.add(handle1);
transactions.add(handle2);
when(kernelTransactions.activeTransactions()).thenReturn(transactions);
KernelTransactionMonitor transactionMonitor = buildTransactionMonitor();
fakeClock.forward(300, TimeUnit.MILLISECONDS);
transactionMonitor.run();
verify(tx1, never()).markForTermination(Status.Transaction.TransactionTimedOut);
verify(tx2, never()).markForTermination(Status.Transaction.TransactionTimedOut);
assertThat(logProvider).doesNotContainMessage("timeout");
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class TransactionDependenciesResolverTest method blockingChainDescriptionForChainedBlockedTransaction.
@Test
void blockingChainDescriptionForChainedBlockedTransaction() {
HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 4, singletonList(new ActiveLock(ResourceTypes.NODE, EXCLUSIVE, 4, 1)));
TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 5, singletonList(new ActiveLock(ResourceTypes.NODE, SHARED, 5, 2)));
TestKernelTransactionHandle handle3 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 6);
map.put(handle1, Optional.of(createQuerySnapshot(1)));
map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, EXCLUSIVE, ResourceTypes.NODE, 5, 1)));
map.put(handle3, Optional.of(createQuerySnapshotWaitingForLock(3, EXCLUSIVE, ResourceTypes.NODE, 6, 2)));
TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
assertThat(resolver.describeBlockingTransactions(handle1)).isEmpty();
assertEquals("[transaction-4]", resolver.describeBlockingTransactions(handle2));
assertEquals("[transaction-4, transaction-5]", resolver.describeBlockingTransactions(handle3));
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class TransactionDependenciesResolverTest method detectBlockedTransactionsBySharedLock.
@Test
void detectBlockedTransactionsBySharedLock() {
HashMap<KernelTransactionHandle, Optional<QuerySnapshot>> map = new HashMap<>();
TestKernelTransactionHandle handle1 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction(), 0, singletonList(new ActiveLock(ResourceTypes.NODE, SHARED, 1, 1)));
TestKernelTransactionHandle handle2 = new TestKernelTransactionHandleWithLocks(new StubKernelTransaction());
map.put(handle1, Optional.of(createQuerySnapshot(1)));
map.put(handle2, Optional.of(createQuerySnapshotWaitingForLock(2, EXCLUSIVE, ResourceTypes.NODE, 1, 1)));
TransactionDependenciesResolver resolver = new TransactionDependenciesResolver(map);
assertFalse(resolver.isBlocked(handle1));
assertTrue(resolver.isBlocked(handle2));
}
use of org.neo4j.kernel.api.KernelTransactionHandle in project neo4j by neo4j.
the class BuiltInDbmsProcedures method killQueries.
@SystemProcedure
@Description("Kill all transactions executing a query with any of the given query ids.")
@Procedure(name = "dbms.killQueries", mode = DBMS)
public Stream<QueryTerminationResult> killQueries(@Name("ids") List<String> idTexts) throws InvalidArgumentsException {
DatabaseManager<DatabaseContext> databaseManager = getDatabaseManager();
DatabaseIdRepository databaseIdRepository = databaseManager.databaseIdRepository();
Map<Long, QueryId> queryIds = new HashMap<>(idTexts.size());
for (String idText : idTexts) {
QueryId id = QueryId.parse(idText);
queryIds.put(id.internalId(), id);
}
List<QueryTerminationResult> result = new ArrayList<>(queryIds.size());
for (FabricTransaction tx : getFabricTransactions()) {
for (ExecutingQuery query : getActiveFabricQueries(tx)) {
QueryId givenQueryId = queryIds.remove(query.internalQueryId());
if (givenQueryId != null) {
result.add(killFabricQueryTransaction(givenQueryId, tx, query));
}
}
}
for (Map.Entry<NamedDatabaseId, DatabaseContext> databaseEntry : databaseManager.registeredDatabases().entrySet()) {
NamedDatabaseId databaseId = databaseEntry.getKey();
DatabaseContext databaseContext = databaseEntry.getValue();
if (databaseContext.database().isStarted()) {
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
if (tx.executingQuery().isPresent()) {
QueryId givenQueryId = queryIds.remove(tx.executingQuery().get().internalQueryId());
if (givenQueryId != null) {
result.add(killQueryTransaction(givenQueryId, tx, databaseId));
}
}
}
}
}
// Add error about the rest
for (QueryId queryId : queryIds.values()) {
result.add(new QueryFailedTerminationResult(queryId, "n/a", "No Query found with this id"));
}
return result.stream();
}
Aggregations