@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 { securityContext.assertCredentialsNotExpired(); try { Set<Long> queryIds = idTexts.stream().map( catchThrown( InvalidArgumentsException.class, QueryId::fromExternalString ) ).map( catchThrown( InvalidArgumentsException.class, QueryId::kernelQueryId ) ).collect( toSet() ); Set<QueryTerminationResult> terminatedQuerys = getActiveTransactions( tx -> executingQueriesWithIds( queryIds, tx ) ).map( catchThrown( InvalidArgumentsException.class, this::killQueryTransaction ) ).collect( toSet() ); boolean killQueryVerbose = resolver.resolveDependency( Config.class ).get( GraphDatabaseSettings.kill_query_verbose ); if ( killQueryVerbose && terminatedQuerys.size() != idTexts.size() ) { for ( String id : idTexts ) { if ( terminatedQuerys.stream().noneMatch( query -> query.queryId.equals( id ) ) ) { terminatedQuerys.add( new QueryFailedTerminationResult( fromExternalString( id ) ) ); } } } return terminatedQuerys.stream(); } catch ( UncaughtCheckedException uncaught ) { throwIfPresent( uncaught.getCauseIfOfType( InvalidArgumentsException.class ) ); throw uncaught; } }
@Description( "List all transactions currently executing at this instance that are visible to the user." ) @Procedure( name = "dbms.listTransactions", mode = DBMS ) public Stream<TransactionStatusResult> listTransactions() throws InvalidArgumentsException { securityContext.assertCredentialsNotExpired(); try { Set<KernelTransactionHandle> handles = getKernelTransactions().activeTransactions().stream() .filter( transaction -> isAdminOrSelf( transaction.subject().username() ) ) .collect( toSet() ); Map<KernelTransactionHandle,List<QuerySnapshot>> handleQuerySnapshotsMap = handles.stream() .collect( toMap( identity(), getTransactionQueries() ) ); TransactionDependenciesResolver transactionBlockerResolvers = new TransactionDependenciesResolver( handleQuerySnapshotsMap ); ZoneId zoneId = getConfiguredTimeZone(); return handles.stream() .map( catchThrown( InvalidArgumentsException.class, tx -> new TransactionStatusResult( tx, transactionBlockerResolvers, handleQuerySnapshotsMap, zoneId ) ) ); } catch ( UncaughtCheckedException uncaught ) { throwIfPresent( uncaught.getCauseIfOfType( InvalidArgumentsException.class ) ); throw uncaught; } }
@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 { securityContext.assertCredentialsNotExpired(); EmbeddedProxySPI nodeManager = resolver.resolveDependency( EmbeddedProxySPI.class ); ZoneId zoneId = getConfiguredTimeZone(); try { return getKernelTransactions().activeTransactions().stream() .flatMap( KernelTransactionHandle::executingQueries ) .filter( query -> isAdminOrSelf( query.username() ) ) .map( catchThrown( InvalidArgumentsException.class, query -> new QueryStatusResult( query, nodeManager, zoneId ) ) ); } catch ( UncaughtCheckedException uncaught ) { throwIfPresent( uncaught.getCauseIfOfType( InvalidArgumentsException.class ) ); throw uncaught; } }
@Description( "Kill all transactions executing the query with the given query id." ) @Procedure( name = "dbms.killQuery", mode = DBMS ) public Stream<QueryTerminationResult> killQuery( @Name( "id" ) String idText ) throws InvalidArgumentsException { securityContext.assertCredentialsNotExpired(); try { long queryId = fromExternalString( idText ).kernelQueryId(); Set<Pair<KernelTransactionHandle,ExecutingQuery>> querys = getActiveTransactions( tx -> executingQueriesWithId( queryId, tx ) ).collect( toSet() ); boolean killQueryVerbose = resolver.resolveDependency( Config.class ).get( GraphDatabaseSettings.kill_query_verbose ); if ( killQueryVerbose && querys.isEmpty() ) { return Stream.<QueryTerminationResult>builder().add( new QueryFailedTerminationResult( fromExternalString( idText ) ) ).build(); } return querys.stream().map( catchThrown( InvalidArgumentsException.class, this::killQueryTransaction ) ); } catch ( UncaughtCheckedException uncaught ) { throwIfPresent( uncaught.getCauseIfOfType( InvalidArgumentsException.class ) ); throw uncaught; } }