From 6e39f0398dc7a308c08330ecf4348aa5c8614f46 Mon Sep 17 00:00:00 2001 From: zhujiashun Date: Thu, 27 Jun 2019 11:45:36 +0800 Subject: [PATCH 1/2] fix lalb be disabled wrongly --- src/brpc/policy/locality_aware_load_balancer.cpp | 2 +- src/brpc/policy/locality_aware_load_balancer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/brpc/policy/locality_aware_load_balancer.cpp b/src/brpc/policy/locality_aware_load_balancer.cpp index 7a3cb3e628..e5d91fd6db 100644 --- a/src/brpc/policy/locality_aware_load_balancer.cpp +++ b/src/brpc/policy/locality_aware_load_balancer.cpp @@ -555,7 +555,7 @@ LocalityAwareLoadBalancer::Weight::~Weight() { int64_t LocalityAwareLoadBalancer::Weight::Disable() { BAIDU_SCOPED_LOCK(_mutex); const int64_t saved = _weight; - _base_weight = 0; + _base_weight = -1; _weight = 0; return saved; } diff --git a/src/brpc/policy/locality_aware_load_balancer.h b/src/brpc/policy/locality_aware_load_balancer.h index 3c269d8f20..65246370e9 100644 --- a/src/brpc/policy/locality_aware_load_balancer.h +++ b/src/brpc/policy/locality_aware_load_balancer.h @@ -86,7 +86,7 @@ class LocalityAwareLoadBalancer : public LoadBalancer { void Describe(std::ostream& os, int64_t now); int64_t Disable(); - bool Disabled() const { return _base_weight == 0; } + bool Disabled() const { return _base_weight == -1; } int64_t MarkOld(size_t index); std::pair ClearOld(); From d4cc3f3fd2eca18380a15726d5d8d710c7a01c72 Mon Sep 17 00:00:00 2001 From: zhujiashun Date: Thu, 27 Jun 2019 12:50:52 +0800 Subject: [PATCH 2/2] Make the condition of lalb::Disabled be _base_weight < 0 --- src/brpc/policy/locality_aware_load_balancer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/brpc/policy/locality_aware_load_balancer.h b/src/brpc/policy/locality_aware_load_balancer.h index 65246370e9..8da16c0378 100644 --- a/src/brpc/policy/locality_aware_load_balancer.h +++ b/src/brpc/policy/locality_aware_load_balancer.h @@ -86,7 +86,7 @@ class LocalityAwareLoadBalancer : public LoadBalancer { void Describe(std::ostream& os, int64_t now); int64_t Disable(); - bool Disabled() const { return _base_weight == -1; } + bool Disabled() const { return _base_weight < 0; } int64_t MarkOld(size_t index); std::pair ClearOld();