Commit 5d440eb9 authored by TousakaRin's avatar TousakaRin

Change isolated_times to atomic variable

parent aaf20ce8
......@@ -184,7 +184,7 @@ void CircuitBreaker::Reset() {
void CircuitBreaker::MarkAsBroken() {
if (_broken.exchange(true, butil::memory_order_acquire)) {
++_isolated_times;
_isolated_times.fetch_add(butil::memory_order_relaxed);
UpdateIsolationDuration();
}
}
......@@ -194,17 +194,20 @@ int CircuitBreaker::health_score() const {
}
void CircuitBreaker::UpdateIsolationDuration() {
int isolation_duration_ms = _isolation_duration_ms.load(butil::memory_order_relaxed);
int64_t now_time_ms = butil::cpuwide_time_ms();
const int max_isolation_duration_ms =
FLAGS_circuit_breaker_max_isolation_duration_ms;
const int min_isolation_duration_ms =
FLAGS_circuit_breaker_min_isolation_duration_ms;
if (now_time_ms - _last_reset_time_ms < max_isolation_duration_ms) {
_isolation_duration_ms =
std::min(_isolation_duration_ms * 2, max_isolation_duration_ms);
isolation_duration_ms =
std::min(isolation_duration_ms * 2, max_isolation_duration_ms);
} else {
_isolation_duration_ms = min_isolation_duration_ms;
isolation_duration_ms = min_isolation_duration_ms;
}
_isolation_duration_ms.store(isolation_duration_ms, butil::memory_order_relaxed);
}
} // namespace brpc
......@@ -52,13 +52,13 @@ public:
// Number of times marked as broken
int isolated_times() const {
return _isolated_times;
return _isolated_times.load(butil::memory_order_relaxed);
}
// The duration that should be isolated when the socket fails in milliseconds.
// The higher the frequency of socket errors, the longer the duration.
int isolation_duration_ms() const {
return _isolation_duration_ms;
return _isolation_duration_ms.load(butil::memory_order_relaxed);
}
private:
......@@ -89,8 +89,8 @@ private:
EmaErrorRecorder _long_window;
EmaErrorRecorder _short_window;
int64_t _last_reset_time_ms;
int _isolation_duration_ms;
int _isolated_times;
butil::atomic<int> _isolation_duration_ms;
butil::atomic<int> _isolated_times;
butil::atomic<bool> _broken;
};
......
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