use of org.neo4j.fabric.transaction.FabricTransaction in project neo4j by neo4j.
the class BuiltInDbmsProcedures method listQueries.
@SystemProcedure
@Description("List all queries currently executing at this instance that are visible to the user.")
@Procedure(name = "dbms.listQueries", mode = DBMS)
public Stream<QueryStatusResult> listQueries() throws InvalidArgumentsException {
ZoneId zoneId = getConfiguredTimeZone();
List<QueryStatusResult> result = new ArrayList<>();
for (FabricTransaction tx : getFabricTransactions()) {
for (ExecutingQuery query : getActiveFabricQueries(tx)) {
String username = query.username();
var action = new AdminActionOnResource(SHOW_TRANSACTION, ALL, new UserSegment(username));
if (isSelfOrAllows(username, action)) {
result.add(new QueryStatusResult(query, (InternalTransaction) transaction, zoneId, "none"));
}
}
}
for (DatabaseContext databaseContext : getDatabaseManager().registeredDatabases().values()) {
if (databaseContext.database().isStarted()) {
DatabaseScope dbScope = new DatabaseScope(databaseContext.database().getNamedDatabaseId().name());
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
if (tx.executingQuery().isPresent()) {
ExecutingQuery query = tx.executingQuery().get();
// Include both the executing query and any previous queries (parent queries of nested query) in the result.
while (query != null) {
String username = query.username();
var action = new AdminActionOnResource(SHOW_TRANSACTION, dbScope, new UserSegment(username));
if (isSelfOrAllows(username, action)) {
result.add(new QueryStatusResult(query, (InternalTransaction) transaction, zoneId, databaseContext.databaseFacade().databaseName()));
}
query = query.getPreviousQuery();
}
}
}
}
}
return result.stream();
}
use of org.neo4j.fabric.transaction.FabricTransaction in project neo4j by neo4j.
the class TestFabricGraphDatabaseService method forceKernelTxCreation.
private InternalTransaction forceKernelTxCreation(BoltTransaction boltTransaction) {
FabricExecutor fabricExecutor = getDependencyResolver().resolveDependency(FabricExecutor.class);
FabricTransaction fabricTransaction = ((BoltFabricDatabaseService.BoltTransactionImpl) boltTransaction).getFabricTransaction();
return fabricExecutor.forceKernelTxCreation(fabricTransaction);
}
use of org.neo4j.fabric.transaction.FabricTransaction in project neo4j by neo4j.
the class BoltFabricDatabaseService method beginTransaction.
@Override
public BoltTransaction beginTransaction(KernelTransaction.Type type, LoginContext loginContext, ClientConnectionInfo clientInfo, List<Bookmark> bookmarks, Duration txTimeout, AccessMode accessMode, Map<String, Object> txMetadata, RoutingContext routingContext) {
memoryTracker.allocateHeap(BOLT_TRANSACTION_SHALLOW_SIZE);
if (txTimeout == null) {
txTimeout = config.getTransactionTimeout();
}
FabricTransactionInfo transactionInfo = new FabricTransactionInfo(accessMode, loginContext, clientInfo, namedDatabaseId, KernelTransaction.Type.IMPLICIT == type, txTimeout, txMetadata, TestOverrides.routingContext(routingContext));
var transactionBookmarkManager = transactionBookmarkManagerFactory.createTransactionBookmarkManager(transactionIdTracker);
transactionBookmarkManager.processSubmittedByClient(bookmarks);
FabricTransaction fabricTransaction = transactionManager.begin(transactionInfo, transactionBookmarkManager);
return new BoltTransactionImpl(transactionInfo, fabricTransaction);
}
use of org.neo4j.fabric.transaction.FabricTransaction 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