Package org.apache.druid.server
Class QueryScheduler
- java.lang.Object
-
- org.apache.druid.server.QueryScheduler
-
- All Implemented Interfaces:
org.apache.druid.query.QueryWatcher
public class QueryScheduler extends Object implements org.apache.druid.query.QueryWatcher
QueryScheduler (potentially) assigns anyQuerythat is to be executed to a 'query lane' using theQueryLaningStrategythat is defined inQuerySchedulerConfig. As aQueryWatcher, 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.
-
-
Field Summary
Fields Modifier and Type Field Description static StringTOTALstatic intUNAVAILABLE
-
Constructor Summary
Constructors Constructor Description QueryScheduler(int totalNumThreads, QueryPrioritizationStrategy prioritizationStrategy, QueryLaningStrategy laningStrategy, ServerConfig serverConfig)Keeping the old constructor as many test classes are dependent on thisQueryScheduler(int totalNumThreads, QueryPrioritizationStrategy prioritizationStrategy, QueryLaningStrategy laningStrategy, ServerConfig serverConfig, org.apache.druid.java.util.emitter.service.ServiceEmitter emitter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancelQuery(String id)Forcibly cancel all futures that have been registered to a specific query idSet<String>getQueryDatasources(String queryId)Get aSetof datasource names for aQueryid, used byQueryResource.cancelQuery(java.lang.String, javax.servlet.http.HttpServletRequest)to authorize that a user may callcancelQuery(java.lang.String)for the given id and datasources<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)voidregisterQueryFuture(org.apache.druid.query.Query<?> query, com.google.common.util.concurrent.ListenableFuture<?> future)<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 thatcancelQuery(java.lang.String)should not interrupt the thread that calls run, in all current usages it only cancels anyListenableFuturecreated downstream.<T> org.apache.druid.query.QueryRunner<T>wrapQueryRunner(org.apache.druid.query.QueryRunner<T> baseRunner)Returns aQueryRunnerthat will callrun(org.apache.druid.query.Query<?>, org.apache.druid.java.util.common.guava.Sequence<T>)whenQueryRunner.run(org.apache.druid.query.QueryPlus<T>, org.apache.druid.query.context.ResponseContext)is called.
-
-
-
Field Detail
-
UNAVAILABLE
public static final int UNAVAILABLE
- See Also:
- Constant Field Values
-
TOTAL
public static final String TOTAL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QueryScheduler
public QueryScheduler(int totalNumThreads, QueryPrioritizationStrategy prioritizationStrategy, QueryLaningStrategy laningStrategy, ServerConfig serverConfig, org.apache.druid.java.util.emitter.service.ServiceEmitter emitter)
-
QueryScheduler
public QueryScheduler(int totalNumThreads, QueryPrioritizationStrategy prioritizationStrategy, QueryLaningStrategy laningStrategy, ServerConfig serverConfig)Keeping the old constructor as many test classes are dependent on this
-
-
Method Detail
-
registerQueryFuture
public void registerQueryFuture(org.apache.druid.query.Query<?> query, com.google.common.util.concurrent.ListenableFuture<?> future)- Specified by:
registerQueryFuturein interfaceorg.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 thatcancelQuery(java.lang.String)should not interrupt the thread that calls run, in all current usages it only cancels anyListenableFuturecreated downstream. If this ever commonly changes, we should add synchronization betweencancelQuery(java.lang.String)and the acquisition of theBulkheadto continue to ensure that anything acquired is also released. In the meantime, if aListenableFutureis registered for the query that calls this method, it MUST handle this synchronization itself to ensure that noBulkheadis acquired without releasing it.
-
wrapQueryRunner
public <T> org.apache.druid.query.QueryRunner<T> wrapQueryRunner(org.apache.druid.query.QueryRunner<T> baseRunner)
Returns aQueryRunnerthat will callrun(org.apache.druid.query.Query<?>, org.apache.druid.java.util.common.guava.Sequence<T>)whenQueryRunner.run(org.apache.druid.query.QueryPlus<T>, org.apache.druid.query.context.ResponseContext)is called.
-
cancelQuery
public boolean cancelQuery(String id)
Forcibly cancel all futures that have been registered to a specific query id
-
getQueryDatasources
public Set<String> getQueryDatasources(String queryId)
Get aSetof datasource names for aQueryid, used byQueryResource.cancelQuery(java.lang.String, javax.servlet.http.HttpServletRequest)to authorize that a user may callcancelQuery(java.lang.String)for the given id and datasources
-
-