From d1e721de0519db2fbc01916aaba2ca91c2189915 Mon Sep 17 00:00:00 2001 From: XieHan Date: Mon, 17 Jan 2022 22:56:05 +0800 Subject: [PATCH] remove 'nalives' check and update strategy. --- src/nameservice/UpstreamPolicies.cc | 10 +++------- src/nameservice/WFServiceGovernance.cc | 13 +++++++++++-- src/nameservice/WFServiceGovernance.h | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/nameservice/UpstreamPolicies.cc b/src/nameservice/UpstreamPolicies.cc index 87048043..0d3959f3 100644 --- a/src/nameservice/UpstreamPolicies.cc +++ b/src/nameservice/UpstreamPolicies.cc @@ -167,11 +167,6 @@ bool UPSGroupPolicy::select(const ParsedURI& uri, WFNSTracing *tracing, } this->check_breaker(); - if (this->nalives == 0) - { - pthread_rwlock_unlock(&this->rwlock); - return false; - } // select_addr == NULL will only happened in consistent_hash EndpointAddress *select_addr = this->first_strategy(uri, tracing); @@ -510,9 +505,10 @@ EndpointAddress *UPSWeightedRandomPolicy::first_strategy(const ParsedURI& uri, EndpointAddress *UPSWeightedRandomPolicy::another_strategy(const ParsedURI& uri, WFNSTracing *tracing) { - /* When all servers down, recover all. */ + /* When all servers are down, recover all servers if any server + * reaches fusing timeout. */ if (this->available_weight == 0) - this->clear_breaker(); + this->try_clear_breaker(); int temp_weight = this->available_weight; if (temp_weight == 0) diff --git a/src/nameservice/WFServiceGovernance.cc b/src/nameservice/WFServiceGovernance.cc index 3964b2d5..aacb7d47 100644 --- a/src/nameservice/WFServiceGovernance.cc +++ b/src/nameservice/WFServiceGovernance.cc @@ -274,6 +274,8 @@ void WFServiceGovernance::check_breaker_locked(int64_t cur_time) list_del(pos); pos->next = NULL; } + else + break; } } @@ -285,10 +287,17 @@ void WFServiceGovernance::check_breaker() pthread_mutex_unlock(&this->breaker_lock); } -void WFServiceGovernance::clear_breaker() +void WFServiceGovernance::try_clear_breaker() { pthread_mutex_lock(&this->breaker_lock); - this->check_breaker_locked(INT64_MAX); + if (!list_empty(&this->breaker_list)) + { + struct list_head *pos = this->breaker_list.next; + struct EndpointAddress::address_entry *entry; + entry = list_entry(pos, struct EndpointAddress::address_entry, list); + if (GET_CURRENT_SECOND >= entry->ptr->broken_timeout) + this->check_breaker_locked(INT64_MAX); + } pthread_mutex_unlock(&this->breaker_lock); } diff --git a/src/nameservice/WFServiceGovernance.h b/src/nameservice/WFServiceGovernance.h index 9e21da34..f5fc24c4 100644 --- a/src/nameservice/WFServiceGovernance.h +++ b/src/nameservice/WFServiceGovernance.h @@ -175,8 +175,8 @@ protected: WFNSTracing *tracing); virtual EndpointAddress *another_strategy(const ParsedURI& uri, WFNSTracing *tracing); - void clear_breaker(); void check_breaker(); + void try_clear_breaker(); void pre_delete_server(EndpointAddress *addr); struct TracingData