Class MemAllowedLimit

  • All Implemented Interfaces:
    org.apache.lucene.index.QueryTimeout, QueryLimit

    public class MemAllowedLimit
    extends Object
    implements QueryLimit
    Enforces a memory-based limit on a given SolrQueryRequest, as specified by the memAllowed query parameter.

    This class tracks per-thread memory allocations during a request using its own ThreadLocal. It records the current thread allocation when the instance was created (typically at the start of SolrQueryRequest processing) as a starting point, and then on every call to shouldExit() it accumulates the amount of reported allocated memory since the previous call, and compares the accumulated amount to the configured threshold, expressed in mebi-bytes.

    NOTE: this class accesses com.sun.management.ThreadMXBean#getCurrentThreadAllocatedBytes using reflection. On JVM-s where this implementation is not available an exception will be thrown when attempting to use the memAllowed parameter.

    • Method Detail

      • shouldExit

        public boolean shouldExit()
        Specified by:
        shouldExit in interface org.apache.lucene.index.QueryTimeout
      • currentValue

        public Object currentValue()
        Description copied from interface: QueryLimit
        A value representing the portion of the specified limit that has been consumed. Reading this value should never affect the outcome (other than the time it takes to do it).
        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.