Search in sources :

Example 1 with DispatchQuery

use of io.trino.dispatcher.DispatchQuery in project trino by trinodb.

the class KillQueryProcedure method killQuery.

@UsedByGeneratedCode
public void killQuery(String queryId, String message, ConnectorSession session) {
    QueryId query = parseQueryId(queryId);
    try {
        checkState(dispatchManager.isPresent(), "No dispatch manager is set. kill_query procedure should be executed on coordinator.");
        DispatchQuery dispatchQuery = dispatchManager.get().getQuery(query);
        checkCanKillQueryOwnedBy(((FullConnectorSession) session).getSession().getIdentity(), dispatchQuery.getSession().getIdentity(), accessControl);
        // check before killing to provide the proper error message (this is racy)
        if (dispatchQuery.isDone()) {
            throw new TrinoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
        }
        dispatchQuery.fail(createKillQueryException(message));
        // verify if the query was killed (if not, we lost the race)
        checkState(dispatchQuery.isDone(), "Failure to fail the query: %s", query);
        if (!ADMINISTRATIVELY_KILLED.toErrorCode().equals(dispatchQuery.getErrorCode().orElse(null))) {
            throw new TrinoException(NOT_SUPPORTED, "Target query is not running: " + queryId);
        }
    } catch (NoSuchElementException e) {
        throw new TrinoException(NOT_FOUND, "Target query not found: " + queryId);
    }
}
Also used : DispatchQuery(io.trino.dispatcher.DispatchQuery) QueryId(io.trino.spi.QueryId) TrinoException(io.trino.spi.TrinoException) NoSuchElementException(java.util.NoSuchElementException) FullConnectorSession(io.trino.FullConnectorSession) UsedByGeneratedCode(io.trino.annotation.UsedByGeneratedCode)

Aggregations

FullConnectorSession (io.trino.FullConnectorSession)1 UsedByGeneratedCode (io.trino.annotation.UsedByGeneratedCode)1 DispatchQuery (io.trino.dispatcher.DispatchQuery)1 QueryId (io.trino.spi.QueryId)1 TrinoException (io.trino.spi.TrinoException)1 NoSuchElementException (java.util.NoSuchElementException)1