Package org.elasticsearch.common.breaker
Class MemoryCircuitBreaker
- java.lang.Object
-
- org.elasticsearch.common.breaker.MemoryCircuitBreaker
-
- All Implemented Interfaces:
CircuitBreaker
public class MemoryCircuitBreaker extends java.lang.Object implements CircuitBreaker
MemoryCircuitBreaker is a circuit breaker that breaks once a configurable memory limit has been reached.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.breaker.CircuitBreaker
CircuitBreaker.Type
-
-
Field Summary
-
Fields inherited from interface org.elasticsearch.common.breaker.CircuitBreaker
ACCOUNTING, FIELDDATA, IN_FLIGHT_REQUESTS, PARENT, REQUEST
-
-
Constructor Summary
Constructors Constructor Description MemoryCircuitBreaker(ByteSizeValue limit, double overheadConstant, org.apache.logging.log4j.Logger logger)
Create a circuit breaker that will break if the number of estimated bytes grows above the limit.MemoryCircuitBreaker(ByteSizeValue limit, double overheadConstant, MemoryCircuitBreaker oldBreaker, org.apache.logging.log4j.Logger logger)
Create a circuit breaker that will break if the number of estimated bytes grows above the limit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
addEstimateBytesAndMaybeBreak(long bytes, java.lang.String label)
Add a number of bytes, tripping the circuit breaker if the aggregated estimates are above the limit.long
addWithoutBreaking(long bytes)
Add an exact number of bytes, not checking for tripping the circuit breaker.void
circuitBreak(java.lang.String fieldName, long bytesNeeded)
Method used to trip the breakerlong
getLimit()
java.lang.String
getName()
double
getOverhead()
long
getTrippedCount()
long
getUsed()
-
-
-
Constructor Detail
-
MemoryCircuitBreaker
public MemoryCircuitBreaker(ByteSizeValue limit, double overheadConstant, org.apache.logging.log4j.Logger logger)
Create a circuit breaker that will break if the number of estimated bytes grows above the limit. All estimations will be multiplied by the given overheadConstant. This breaker starts with 0 bytes used.- Parameters:
limit
- circuit breaker limitoverheadConstant
- constant multiplier for byte estimations
-
MemoryCircuitBreaker
public MemoryCircuitBreaker(ByteSizeValue limit, double overheadConstant, MemoryCircuitBreaker oldBreaker, org.apache.logging.log4j.Logger logger)
Create a circuit breaker that will break if the number of estimated bytes grows above the limit. All estimations will be multiplied by the given overheadConstant. Uses the given oldBreaker to initialize the starting offset.- Parameters:
limit
- circuit breaker limitoverheadConstant
- constant multiplier for byte estimationsoldBreaker
- the previous circuit breaker to inherit the used value from (starting offset)
-
-
Method Detail
-
circuitBreak
public void circuitBreak(java.lang.String fieldName, long bytesNeeded) throws CircuitBreakingException
Method used to trip the breaker- Specified by:
circuitBreak
in interfaceCircuitBreaker
- Parameters:
fieldName
- name of the field responsible for tripping the breakerbytesNeeded
- bytes asked for but unable to be allocated- Throws:
CircuitBreakingException
-
addEstimateBytesAndMaybeBreak
public double addEstimateBytesAndMaybeBreak(long bytes, java.lang.String label) throws CircuitBreakingException
Add a number of bytes, tripping the circuit breaker if the aggregated estimates are above the limit. Automatically trips the breaker if the memory limit is set to 0. Will never trip the breaker if the limit is set < 0, but can still be used to aggregate estimations.- Specified by:
addEstimateBytesAndMaybeBreak
in interfaceCircuitBreaker
- Parameters:
bytes
- number of bytes to add to the breakerlabel
- string label describing the bytes being added- Returns:
- number of "used" bytes so far
- Throws:
CircuitBreakingException
-
addWithoutBreaking
public long addWithoutBreaking(long bytes)
Add an exact number of bytes, not checking for tripping the circuit breaker. This bypasses the overheadConstant multiplication.- Specified by:
addWithoutBreaking
in interfaceCircuitBreaker
- Parameters:
bytes
- number of bytes to add to the breaker- Returns:
- number of "used" bytes so far
-
getUsed
public long getUsed()
- Specified by:
getUsed
in interfaceCircuitBreaker
- Returns:
- the number of aggregated "used" bytes so far
-
getLimit
public long getLimit()
- Specified by:
getLimit
in interfaceCircuitBreaker
- Returns:
- the number of bytes that can be added before the breaker trips
-
getOverhead
public double getOverhead()
- Specified by:
getOverhead
in interfaceCircuitBreaker
- Returns:
- the constant multiplier the breaker uses for aggregations
-
getTrippedCount
public long getTrippedCount()
- Specified by:
getTrippedCount
in interfaceCircuitBreaker
- Returns:
- the number of times the breaker has been tripped
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfaceCircuitBreaker
- Returns:
- the name of the breaker
-
-