Commit 1ff59abf authored by TousakaRin's avatar TousakaRin

Remove EmaRecorder::_broken

parent 09b75b5d
...@@ -61,16 +61,11 @@ CircuitBreaker::EmaErrorRecorder::EmaErrorRecorder(int window_size, ...@@ -61,16 +61,11 @@ CircuitBreaker::EmaErrorRecorder::EmaErrorRecorder(int window_size,
, _smooth(std::pow(EPSILON, 1.0/window_size)) , _smooth(std::pow(EPSILON, 1.0/window_size))
, _sample_count(0) , _sample_count(0)
, _ema_error_cost(0) , _ema_error_cost(0)
, _ema_latency(0) , _ema_latency(0) {
, _broken(false) {
} }
bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code, bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code,
int64_t latency) { int64_t latency) {
if (_broken.load(butil::memory_order_relaxed)) {
return false;
}
int64_t ema_latency = 0; int64_t ema_latency = 0;
bool healthy = false; bool healthy = false;
if (error_code == 0) { if (error_code == 0) {
...@@ -85,9 +80,6 @@ bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code, ...@@ -85,9 +80,6 @@ bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code,
return true; return true;
} }
if (!healthy) {
_broken.store(true, butil::memory_order_relaxed);
}
return healthy; return healthy;
} }
...@@ -95,7 +87,6 @@ void CircuitBreaker::EmaErrorRecorder::Reset() { ...@@ -95,7 +87,6 @@ void CircuitBreaker::EmaErrorRecorder::Reset() {
_sample_count.store(0, butil::memory_order_relaxed); _sample_count.store(0, butil::memory_order_relaxed);
_ema_error_cost.store(0, butil::memory_order_relaxed); _ema_error_cost.store(0, butil::memory_order_relaxed);
_ema_latency.store(0, butil::memory_order_relaxed); _ema_latency.store(0, butil::memory_order_relaxed);
_broken.store(false, butil::memory_order_relaxed);
} }
int64_t CircuitBreaker::EmaErrorRecorder::UpdateLatency(int64_t latency) { int64_t CircuitBreaker::EmaErrorRecorder::UpdateLatency(int64_t latency) {
...@@ -161,13 +152,13 @@ CircuitBreaker::CircuitBreaker() ...@@ -161,13 +152,13 @@ CircuitBreaker::CircuitBreaker()
} }
bool CircuitBreaker::OnCallEnd(int error_code, int64_t latency) { bool CircuitBreaker::OnCallEnd(int error_code, int64_t latency) {
if(_long_window.OnCallEnd(error_code, latency) && if (_broken.load(butil::memory_order_relaxed) ||
_short_window.OnCallEnd(error_code, latency)) { !_long_window.OnCallEnd(error_code, latency) ||
return true; !_short_window.OnCallEnd(error_code, latency)) {
} else {
UpdateIsolationDuration(); UpdateIsolationDuration();
return false; return false;
} }
return true;
} }
void CircuitBreaker::Reset() { void CircuitBreaker::Reset() {
......
...@@ -67,7 +67,6 @@ private: ...@@ -67,7 +67,6 @@ private:
butil::atomic<int64_t> BAIDU_CACHELINE_ALIGNMENT _sample_count; butil::atomic<int64_t> BAIDU_CACHELINE_ALIGNMENT _sample_count;
butil::atomic<int64_t> _ema_error_cost; butil::atomic<int64_t> _ema_error_cost;
butil::atomic<int64_t> _ema_latency; butil::atomic<int64_t> _ema_latency;
butil::atomic<bool> _broken;
}; };
EmaErrorRecorder _long_window; EmaErrorRecorder _long_window;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment