mirror of
https://github.com/sogou/workflow.git
synced 2026-10-20 22:26:59 +08:00
update codes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user