Class CircuitBreakingOperations

java.lang.Object
org.elasticsearch.lucene.util.automaton.CircuitBreakingOperations

public final class CircuitBreakingOperations extends Object
Provides a circuit-breaker-aware variant of Operations.determinize(Automaton, int).

Lucene's Operations.determinize can allocate memory proportional to the powerset of the NFA states, which grows exponentially for certain patterns (e.g. .*a.*b.*c.*d.*). The standard effort-based work limit (TooComplexToDeterminizeException) bounds CPU work but does not directly bound memory. This class periodically estimates the memory consumed by the growing DFA and intermediate data structures, checking the circuit breaker so that construction is aborted before an OOM can occur.

The helper classes below (IntSet, FrozenIntSet, StateSet, etc.) are copied from Lucene's package-private internals because they cannot be accessed from outside org.apache.lucene.util.automaton.

See Also:
  • Method Details

    • determinize

      public static org.apache.lucene.util.automaton.Automaton determinize(org.apache.lucene.util.automaton.Automaton a, int workLimit, CircuitBreaker circuitBreaker, String label)
      Determinizes the given automaton, periodically checking the provided circuit breaker.

      This is functionally equivalent to Operations.determinize(Automaton, int) but adds memory accounting. Temporary memory reserved on the breaker during construction is released before returning (or in the finally block on exception). The caller is responsible for accounting the final automaton's ramBytesUsed() separately.

      Parameters:
      a - the NFA to determinize
      workLimit - maximum "effort" before throwing TooComplexToDeterminizeException
      circuitBreaker - the circuit breaker to check (must not be null)
      label - descriptive label for circuit breaker error messages
      Returns:
      the determinized automaton
      Throws:
      org.apache.lucene.util.automaton.TooComplexToDeterminizeException - if effort exceeds workLimit
      CircuitBreakingException - if the breaker trips