Package org.apache.solr.search
Class QueryLimits
java.lang.Object
org.apache.solr.search.QueryLimits
- All Implemented Interfaces:
org.apache.lucene.index.QueryTimeout
Represents the limitations on the query. These limits might be wall clock time, cpu time, memory,
or other resource limits. Exceeding any specified limit will cause
shouldExit() to
return true the next time it is checked (it may be checked in either Lucene code or Solr code)-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionQueryLimits(SolrQueryRequest req, SolrQueryResponse rsp) Implementors of a Query Limit should add an if block here to activate it, and typically this if statement will hinge on hasXXXLimit() static method attached to the implementation class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadjustShardRequestLimits(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params, ResponseBuilder rb) Allow each limit to adjust the shard request parameters if needed.currentLimitValueFor(Class<? extends QueryLimit> limitClass) formatExceptionMessage(String label) Format an exception message with optional label and details fromlimitStatusMessage().formatShardLimitExceptionMessage(String label, String shard, QueryLimit limit) static QueryLimitsHelper method to retrieve the current QueryLimits fromSolrRequestInfo.getRequestInfo()if it exists, otherwise it returnsNONE.booleanReturn true if there are any limits enabled for the current request.Method to diagnose limit exceeded.booleanbooleanIf limit is reached then depending on the request paramCommonParams.PARTIAL_RESULTSeither mark it as partial result in the response and signal the caller to return, or throw an exception.boolean
-
Field Details
-
UNLIMITED
- See Also:
-
NONE
-
-
Constructor Details
-
QueryLimits
Implementors of a Query Limit should add an if block here to activate it, and typically this if statement will hinge on hasXXXLimit() static method attached to the implementation class.- Parameters:
req- the current SolrQueryRequest.rsp- the current SolrQueryResponse.
-
-
Method Details
-
shouldExit
public boolean shouldExit()- Specified by:
shouldExitin interfaceorg.apache.lucene.index.QueryTimeout
-
formatExceptionMessage
Format an exception message with optional label and details fromlimitStatusMessage(). -
formatShardLimitExceptionMessage
-
maybeExitWithPartialResults
public boolean maybeExitWithPartialResults(Supplier<String> label) throws QueryLimitsExceededException If limit is reached then depending on the request paramCommonParams.PARTIAL_RESULTSeither mark it as partial result in the response and signal the caller to return, or throw an exception.- Parameters:
label- optional label to indicate the caller.- Returns:
- true if the caller should stop processing and return partial results, false otherwise.
- Throws:
QueryLimitsExceededException- ifallowPartialResultsis false and limits have been reached.
-
maybeExitWithPartialResults
- Throws:
QueryLimitsExceededException
-
limitStatusMessage
Method to diagnose limit exceeded. Note that while this should always list the exceeded limit, it may also nominate additional limits that have been exceeded since the actual check that cause the failure. This gap is intentional to avoid overly complicated (and possibly expensive) tracking code that would have to run within the shouldExit method. This method should only be used to report a failure since it incurs the cost of rechecking every configured limit and does not short circuit.- Returns:
- A string describing the state pass/fail state of each limit specified for this request.
-
currentLimitValueFor
-
isLimitsEnabled
public boolean isLimitsEnabled()Return true if there are any limits enabled for the current request. -
adjustShardRequestLimits
public boolean adjustShardRequestLimits(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params, ResponseBuilder rb) throws QueryLimitsExceededException Allow each limit to adjust the shard request parameters if needed. This is useful for timeAllowed, cpu, or memory limits that need to be propagated to shards with potentially modified values.- Returns:
- true if the shard request should be skipped because one or more limits would be tripped after sending, during execution.
- Throws:
QueryLimitsExceededException- ifallowPartialResultsis false and limits would have been tripped by the shard request.
-
getCurrentLimits
Helper method to retrieve the current QueryLimits fromSolrRequestInfo.getRequestInfo()if it exists, otherwise it returnsNONE.
-