Interface CircuitBreaker

All Known Implementing Classes:
ChildMemoryCircuitBreaker, NoopCircuitBreaker

public interface CircuitBreaker
Interface for an object that can be incremented, breaking after some configured limit has been reached.
  • Field Details

    • PARENT

      static final String PARENT
      The parent breaker is a sum of all the following breakers combined. With this we allow a single breaker to have a significant amount of memory available while still having a "total" limit for all breakers. Note that it's not a "real" breaker in that it cannot be added to or subtracted from by itself.
      See Also:
    • FIELDDATA

      static final String FIELDDATA
      The fielddata breaker tracks data used for fielddata (on fields) as well as the id cached used for parent/child queries.
      See Also:
    • REQUEST

      static final String REQUEST
      The request breaker tracks memory used for particular requests. This includes allocations for things like the cardinality aggregation, and accounting for the number of buckets used in an aggregation request. Generally the amounts added to this breaker are released after a request is finished.
      See Also:
    • IN_FLIGHT_REQUESTS

      static final String IN_FLIGHT_REQUESTS
      The in-flight request breaker tracks bytes allocated for reading and writing requests on the network layer.
      See Also:
    • ACCOUNTING

      static final String ACCOUNTING
      The accounting breaker tracks things held in memory that is independent of the request lifecycle. This includes memory used by Lucene for segments.
      See Also:
  • Method Details

    • circuitBreak

      void circuitBreak(String fieldName, long bytesNeeded)
      Trip the circuit breaker
      Parameters:
      fieldName - name of the field responsible for tripping the breaker
      bytesNeeded - bytes asked for but unable to be allocated
    • addEstimateBytesAndMaybeBreak

      void addEstimateBytesAndMaybeBreak(long bytes, String label) throws CircuitBreakingException
      Add bytes to the breaker and trip if the that puts breaker over the limit.
      Parameters:
      bytes - number of bytes to add
      label - thing requesting the bytes being added that is included in the exception if the breaker is tripped
      Throws:
      CircuitBreakingException
    • addWithoutBreaking

      void addWithoutBreaking(long bytes)
      Add bytes to the circuit breaker without tripping.
    • getUsed

      long getUsed()
      Returns:
      the currently used bytes the breaker is tracking
    • getLimit

      long getLimit()
      Returns:
      maximum number of bytes the circuit breaker can track before tripping
    • getOverhead

      double getOverhead()
      Returns:
      overhead of circuit breaker
    • getTrippedCount

      long getTrippedCount()
      Returns:
      the number of times the circuit breaker has been tripped
    • getName

      String getName()
      Returns:
      the name of the breaker
    • getDurability

      CircuitBreaker.Durability getDurability()
      Returns:
      whether a tripped circuit breaker will reset itself (transient) or requires manual intervention (permanent).
    • setLimitAndOverhead

      void setLimitAndOverhead(long limit, double overhead)
      sets the new limit and overhead values for the circuit breaker. The resulting write should be readable by other threads.
      Parameters:
      limit - the desired limit
      overhead - the desired overhead constant