Skip to content

Commit cd0d62d

Browse files
authored
Check 'breaker_list' before locking. (sogou#1767)
* Check breaker_list before locking. * Remove 'pre_select'.
1 parent 9745c2e commit cd0d62d

3 files changed

Lines changed: 4 additions & 30 deletions

File tree

src/nameservice/WFDnsResolver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class WFResolverTask : public WFRouterTask
6161
protected:
6262
virtual void dispatch();
6363
virtual SubTask *done();
64-
void set_has_next() { has_next_ = true; }
6564

6665
private:
6766
void thread_dns_callback(void *thrd_dns_task);

src/nameservice/WFServiceGovernance.cc

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,6 @@ void WFSGResolverTask::dispatch()
144144
return;
145145
}
146146

147-
if (sg_->pre_select_)
148-
{
149-
WFConditional *cond = sg_->pre_select_(this);
150-
if (cond)
151-
{
152-
series_of(this)->push_front(cond);
153-
this->set_has_next();
154-
this->subtask_done();
155-
return;
156-
}
157-
else if (this->state != WFT_STATE_UNDEFINED)
158-
{
159-
this->subtask_done();
160-
return;
161-
}
162-
}
163-
164147
if (sg_->select(ns_params_.uri, tracing, &addr))
165148
{
166149
auto *tracing_data = (WFServiceGovernance::TracingData *)tracing->data;
@@ -324,10 +307,12 @@ void WFServiceGovernance::check_breaker_locked(int64_t cur_time)
324307

325308
void WFServiceGovernance::check_breaker()
326309
{
327-
pthread_mutex_lock(&this->breaker_lock);
328310
if (!list_empty(&this->breaker_list))
311+
{
312+
pthread_mutex_lock(&this->breaker_lock);
329313
this->check_breaker_locked(GET_CURRENT_SECOND);
330-
pthread_mutex_unlock(&this->breaker_lock);
314+
pthread_mutex_unlock(&this->breaker_lock);
315+
}
331316
}
332317

333318
void WFServiceGovernance::try_clear_breaker()

src/nameservice/WFServiceGovernance.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <unordered_map>
2626
#include <vector>
2727
#include <atomic>
28-
#include <functional>
2928
#include "URIParser.h"
3029
#include "EndpointParams.h"
3130
#include "WFNameService.h"
@@ -123,14 +122,6 @@ class WFServiceGovernance : public WFNSPolicy
123122

124123
static bool in_select_history(WFNSTracing *tracing, EndpointAddress *addr);
125124

126-
public:
127-
using pre_select_t = std::function<WFConditional *(WFRouterTask *)>;
128-
129-
void set_pre_select(pre_select_t pre_select)
130-
{
131-
pre_select_ = std::move(pre_select);
132-
}
133-
134125
private:
135126
virtual bool select(const ParsedURI& uri, WFNSTracing *tracing,
136127
EndpointAddress **addr);
@@ -156,7 +147,6 @@ class WFServiceGovernance : public WFNSPolicy
156147
struct list_head breaker_list;
157148
pthread_mutex_t breaker_lock;
158149
unsigned int mttr_seconds;
159-
pre_select_t pre_select_;
160150

161151
protected:
162152
virtual EndpointAddress *first_strategy(const ParsedURI& uri,

0 commit comments

Comments
 (0)