Class TimeAllowedLimit

java.lang.Object
org.apache.solr.search.TimeAllowedLimit
All Implemented Interfaces:
org.apache.lucene.index.QueryTimeout, QueryLimit

public class TimeAllowedLimit extends Object implements QueryLimit
Enforces a wall clock based timeout on a given SolrQueryRequest. This class holds the logic for the timeAllowed query parameter. Note that timeAllowed will be ignored for local processing of sub-queries in cases where the parent query already has timeAllowed set. Essentially only one timeAllowed can be specified for any thread executing a query. This is to ensure that subqueries don't escape from the intended limit.

Distributed requests will approximately track the original starting point of the parent request. Shard requests may be skipped if the limit would run out shortly after they are sent - this in-flight allowance is determined by INFLIGHT_PARAM in milliseconds, with the default value of DEFAULT_INFLIGHT_MS.

  • Field Details

  • Constructor Details

    • TimeAllowedLimit

      public TimeAllowedLimit(SolrQueryRequest req)
      Create an object to represent a time limit for the current request.
      Parameters:
      req - A solr request that has a value for timeAllowed
      Throws:
      IllegalArgumentException - if the request does not contain timeAllowed parameter. This should be validated with hasTimeLimit(SolrQueryRequest) prior to constructing this object
  • Method Details

    • adjustShardRequestLimit

      public boolean adjustShardRequestLimit(ShardRequest sreq, String shard, org.apache.solr.common.params.ModifiableSolrParams params)
      Description copied from interface: QueryLimit
      Allow limit to adjust shard request parameters if needed.
      Specified by:
      adjustShardRequestLimit in interface QueryLimit
      Returns:
      true if the shard request should be skipped because a limit will be tripped after sending, during execution.
    • shouldExit

      public boolean shouldExit()
      Return true if a max limit value is set and the current usage has exceeded the limit.
      Specified by:
      shouldExit in interface org.apache.lucene.index.QueryTimeout
    • currentValue

      public Object currentValue()
      Return elapsed time in nanoseconds since this limit was started.
      Specified by:
      currentValue in interface QueryLimit
      Returns:
      an expression of the amount of the limit used so far, numeric if possible, if non-numeric it should have toString() suitable for logging or similar expression to the user.