mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
add comments to the code
This commit is contained in:
parent
433eda70fd
commit
ea38df2c28
@ -82,7 +82,7 @@ namespace DB
|
|||||||
|
|
||||||
resolve(ip, ptr_records);
|
resolve(ip, ptr_records);
|
||||||
|
|
||||||
if (!wait())
|
if (!wait_and_process())
|
||||||
{
|
{
|
||||||
cancel_requests();
|
cancel_requests();
|
||||||
throw DB::Exception("Failed to complete reverse DNS query for IP " + ip, DB::ErrorCodes::DNS_ERROR);
|
throw DB::Exception("Failed to complete reverse DNS query for IP " + ip, DB::ErrorCodes::DNS_ERROR);
|
||||||
@ -99,7 +99,7 @@ namespace DB
|
|||||||
|
|
||||||
resolve_v6(ip, ptr_records);
|
resolve_v6(ip, ptr_records);
|
||||||
|
|
||||||
if (!wait())
|
if (!wait_and_process())
|
||||||
{
|
{
|
||||||
cancel_requests();
|
cancel_requests();
|
||||||
throw DB::Exception("Failed to complete reverse DNS query for IP " + ip, DB::ErrorCodes::DNS_ERROR);
|
throw DB::Exception("Failed to complete reverse DNS query for IP " + ip, DB::ErrorCodes::DNS_ERROR);
|
||||||
@ -125,7 +125,7 @@ namespace DB
|
|||||||
ares_gethostbyaddr(channel, reinterpret_cast<const void*>(&addr), sizeof(addr), AF_INET6, callback, &response);
|
ares_gethostbyaddr(channel, reinterpret_cast<const void*>(&addr), sizeof(addr), AF_INET6, callback, &response);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CaresPTRResolver::wait()
|
bool CaresPTRResolver::wait_and_process()
|
||||||
{
|
{
|
||||||
int sockets[ARES_GETSOCK_MAXNUM];
|
int sockets[ARES_GETSOCK_MAXNUM];
|
||||||
pollfd pollfd[ARES_GETSOCK_MAXNUM];
|
pollfd pollfd[ARES_GETSOCK_MAXNUM];
|
||||||
@ -140,17 +140,19 @@ namespace DB
|
|||||||
{
|
{
|
||||||
number_of_fds_ready = poll(readable_sockets.data(), static_cast<nfds_t>(readable_sockets.size()), static_cast<int>(timeout));
|
number_of_fds_ready = poll(readable_sockets.data(), static_cast<nfds_t>(readable_sockets.size()), static_cast<int>(timeout));
|
||||||
|
|
||||||
// will add comments/ improve readability soon
|
bool poll_error = number_of_fds_ready < 0;
|
||||||
if (number_of_fds_ready < 0)
|
bool is_poll_error_an_interrupt = poll_error && errno == EINTR;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Retry in case of interrupts and return false in case of actual errors.
|
||||||
|
* */
|
||||||
|
if (is_poll_error_an_interrupt)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
continue;
|
||||||
{
|
}
|
||||||
continue;
|
else if (poll_error)
|
||||||
}
|
{
|
||||||
else
|
return false;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +189,7 @@ namespace DB
|
|||||||
if (ARES_GETSOCK_READABLE(sockets_bitmask, i))
|
if (ARES_GETSOCK_READABLE(sockets_bitmask, i))
|
||||||
{
|
{
|
||||||
pollfd[i].fd = sockets[i];
|
pollfd[i].fd = sockets[i];
|
||||||
pollfd[i].events = POLLRDNORM | POLLIN;
|
pollfd[i].events = C_ARES_POLL_EVENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pollfd[i].events)
|
if (pollfd[i].events)
|
||||||
@ -227,7 +229,7 @@ namespace DB
|
|||||||
{
|
{
|
||||||
for (auto readable_socket : readable_sockets)
|
for (auto readable_socket : readable_sockets)
|
||||||
{
|
{
|
||||||
auto fd = readable_socket.revents & (POLLRDNORM | POLLIN) ? readable_socket.fd : ARES_SOCKET_BAD;
|
auto fd = readable_socket.revents & C_ARES_POLL_EVENTS ? readable_socket.fd : ARES_SOCKET_BAD;
|
||||||
ares_process_fd(channel, fd, ARES_SOCKET_BAD);
|
ares_process_fd(channel, fd, ARES_SOCKET_BAD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,9 @@ namespace DB
|
|||||||
* Allow only DNSPTRProvider to instantiate this class
|
* Allow only DNSPTRProvider to instantiate this class
|
||||||
* */
|
* */
|
||||||
struct provider_token {};
|
struct provider_token {};
|
||||||
|
|
||||||
|
static constexpr auto C_ARES_POLL_EVENTS = POLLRDNORM | POLLIN;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CaresPTRResolver(provider_token);
|
explicit CaresPTRResolver(provider_token);
|
||||||
~CaresPTRResolver() override;
|
~CaresPTRResolver() override;
|
||||||
@ -32,7 +35,7 @@ namespace DB
|
|||||||
std::unordered_set<std::string> resolve_v6(const std::string & ip) override;
|
std::unordered_set<std::string> resolve_v6(const std::string & ip) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool wait();
|
bool wait_and_process();
|
||||||
|
|
||||||
void cancel_requests();
|
void cancel_requests();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user