@Override public URL validateURLAccess( URL url ) throws URLAccessValidationError { return urlValidator.apply( url ); }
@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 the active lock requests granted for the transaction executing the query with the given query id." ) @Procedure( name = "dbms.listActiveLocks", mode = DBMS ) public Stream<ActiveLocksResult> listActiveLocks( @Name( "queryId" ) String queryId ) throws InvalidArgumentsException { securityContext.assertCredentialsNotExpired(); try { long id = fromExternalString( queryId ).kernelQueryId(); return getActiveTransactions( tx -> executingQueriesWithId( id, tx ) ) .flatMap( this::getActiveLocksForQuery ); } 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; } }
@Override public OUT next() throws IOException { if ( !hasNext() ) { throw new IllegalStateException(); } return converter.apply( items[cursor++] ); }
@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; } }
@Override public TO next() throws EX { FROM from = fromIterator.next(); return function.apply( from ); }
@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; } }
return throwing.apply( input );
/** * Map current instances to some other type using the converter function. * Even called on instances that haven't been instantiated yet. * Mapping is preserved in returned {@link EnumMap}. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ <R,E extends Exception> EnumMap<IndexSlot,R> map( ThrowingFunction<T,R,E> converter ) throws E { EnumMap<IndexSlot,R> result = new EnumMap<>( IndexSlot.class ); for ( IndexSlot slot : IndexSlot.values() ) { result.put( slot, converter.apply( select( slot ) ) ); } return result; }
/** * Map current instances to some other type using the converter function, * without preserving the mapping. * Even called on instances that haven't been instantiated yet. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ @SuppressWarnings( "unchecked" ) <R,E extends Exception> Iterable<R> transform( ThrowingFunction<T,R,E> converter ) throws E { List<R> result = new ArrayList<>(); for ( IndexSlot slot : IndexSlot.values() ) { result.add( converter.apply( select( slot ) ) ); } return result; }
private static <FROM, TO, EX extends Exception> Callable<TO> task( final ThrowingFunction<FROM,TO,EX> function, String name, final FROM parameter, final FailableConsumer<Thread> threadConsumer ) { return () -> { Thread thread = Thread.currentThread(); String previousName = thread.getName(); thread.setName( name ); threadConsumer.accept( thread ); try { return function.apply( parameter ); } catch ( Exception failure ) { threadConsumer.fail( failure ); throw failure; } finally { thread.setName( previousName ); } }; }
@Override public boolean next() throws IOException { while ( currentLogTransactionCursor == null || !currentLogTransactionCursor.next() ) { // We've run out of transactions in this log version, back up to a previous one currentVersion--; if ( currentVersion < backToPosition.getLogVersion() ) { return false; } closeCurrent(); LogPosition position = currentVersion > backToPosition.getLogVersion() ? start( currentVersion ) : backToPosition; currentLogTransactionCursor = cursorFactory.apply( position ); } return true; }
private ThrowingFunction<LogPosition,TransactionCursor,IOException> log( int... transactionCounts ) throws IOException { long baseOffset = LogPosition.start( 0 ).getByteOffset(); @SuppressWarnings( "unchecked" ) ThrowingFunction<LogPosition,TransactionCursor,IOException> result = mock( ThrowingFunction.class ); AtomicLong txId = new AtomicLong( 0 ); CommittedTransactionRepresentation[][] logs = new CommittedTransactionRepresentation[transactionCounts.length][]; for ( int logVersion = 0; logVersion < transactionCounts.length; logVersion++ ) { logs[logVersion] = transactions( transactionCounts[logVersion], txId ); } when( result.apply( any( LogPosition.class ) ) ).thenAnswer( invocation -> { LogPosition position = invocation.getArgument( 0 ); if ( position == null ) { // A mockito issue when calling the "when" methods, I believe return null; } // For simplicity the offset means, in this test, the array offset CommittedTransactionRepresentation[] transactions = logs[toIntExact( position.getLogVersion() )]; CommittedTransactionRepresentation[] subset = copyOfRange( transactions, toIntExact( position.getByteOffset() - baseOffset ), transactions.length ); ArrayUtil.reverse( subset ); return given( subset ); } ); return result; }
private int mapToken( ThrowingFunction<Token, Integer, KernelException> f ) { try ( Transaction tx = beginTransaction() ) { return f.apply( tx.token() ); } catch ( KernelException e ) { fail( "Unwanted exception: " + e.getMessage() ); return -1; // unreachable } }
@Override public URL validateURLAccess( URL url ) throws URLAccessValidationError { return urlValidator.apply( url ); }
@Override public OUT next() throws IOException { if ( !hasNext() ) { throw new IllegalStateException(); } return converter.apply( items[cursor++] ); }
@Override public TO next() throws EX { FROM from = fromIterator.next(); return function.apply( from ); }
/** * Map current instances to some other type using the converter function, * without preserving the mapping. * Even called on instances that haven't been instantiated yet. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ @SuppressWarnings( "unchecked" ) <R,E extends Exception> Iterable<R> transform( ThrowingFunction<T,R,E> converter ) throws E { List<R> result = new ArrayList<>(); for ( IndexSlot slot : IndexSlot.values() ) { result.add( converter.apply( select( slot ) ) ); } return result; }
/** * Map current instances to some other type using the converter function. * Even called on instances that haven't been instantiated yet. * Mapping is preserved in returned {@link EnumMap}. * * @param converter {@link ThrowingFunction} which converts from the source to target instance. * @param <R> type of returned instance. * @param <E> type of exception that converter may throw. * @return A new {@link EnumMap} containing the mapped values. * @throws E exception from converter. */ <R,E extends Exception> EnumMap<IndexSlot,R> map( ThrowingFunction<T,R,E> converter ) throws E { EnumMap<IndexSlot,R> result = new EnumMap<>( IndexSlot.class ); for ( IndexSlot slot : IndexSlot.values() ) { result.put( slot, converter.apply( select( slot ) ) ); } return result; }