Class QueryScheduler

  • All Implemented Interfaces:
    org.apache.druid.query.QueryWatcher

    public class QueryScheduler
    extends Object
    implements org.apache.druid.query.QueryWatcher
    QueryScheduler (potentially) assigns any Query that is to be executed to a 'query lane' using the QueryLaningStrategy that is defined in QuerySchedulerConfig. As a QueryWatcher, it also provides cancellation facilities to brokers, historicals, and realtime tasks. This class is shared by all requests on the HTTP theadpool and must be thread safe.
    • Method Detail

      • registerQueryFuture

        public void registerQueryFuture​(org.apache.druid.query.Query<?> query,
                                        com.google.common.util.concurrent.ListenableFuture<?> future)
        Specified by:
        registerQueryFuture in interface org.apache.druid.query.QueryWatcher
      • prioritizeAndLaneQuery

        public <T> org.apache.druid.query.Query<T> prioritizeAndLaneQuery​(org.apache.druid.query.QueryPlus<T> queryPlus,
                                                                          Set<SegmentServerSelector> segments)
        Assign a query a priority and lane (if not set)
      • run

        public <T> org.apache.druid.java.util.common.guava.Sequence<T> run​(org.apache.druid.query.Query<?> query,
                                                                           org.apache.druid.java.util.common.guava.Sequence<T> resultSequence)
        Run a query with the scheduler, attempting to acquire a semaphore from the total and lane specific query capacities Note that cancelQuery(java.lang.String) should not interrupt the thread that calls run, in all current usages it only cancels any ListenableFuture created downstream. If this ever commonly changes, we should add synchronization between cancelQuery(java.lang.String) and the acquisition of the Bulkhead to continue to ensure that anything acquired is also released. In the meantime, if a ListenableFuture is registered for the query that calls this method, it MUST handle this synchronization itself to ensure that no Bulkhead is acquired without releasing it.
      • cancelQuery

        public boolean cancelQuery​(String id)
        Forcibly cancel all futures that have been registered to a specific query id