mirror of
https://github.com/sogou/workflow.git
synced 2026-10-24 16:33:15 +08:00
Merge pull request #755 from holmes1412/windows
consistent_hash_with_group() skips tracing (Windows)
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
* - Additional, we support Main-backup & Group for server and working well in any mode.
|
||||
*
|
||||
* @code{.cc}
|
||||
upstream_create_weighted_random("abc.sogou", true); //UPSTREAM_WIGHTED_RANDOM
|
||||
upstream_create_weighted_random("abc.sogou", true); //UPSTREAM_WEIGHTED_RANDOM
|
||||
upstream_add_server("abc.sogou", "192.168.2.100:8081"); //weight=1, max_fails=200
|
||||
upstream_add_server("abc.sogou", "192.168.2.100:9090"); //weight=1, max_fails=200
|
||||
AddressParams params = ADDRESS_PARAMS_DEFAULT;
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
* @note
|
||||
*/
|
||||
static int upstream_create_vnswrr(const std::string& name);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Delete one upstream
|
||||
* @param[in] name upstream name
|
||||
|
||||
@@ -169,11 +169,6 @@ bool UPSGroupPolicy::select(const ParsedURI& uri, WFNSTracing *tracing,
|
||||
}
|
||||
|
||||
this->check_breaker();
|
||||
if (this->nalives == 0)
|
||||
{
|
||||
this->rwlock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
// select_addr == NULL will only happened in consistent_hash
|
||||
EndpointAddress *select_addr = this->first_strategy(uri, tracing);
|
||||
@@ -201,17 +196,17 @@ bool UPSGroupPolicy::select(const ParsedURI& uri, WFNSTracing *tracing,
|
||||
}
|
||||
|
||||
/*
|
||||
* flag true : return an available one. If not exists, return NULL.
|
||||
* false: means addr maybe group-alive.
|
||||
* If addr is not available, get one from addr->group.
|
||||
* addr_failed true: return an available one. If not exists, return NULL.
|
||||
* false: means addr maybe group-alive.
|
||||
* If addr is not available, get one from addr->group.
|
||||
*/
|
||||
EndpointAddress *UPSGroupPolicy::check_and_get(EndpointAddress *addr,
|
||||
bool flag,
|
||||
bool addr_failed,
|
||||
WFNSTracing *tracing)
|
||||
{
|
||||
UPSAddrParams *params = static_cast<UPSAddrParams *>(addr->params);
|
||||
|
||||
if (flag == true) // && addr->fail_count >= addr->params->max_fails
|
||||
if (addr_failed) // means fail_count >= max_fails
|
||||
{
|
||||
if (params->group_id == -1)
|
||||
return NULL;
|
||||
@@ -404,7 +399,8 @@ int UPSGroupPolicy::remove_server_locked(const std::string& address)
|
||||
return ret;
|
||||
}
|
||||
|
||||
EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash)
|
||||
EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash,
|
||||
WFNSTracing *tracing)
|
||||
{
|
||||
const UPSAddrParams *params;
|
||||
EndpointAddress *addr = NULL;
|
||||
@@ -434,7 +430,7 @@ EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash)
|
||||
if (!addr)
|
||||
return NULL;
|
||||
|
||||
return this->check_and_get(addr, false, NULL);
|
||||
return this->check_and_get(addr, false, tracing);
|
||||
}
|
||||
|
||||
void UPSWeightedRandomPolicy::add_server_locked(EndpointAddress *addr)
|
||||
@@ -584,7 +580,7 @@ EndpointAddress *UPSVNSWRRPolicy::first_strategy(const ParsedURI& uri,
|
||||
|
||||
break;
|
||||
}
|
||||
this->cur_idx = idx;
|
||||
this->cur_idx = idx + 1;
|
||||
return this->servers[idx];
|
||||
}
|
||||
|
||||
@@ -643,7 +639,7 @@ EndpointAddress *UPSConsistentHashPolicy::first_strategy(const ParsedURI& uri,
|
||||
uri.path ? uri.path : "",
|
||||
uri.query ? uri.query : "",
|
||||
uri.fragment ? uri.fragment : "");
|
||||
return this->consistent_hash_with_group(hash_value);
|
||||
return this->consistent_hash_with_group(hash_value, tracing);
|
||||
}
|
||||
|
||||
EndpointAddress *UPSManualPolicy::first_strategy(const ParsedURI& uri,
|
||||
@@ -666,6 +662,6 @@ EndpointAddress *UPSManualPolicy::another_strategy(const ParsedURI& uri,
|
||||
uri.path ? uri.path : "",
|
||||
uri.query ? uri.query : "",
|
||||
uri.fragment ? uri.fragment : "");
|
||||
return this->consistent_hash_with_group(hash_value);
|
||||
return this->consistent_hash_with_group(hash_value, tracing);
|
||||
}
|
||||
|
||||
|
||||
@@ -74,9 +74,10 @@ protected:
|
||||
virtual void add_server_locked(EndpointAddress *addr);
|
||||
virtual int remove_server_locked(const std::string& address);
|
||||
|
||||
EndpointAddress *consistent_hash_with_group(unsigned int hash);
|
||||
EndpointAddress *consistent_hash_with_group(unsigned int hash,
|
||||
WFNSTracing *tracing);
|
||||
EndpointAddress *check_and_get(EndpointAddress *addr,
|
||||
bool flag, WFNSTracing *tracing);
|
||||
bool addr_failed, WFNSTracing *tracing);
|
||||
|
||||
bool is_alive(const EndpointAddress *addr) const;
|
||||
};
|
||||
|
||||
@@ -164,10 +164,6 @@ void WFServiceGovernance::tracing_deleter(void *data)
|
||||
bool WFServiceGovernance::in_select_history(WFNSTracing *tracing,
|
||||
EndpointAddress *addr)
|
||||
{
|
||||
/* 'tracing' is NULL in consistent hash. */
|
||||
if (!tracing)
|
||||
return false;
|
||||
|
||||
struct TracingData *tracing_data = (struct TracingData *)tracing->data;
|
||||
|
||||
if (!tracing_data)
|
||||
|
||||
Reference in New Issue
Block a user