mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Make CaresPTRResolver completely thread-safe
This commit is contained in:
parent
7d11054134
commit
2c41c0357d
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#include <mutex>
|
||||||
#include "DNSPTRResolver.h"
|
#include "DNSPTRResolver.h"
|
||||||
|
|
||||||
using ares_channel = struct ares_channeldata *;
|
using ares_channel = struct ares_channeldata *;
|
||||||
@ -46,6 +47,8 @@ namespace DB
|
|||||||
void process_readable_sockets(std::span<pollfd> readable_sockets);
|
void process_readable_sockets(std::span<pollfd> readable_sockets);
|
||||||
|
|
||||||
ares_channel channel;
|
ares_channel channel;
|
||||||
|
|
||||||
|
static std::mutex mutex;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#include "DNSPTRResolverProvider.h"
|
#include "DNSPTRResolverProvider.h"
|
||||||
|
#include "LockedDNSPTRResolver.h"
|
||||||
#include "CaresPTRResolver.h"
|
#include "CaresPTRResolver.h"
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
std::shared_ptr<DNSPTRResolver> DNSPTRResolverProvider::get()
|
std::shared_ptr<DNSPTRResolver> DNSPTRResolverProvider::get()
|
||||||
{
|
{
|
||||||
return std::make_shared<CaresPTRResolver>(
|
static auto resolver = std::make_shared<CaresPTRResolver>(
|
||||||
CaresPTRResolver::provider_token {}
|
CaresPTRResolver::provider_token {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return resolver;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/Common/LockedDNSPTRResolver.cpp
Normal file
25
src/Common/LockedDNSPTRResolver.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "LockedDNSPTRResolver.h"
|
||||||
|
|
||||||
|
namespace DB {
|
||||||
|
|
||||||
|
std::mutex LockedPTRResolver::mutex;
|
||||||
|
|
||||||
|
LockedPTRResolver::LockedPTRResolver(std::unique_ptr<DNSPTRResolver> resolver_)
|
||||||
|
: resolver(std::move(resolver_))
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::unordered_set<std::string> LockedPTRResolver::resolve(const std::string & ip)
|
||||||
|
{
|
||||||
|
std::lock_guard guard(mutex);
|
||||||
|
|
||||||
|
return resolver->resolve(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_set<std::string> LockedPTRResolver::resolve_v6(const std::string & ip)
|
||||||
|
{
|
||||||
|
std::lock_guard guard(mutex);
|
||||||
|
|
||||||
|
return resolver->resolve_v6(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
src/Common/LockedDNSPTRResolver.h
Normal file
25
src/Common/LockedDNSPTRResolver.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include <Common/DNSPTRResolver.h>
|
||||||
|
|
||||||
|
namespace DB {
|
||||||
|
class LockedPTRResolver : public DNSPTRResolver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
LockedPTRResolver(std::unique_ptr<DNSPTRResolver> resolver);
|
||||||
|
|
||||||
|
std::unordered_set<std::string> resolve(const std::string & ip) override;
|
||||||
|
|
||||||
|
std::unordered_set<std::string> resolve_v6(const std::string & ip) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// this needs to be owned
|
||||||
|
std::unique_ptr<DNSPTRResolver> resolver;
|
||||||
|
|
||||||
|
static std::mutex mutex;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user