-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make DnsResolver better #1443
make DnsResolver better #1443
Conversation
…) tuple at the same time
src/manager/DnsCache.cc
Outdated
{ | ||
int64_t cur_time = GET_CURRENT_SECOND; | ||
std::lock_guard<std::mutex> lock(mutex_); | ||
const DnsHandle *handle = cache_pool_.get(host_port); | ||
|
||
delayed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个为啥在锁里。
src/manager/DnsCache.cc
Outdated
|
||
const DnsCache::DnsHandle *DnsCache::get_inner(const HostPort& host_port, int type) | ||
const DnsCache::DnsHandle *DnsCache::get_inner(const HostPort& host_port, | ||
int type, bool& delayed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个delayed应该用指针的
src/nameservice/WFDnsResolver.cc
Outdated
@@ -441,6 +452,22 @@ void WFResolverTask::dispatch() | |||
} | |||
} | |||
|
|||
if (!in_guard_ && !dns_delayed) | |||
{ | |||
std::string guard_name = __get_guard_name(host_, port_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
family作为第一个参数吧。
src/nameservice/WFDnsResolver.cc
Outdated
std::string guard_name = __get_guard_name(host_, port_, | ||
ep_params_.address_family); | ||
WFTimerTask *timer = WFTaskFactory::create_timer_task(0, 0, nullptr); | ||
auto *guard = WFTaskFactory::create_guard(guard_name, timer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不会用auto,直接写WFConditional。
src/manager/DnsCache.h
Outdated
@@ -35,6 +35,8 @@ struct DnsCacheValue | |||
struct addrinfo *addrinfo; | |||
int64_t confident_time; | |||
int64_t expire_time; | |||
bool confident_delayed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加了一个指针的大小,有一点浪费了。
src/nameservice/WFDnsResolver.cc
Outdated
std::string guard_name("dns:"); | ||
guard_name.append(host ? host : "").append(":"); | ||
guard_name.append(std::to_string(port)).append(":"); | ||
guard_name.append(std::to_string(address_family)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个命名和dns cache里统一一下吧。例如:"0xfffff.github.com4:80",其中0xfffff是这个dns resolver的地址。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
往ResolverTask里传递一个Resolver地址,较为奇怪;或许可用DnsClient地址,虽然也较为奇怪
src/manager/DnsCache.cc
Outdated
h->value.expire_time += TTL_INC; | ||
h->value.expire_delayed = true; | ||
|
||
if (delayed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用判断了吧。
src/manager/DnsCache.cc
Outdated
{ | ||
int64_t cur_time = GET_CURRENT_SECOND; | ||
*delayed = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delayed是在 return NULL的时候,才有意义吗?好像return一个正常handler的时候,这个值是无意义的。这样的话,是不是可以在return NULL的时候才给这个指针内容赋值呢?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以,稍显繁复,但无伤大雅
src/nameservice/WFDnsResolver.cc
Outdated
switch (family) | ||
{ | ||
case AF_UNSPEC: | ||
cache_host.push_back('*'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里直接return hostname+'*'就可以了吧?
@@ -27,7 +27,7 @@ | |||
#define TTL_INC 5 | |||
|
|||
const DnsCache::DnsHandle *DnsCache::get_inner(const HostPort& host_port, | |||
int type, bool *delayed) | |||
int type) | |||
{ | |||
int64_t cur_time = GET_CURRENT_SECOND; | |||
std::lock_guard<std::mutex> lock(mutex_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的cache_pool_返回const DnsHandle *
,但下面又用const_cast去改value
,这里多出的的const设计感觉很突兀
src/manager/DnsCache.cc
Outdated
@@ -39,7 +40,13 @@ const DnsCache::DnsHandle *DnsCache::get_inner(const HostPort& host_port, int ty | |||
case GET_TYPE_TTL: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不要用switch了,把代码合并一下,也不需要CONFIDENT_INC了,反正都是5秒。
src/manager/WFGlobal.cc
Outdated
@@ -478,7 +478,46 @@ inline ExecQueue *__ExecManager::get_exec_queue(const std::string& queue_name) | |||
return queue; | |||
} | |||
|
|||
static void __dns_server_family(bool *v4, bool *v6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数最好不要假设外部已经把v4,v6都初始化为false了。
分成两个PR重新提交吧。这个有点太乱了。 |
No description provided.