Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f81b0f4

Browse files
authored
Merge pull request sogou#753 from holmes1412/master
consistent_hash_with_group() skips tracing
2 parents 8be49d5 + 6840b4b commit f81b0f4

6 files changed

Lines changed: 17 additions & 19 deletions

File tree

docs/about-timer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ using timer_callback_t = std::function<void (WFTimerTask *)>;
1010

1111
class WFTaskFactory
1212
{
13-
...
13+
...
1414
static WFTimerTask *create_timer_task(unsigned int microseconds,
1515
timer_callback_t callback);
16-
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,
16+
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,
1717
timer_callback_t callback);
1818
};
1919
~~~

docs/en/about-timer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using timer_callback_t = std::function<void (WFTimerTask *)>;
1111

1212
class WFTaskFactory
1313
{
14-
...
14+
...
1515
static WFTimerTask *create_timer_task(unsigned int microseconds,
1616
timer_callback_t callback);
1717
static WFTimerTask *create_timer_task(time_t seconds, long nanoseconds,

src/manager/UpstreamManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* - Additional, we support Main-backup & Group for server and working well in any mode.
4545
*
4646
* @code{.cc}
47-
upstream_create_weighted_random("abc.sogou", true); //UPSTREAM_WIGHTED_RANDOM
47+
upstream_create_weighted_random("abc.sogou", true); //UPSTREAM_WEIGHTED_RANDOM
4848
upstream_add_server("abc.sogou", "192.168.2.100:8081"); //weight=1, max_fails=200
4949
upstream_add_server("abc.sogou", "192.168.2.100:9090"); //weight=1, max_fails=200
5050
AddressParams params = ADDRESS_PARAMS_DEFAULT;

src/nameservice/UpstreamPolicies.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ bool UPSGroupPolicy::select(const ParsedURI& uri, WFNSTracing *tracing,
194194
}
195195

196196
/*
197-
* flag true : return an available one. If not exists, return NULL.
198-
* false: means addr maybe group-alive.
199-
* If addr is not available, get one from addr->group.
197+
* addr_failed true: return an available one. If not exists, return NULL.
198+
* false: means addr maybe group-alive.
199+
* If addr is not available, get one from addr->group.
200200
*/
201201
EndpointAddress *UPSGroupPolicy::check_and_get(EndpointAddress *addr,
202-
bool flag,
202+
bool addr_failed,
203203
WFNSTracing *tracing)
204204
{
205205
UPSAddrParams *params = static_cast<UPSAddrParams *>(addr->params);
206206

207-
if (flag == true) // && addr->fail_count >= addr->params->max_fails
207+
if (addr_failed == true) // means fail_count >= max_fails
208208
{
209209
if (params->group_id == -1)
210210
return NULL;
@@ -397,7 +397,8 @@ int UPSGroupPolicy::remove_server_locked(const std::string& address)
397397
return ret;
398398
}
399399

400-
EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash)
400+
EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash,
401+
WFNSTracing *tracing)
401402
{
402403
const UPSAddrParams *params;
403404
EndpointAddress *addr = NULL;
@@ -427,7 +428,7 @@ EndpointAddress *UPSGroupPolicy::consistent_hash_with_group(unsigned int hash)
427428
if (!addr)
428429
return NULL;
429430

430-
return this->check_and_get(addr, false, NULL);
431+
return this->check_and_get(addr, false, tracing);
431432
}
432433

433434
void UPSWeightedRandomPolicy::add_server_locked(EndpointAddress *addr)
@@ -636,7 +637,7 @@ EndpointAddress *UPSConsistentHashPolicy::first_strategy(const ParsedURI& uri,
636637
uri.path ? uri.path : "",
637638
uri.query ? uri.query : "",
638639
uri.fragment ? uri.fragment : "");
639-
return this->consistent_hash_with_group(hash_value);
640+
return this->consistent_hash_with_group(hash_value, tracing);
640641
}
641642

642643
EndpointAddress *UPSManualPolicy::first_strategy(const ParsedURI& uri,
@@ -659,6 +660,6 @@ EndpointAddress *UPSManualPolicy::another_strategy(const ParsedURI& uri,
659660
uri.path ? uri.path : "",
660661
uri.query ? uri.query : "",
661662
uri.fragment ? uri.fragment : "");
662-
return this->consistent_hash_with_group(hash_value);
663+
return this->consistent_hash_with_group(hash_value, tracing);
663664
}
664665

src/nameservice/UpstreamPolicies.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ class UPSGroupPolicy : public WFServiceGovernance
7171
virtual void add_server_locked(EndpointAddress *addr);
7272
virtual int remove_server_locked(const std::string& address);
7373

74-
EndpointAddress *consistent_hash_with_group(unsigned int hash);
74+
EndpointAddress *consistent_hash_with_group(unsigned int hash,
75+
WFNSTracing *tracing);
7576
EndpointAddress *check_and_get(EndpointAddress *addr,
76-
bool flag, WFNSTracing *tracing);
77+
bool addr_failed, WFNSTracing *tracing);
7778

7879
bool is_alive(const EndpointAddress *addr) const;
7980
};

src/nameservice/WFServiceGovernance.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ void WFServiceGovernance::tracing_deleter(void *data)
166166
bool WFServiceGovernance::in_select_history(WFNSTracing *tracing,
167167
EndpointAddress *addr)
168168
{
169-
/* 'tracing' is NULL in consistent hash. */
170-
if (!tracing)
171-
return false;
172-
173169
struct TracingData *tracing_data = (struct TracingData *)tracing->data;
174170

175171
if (!tracing_data)

0 commit comments

Comments
 (0)