Class 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 cause shouldExit() to return true the next time it is checked (it may be checked in either Lucene code or Solr code)
    • 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 interface org.apache.lucene.index.QueryTimeout
      • formatExceptionMessage

        public String formatExceptionMessage​(String label)
        Format an exception message with optional label and details from limitStatusMessage().
      • maybeExitWithPartialResults

        public boolean maybeExitWithPartialResults​(String label)
                                            throws QueryLimitsExceededException
        If limit is reached then depending on the request param CommonParams.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 - if CommonParams.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.
      • isLimitsEnabled

        public boolean isLimitsEnabled()
        Return true if there are any limits enabled for the current request.