MCPcopy Create free account
hub / github.com/apache/brpc / OnCallEnd

Method OnCallEnd

src/brpc/circuit_breaker.cpp:83–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code,
84 int64_t latency) {
85 int64_t ema_latency = 0;
86 bool healthy = false;
87 if (error_code == 0) {
88 ema_latency = UpdateLatency(latency);
89 healthy = UpdateErrorCost(0, ema_latency);
90 } else {
91 ema_latency = _ema_latency.load(butil::memory_order_relaxed);
92 healthy = UpdateErrorCost(latency, ema_latency);
93 }
94
95 // When the window is initializing, use error_rate to determine
96 // if it needs to be isolated.
97 if (_sample_count_when_initializing.load(butil::memory_order_relaxed) < _window_size &&
98 _sample_count_when_initializing.fetch_add(1, butil::memory_order_relaxed) < _window_size) {
99 if (error_code != 0) {
100 const int32_t error_count =
101 _error_count_when_initializing.fetch_add(1, butil::memory_order_relaxed);
102 return error_count < _window_size * _max_error_percent / 100;
103 }
104 // Because once OnCallEnd returned false, the node will be ioslated soon,
105 // so when error_code=0, we no longer check the error count.
106 return true;
107 }
108
109 return healthy;
110}
111
112void CircuitBreaker::EmaErrorRecorder::Reset() {
113 if (_sample_count_when_initializing.load(butil::memory_order_relaxed) < _window_size) {

Callers 2

feed_back_threadMethod · 0.80

Calls 3

fetch_addMethod · 0.80
loadMethod · 0.45
storeMethod · 0.45

Tested by 1

feed_back_threadMethod · 0.64