Interface CircuitBreaker
- All Known Implementing Classes:
NoopCircuitBreaker
@PublicApi(since="1.0.0")
public interface CircuitBreaker
Interface for an object that can be incremented, breaking after some
configured limit has been reached.
- Opensearch.api:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe breaker durability can beCircuitBreaker.Durability.TRANSIENTorCircuitBreaker.Durability.PERMANENTstatic enumThe type of breaker can beCircuitBreaker.Type.MEMORY,CircuitBreaker.Type.PARENT, orCircuitBreaker.Type.NOOP -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe fielddata breaker tracks data used for fielddata (on fields) as well as the id cached used for parent/child queries.static final StringThe in-flight request breaker tracks bytes allocated for reading and writing requests on the network layer.static final StringThe parent breaker is a sum of all the following breakers combined.static final StringThe request breaker tracks memory used for particular requests. -
Method Summary
Modifier and TypeMethodDescriptiondoubleaddEstimateBytesAndMaybeBreak(long bytes, String label) add bytes to the breaker and maybe triplongaddWithoutBreaking(long bytes) Adjust the circuit breaker without trippingvoidcircuitBreak(String fieldName, long bytesNeeded) Trip the circuit breakerReturns theCircuitBreaker.Durabilityof this breakerlonggetLimit()getName()doublelonglonggetUsed()voidsetLimitAndOverhead(long limit, double overhead) sets the new limit and overhead values for the circuit breaker.
-
Field Details
-
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
The fielddata breaker tracks data used for fielddata (on fields) as well as the id cached used for parent/child queries.- See Also:
-
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
The in-flight request breaker tracks bytes allocated for reading and writing requests on the network layer.- See Also:
-
-
Method Details
-
circuitBreak
Trip the circuit breaker- Parameters:
fieldName- name of the field responsible for tripping the breakerbytesNeeded- bytes asked for but unable to be allocated
-
addEstimateBytesAndMaybeBreak
add bytes to the breaker and maybe trip- Parameters:
bytes- number of bytes to addlabel- string label describing the bytes being added- Returns:
- the number of "used" bytes for the circuit breaker
- Throws:
CircuitBreakingException- if the breaker tripped
-
addWithoutBreaking
long addWithoutBreaking(long bytes) Adjust the circuit breaker without tripping- Parameters:
bytes- number of bytes to add- Returns:
- the number of "used" bytes for the circuit breaker
-
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 theCircuitBreaker.Durabilityof this breaker- Returns:
- whether a tripped circuit breaker will
reset itself (
CircuitBreaker.Durability.TRANSIENT) or requires manual intervention (CircuitBreaker.Durability.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 limitoverhead- the desired overhead constant
-