Skip to content
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

Closed
wants to merge 15 commits into from
Closed

make DnsResolver better #1443

wants to merge 15 commits into from

Conversation

kedixa
Copy link
Contributor

@kedixa kedixa commented Dec 12, 2023

No description provided.

{
int64_t cur_time = GET_CURRENT_SECOND;
std::lock_guard<std::mutex> lock(mutex_);
const DnsHandle *handle = cache_pool_.get(host_port);

delayed = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个为啥在锁里。


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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个delayed应该用指针的

@@ -441,6 +452,22 @@ void WFResolverTask::dispatch()
}
}

if (!in_guard_ && !dns_delayed)
{
std::string guard_name = __get_guard_name(host_, port_,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

family作为第一个参数吧。

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不会用auto,直接写WFConditional。

@@ -35,6 +35,8 @@ struct DnsCacheValue
struct addrinfo *addrinfo;
int64_t confident_time;
int64_t expire_time;
bool confident_delayed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了一个指针的大小,有一点浪费了。

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));
Copy link
Contributor

@Barenboim Barenboim Dec 12, 2023

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的地址。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

往ResolverTask里传递一个Resolver地址,较为奇怪;或许可用DnsClient地址,虽然也较为奇怪

h->value.expire_time += TTL_INC;
h->value.expire_delayed = true;

if (delayed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不用判断了吧。

{
int64_t cur_time = GET_CURRENT_SECOND;
*delayed = false;
Copy link
Contributor

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的时候才给这个指针内容赋值呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以,稍显繁复,但无伤大雅

switch (family)
{
case AF_UNSPEC:
cache_host.push_back('*');
Copy link
Contributor

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_);
Copy link
Contributor Author

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设计感觉很突兀

@@ -39,7 +40,13 @@ const DnsCache::DnsHandle *DnsCache::get_inner(const HostPort& host_port, int ty
case GET_TYPE_TTL:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不要用switch了,把代码合并一下,也不需要CONFIDENT_INC了,反正都是5秒。

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数最好不要假设外部已经把v4,v6都初始化为false了。

@Barenboim
Copy link
Contributor

分成两个PR重新提交吧。这个有点太乱了。

@Barenboim Barenboim closed this Dec 18, 2023
@kedixa kedixa deleted the dev branch December 22, 2023 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants