Package org.apache.solr.search
Class QueryLimits
- java.lang.Object
-
- org.apache.solr.search.QueryLimits
-
- All Implemented Interfaces:
org.apache.lucene.index.QueryTimeout
public class QueryLimits extends Object implements 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 causeshouldExit()
to return true the next time it is checked (it may be checked in either Lucene code or Solr code)
-
-
Field Summary
Fields Modifier and Type Field Description static QueryLimits
NONE
-
Constructor Summary
Constructors Constructor Description QueryLimits(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<Object>
currentLimitValueFor(Class<? extends QueryLimit> limitClass)
String
formatExceptionMessage(String label)
Format an exception message with optional label and details fromlimitStatusMessage()
.static QueryLimits
getCurrentLimits()
Helper method to retrieve the current QueryLimits fromSolrRequestInfo.getRequestInfo()
if it exists, otherwise it returnsNONE
.boolean
isLimitsEnabled()
Return true if there are any limits enabled for the current request.String
limitStatusMessage()
Method to diagnose limit exceeded.boolean
maybeExitWithPartialResults(String label)
If limit is reached then depending on the request paramCommonParams.PARTIAL_RESULTS
either mark it as partial result in the response and signal the caller to return, or throw an exception.boolean
shouldExit()
-
-
-
Field Detail
-
NONE
public static QueryLimits NONE
-
-
Constructor Detail
-
QueryLimits
public QueryLimits(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.- Parameters:
req
- the current SolrQueryRequest.rsp
- the current SolrQueryResponse.
-
-
Method Detail
-
shouldExit
public boolean shouldExit()
- Specified by:
shouldExit
in interfaceorg.apache.lucene.index.QueryTimeout
-
formatExceptionMessage
public String formatExceptionMessage(String label)
Format an exception message with optional label and details fromlimitStatusMessage()
.
-
maybeExitWithPartialResults
public boolean maybeExitWithPartialResults(String label) throws QueryLimitsExceededException
If limit is reached then depending on the request paramCommonParams.PARTIAL_RESULTS
either 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
- ifCommonParams.PARTIAL_RESULTS
request parameter is false and limits have been reached.
-
limitStatusMessage
public String 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
public Optional<Object> currentLimitValueFor(Class<? extends QueryLimit> limitClass)
-
isLimitsEnabled
public boolean isLimitsEnabled()
Return true if there are any limits enabled for the current request.
-
getCurrentLimits
public static QueryLimits getCurrentLimits()
Helper method to retrieve the current QueryLimits fromSolrRequestInfo.getRequestInfo()
if it exists, otherwise it returnsNONE
.
-
-