Search in sources :

Example 26 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery in project neo4j by neo4j.

the class ExecutingQueryFactory method createForStatement.

public ExecutingQuery createForStatement(KernelStatement statement, String queryText, MapValue queryParameters) {
    KernelTransactionImplementation transaction = statement.getTransaction();
    ExecutingQuery executingQuery = createUnbound(queryText, queryParameters, transaction.clientInfo(), statement.username(), transaction.getMetaData());
    bindToStatement(executingQuery, statement);
    return executingQuery;
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery)

Example 27 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery in project neo4j by neo4j.

the class StatementQueryRegistry method startQueryExecution.

@Override
public ExecutingQuery startQueryExecution(String queryText, MapValue queryParameters) {
    ExecutingQuery executingQuery = factory.createForStatement(statement, queryText, queryParameters);
    registerExecutingQuery(executingQuery);
    return executingQuery;
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery)

Example 28 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery in project neo4j by neo4j.

the class KernelStatementTest method getQueryWithWaitingTime.

private static ExecutingQuery getQueryWithWaitingTime() {
    ExecutingQuery executingQuery = mock(ExecutingQuery.class);
    when(executingQuery.reportedWaitingTimeNanos()).thenReturn(1L);
    return executingQuery;
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery)

Example 29 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery in project neo4j by neo4j.

the class TransactionDependenciesResolverTest method createQuerySnapshotWaitingForLock.

private static QuerySnapshot createQuerySnapshotWaitingForLock(long queryId, LockType lockType, ResourceType resourceType, long transacitonId, long id) {
    ExecutingQuery executingQuery = createExecutingQuery(queryId);
    executingQuery.lockTracer().waitForLock(lockType, resourceType, transacitonId, id);
    return executingQuery.snapshot();
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery)

Example 30 with ExecutingQuery

use of org.neo4j.kernel.api.query.ExecutingQuery 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

ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)30 Test (org.junit.Test)12 QueryLogger (org.neo4j.kernel.impl.query.QueryLoggerKernelExtension.QueryLogger)9 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)9 FakeClock (org.neo4j.time.FakeClock)9 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Test (org.junit.jupiter.api.Test)5 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)4 HashMap (java.util.HashMap)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 ArrayList (java.util.ArrayList)2 MutableObject (org.apache.commons.lang3.mutable.MutableObject)2 InOrder (org.mockito.InOrder)2 DatabaseContext (org.neo4j.dbms.database.DatabaseContext)2 FabricTransaction (org.neo4j.fabric.transaction.FabricTransaction)2 ClientConnectionInfo (org.neo4j.internal.kernel.api.connectioninfo.ClientConnectionInfo)2 AdminActionOnResource (org.neo4j.internal.kernel.api.security.AdminActionOnResource)2 DatabaseScope (org.neo4j.internal.kernel.api.security.AdminActionOnResource.DatabaseScope)2 SecurityContext (org.neo4j.internal.kernel.api.security.SecurityContext)2 UserSegment (org.neo4j.internal.kernel.api.security.UserSegment)2