Search in sources :

Example 1 with FabricTransaction

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();
}
Also used : AdminActionOnResource(org.neo4j.internal.kernel.api.security.AdminActionOnResource) ZoneId(java.time.ZoneId) DatabaseScope(org.neo4j.internal.kernel.api.security.AdminActionOnResource.DatabaseScope) ArrayList(java.util.ArrayList) FabricTransaction(org.neo4j.fabric.transaction.FabricTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) DatabaseContext(org.neo4j.dbms.database.DatabaseContext) ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) UserSegment(org.neo4j.internal.kernel.api.security.UserSegment) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Example 2 with FabricTransaction

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);
}
Also used : FabricExecutor(org.neo4j.fabric.executor.FabricExecutor) FabricTransaction(org.neo4j.fabric.transaction.FabricTransaction)

Example 3 with 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);
}
Also used : FabricTransactionInfo(org.neo4j.fabric.transaction.FabricTransactionInfo) FabricTransaction(org.neo4j.fabric.transaction.FabricTransaction)

Example 4 with 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();
}
Also used : HashMap(java.util.HashMap) DatabaseIdRepository(org.neo4j.kernel.database.DatabaseIdRepository) ArrayList(java.util.ArrayList) FabricTransaction(org.neo4j.fabric.transaction.FabricTransaction) KernelTransactionHandle(org.neo4j.kernel.api.KernelTransactionHandle) DatabaseContext(org.neo4j.dbms.database.DatabaseContext) ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId) Map(java.util.Map) HashMap(java.util.HashMap) Description(org.neo4j.procedure.Description) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure)

Aggregations

FabricTransaction (org.neo4j.fabric.transaction.FabricTransaction)4 ArrayList (java.util.ArrayList)2 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)2 KernelTransactionHandle (org.neo4j.kernel.api.KernelTransactionHandle)2 SystemProcedure (org.neo4j.kernel.api.procedure.SystemProcedure)2 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)2 Description (org.neo4j.procedure.Description)2 Procedure (org.neo4j.procedure.Procedure)2 ZoneId (java.time.ZoneId)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FabricExecutor (org.neo4j.fabric.executor.FabricExecutor)1 FabricTransactionInfo (org.neo4j.fabric.transaction.FabricTransactionInfo)1 AdminActionOnResource (org.neo4j.internal.kernel.api.security.AdminActionOnResource)1 DatabaseScope (org.neo4j.internal.kernel.api.security.AdminActionOnResource.DatabaseScope)1 UserSegment (org.neo4j.internal.kernel.api.security.UserSegment)1 DatabaseIdRepository (org.neo4j.kernel.database.DatabaseIdRepository)1 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1