Github user arina-ielchiieva commented on a diff in the pull request: https://github.com/apache/drill/pull/1051#discussion_r154680084 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/work/foreman/rm/ThrottledResourceManager.java --- @@ -314,13 +315,49 @@ public void exit() { lease = null; } + @Override + public void cancel() { + if (queueAcquirerThread != null) { + queueAcquirerThread.interrupt(); + } + foreman.moveToState(QueryState.CANCELED, null); + } + @Override public boolean hasQueue() { return true; } @Override public String queueName() { return lease == null ? null : lease.queueName(); } + + /** + * Is used to start query enqueue process in separate thread. + * Changes query state depending on the result. + */ + private class QueueAcquirer implements Runnable { + + private final QueryQueue queryQueue; + private final Foreman foreman; + private final double queryCost; + + QueueAcquirer(QueryQueue queryQueue, Foreman foreman, double queryCost) { + this.queryQueue = queryQueue; + this.foreman = foreman; + this.queryCost = queryCost; + } + + @Override + public void run() { + try { + queryQueue.enqueue(foreman.getQueryId(), queryCost); + foreman.moveToState(QueryState.STARTING, null); + } catch (Exception e) { --- End diff -- Logic is removed.
---