consistent_hash_with_group() skips tracing

This commit is contained in:
holmes1412
2022-02-11 20:31:10 +08:00
parent 553e5da744
commit 852600fa60
5 changed files with 17 additions and 15 deletions

View File

@@ -10,10 +10,10 @@ using timer_callback_t = std::function<void (WFTimerTask *)>;
class WFTaskFactory
{
...
...
static WFTimerTask *create_timer_task(unsigned int microseconds,
timer_callback_t callback);
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,
timer_callback_t callback);
};
~~~

View File

@@ -11,7 +11,7 @@ using timer_callback_t = std::function<void (WFTimerTask *)>;
class WFTaskFactory
{
...
...
static WFTimerTask *create_timer_task(unsigned int microseconds,
timer_callback_t callback);
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,

View File

@@ -44,7 +44,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;

View File

@@ -194,17 +194,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 == true) // means fail_count >= max_fails
{
if (params->group_id == -1)
return NULL;
@@ -397,7 +397,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;
@@ -427,7 +428,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)
@@ -636,7 +637,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,
@@ -659,6 +660,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);
}

View File

@@ -71,9 +71,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;
};