update codes

This commit is contained in:
holmes1412
2021-08-11 21:32:52 +08:00
parent 822e9c2c18
commit 2c19c8ee87
3 changed files with 13 additions and 16 deletions
+11 -11
View File
@@ -106,7 +106,7 @@ UPSGroupPolicy::~UPSGroupPolicy()
}
}
inline bool UPSGroupPolicy::is_alive_or_group_alive(const EndpointAddress *addr) const
inline bool UPSGroupPolicy::is_alive(const EndpointAddress *addr) const
{
UPSAddrParams *params = static_cast<UPSAddrParams *>(addr->params);
return ((params->group_id < 0 &&
@@ -203,9 +203,9 @@ bool UPSGroupPolicy::select(const ParsedURI& uri, WFNSTracing *tracing,
* false: means addr maybe group-alive.
* If addr is not available, get one from addr->group.
*/
inline EndpointAddress *UPSGroupPolicy::check_and_get(EndpointAddress *addr,
bool flag,
WFNSTracing *tracing)
EndpointAddress *UPSGroupPolicy::check_and_get(EndpointAddress *addr,
bool flag,
WFNSTracing *tracing)
{
UPSAddrParams *params = static_cast<UPSAddrParams *>(addr->params);
@@ -365,6 +365,11 @@ int UPSGroupPolicy::remove_server_locked(const std::string& address)
//std::lock_guard<std::mutex> lock(group->mutex);
pthread_mutex_lock(&group->mutex);
if (addr->fail_count < params->max_fails)
this->fuse_one_server(addr);
else
this->remove_server_from_breaker(addr);
if (params->server_type == 0)
group->weight -= params->weight;
@@ -377,11 +382,6 @@ int UPSGroupPolicy::remove_server_locked(const std::string& address)
}
}
if (addr->fail_count < params->max_fails)
this->fuse_one_server(addr);
else
this->remove_server_from_breaker(addr);
this->server_list_change(addr, REMOVE_SERVER);
remove_list.push_back(addr);
pthread_mutex_unlock(&group->mutex);
@@ -428,7 +428,7 @@ EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash)
for (EndpointAddress *server : this->servers)
{
if (this->is_alive_or_group_alive(server))
if (this->is_alive(server))
{
params = static_cast<UPSAddrParams *>(server->params);
@@ -550,7 +550,7 @@ EndpointAddress *UPSWeightedRandomPolicy::another_strategy(const ParsedURI& uri,
for (EndpointAddress *server : this->servers)
{
if (this->is_alive_or_group_alive(server))
if (this->is_alive(server))
{
addr = server;
params = static_cast<UPSAddrParams *>(server->params);
+1 -1
View File
@@ -78,7 +78,7 @@ protected:
EndpointAddress *check_and_get(EndpointAddress *addr,
bool flag, WFNSTracing *tracing);
bool is_alive_or_group_alive(const EndpointAddress *addr) const;
bool is_alive(const EndpointAddress *addr) const;
};
class UPSWeightedRandomPolicy : public UPSGroupPolicy
+1 -4
View File
@@ -258,15 +258,12 @@ void WFServiceGovernance::failed(RouteManager::RouteResult *result,
server = (EndpointAddress *)tracing->data;
pthread_rwlock_wrlock(&this->rwlock);
size_t fail_count = ++server->fail_count;
if (--server->ref == 0)
delete server;
else if (fail_count == server->params->max_fails)
else if (++server->fail_count == server->params->max_fails)
this->fuse_server_to_breaker(server);
pthread_rwlock_unlock(&this->rwlock);
this->WFNSPolicy::failed(result, tracing, target);
}