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);
}
}
Aggregations