Class QueryLimits

java.lang.Object
org.apache.solr.search.QueryLimits
All Implemented Interfaces:
org.apache.lucene.index.QueryTimeout

public final 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)
  • Field Details

  • Constructor Details

    • 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 Details

    • 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().
    • formatShardLimitExceptionMessage

      public String formatShardLimitExceptionMessage(String label, String shard, QueryLimit limit)
    • maybeExitWithPartialResults

      public boolean maybeExitWithPartialResults(Supplier<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 allowPartialResults is false and limits have been reached.
    • maybeExitWithPartialResults

      public boolean maybeExitWithPartialResults(String label) throws QueryLimitsExceededException
      Throws:
      QueryLimitsExceededException
    • 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.
    • 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 - if allowPartialResults is false and limits would have been tripped by the shard request.
    • getCurrentLimits

      public static QueryLimits getCurrentLimits()
      Helper method to retrieve the current QueryLimits from SolrRequestInfo.getRequestInfo() if it exists, otherwise it returns NONE.