mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 21:42:39 +00:00
no update network_interfaces
Signed-off-by: Duc Canh Le <duccanh.le@ahrefs.com>
This commit is contained in:
parent
3b48b5aa5e
commit
15fe392fed
@ -79,33 +79,6 @@ struct NetworkInterfaces : public boost::noncopyable
|
||||
{
|
||||
freeifaddrs(ifaddr);
|
||||
}
|
||||
|
||||
static std::shared_ptr<const NetworkInterfaces> instance()
|
||||
{
|
||||
static constexpr int NET_INTERFACE_VALID_PERIOD_MS = 30000;
|
||||
static std::shared_ptr<const NetworkInterfaces> nf = std::make_shared<const NetworkInterfaces>();
|
||||
static std::atomic<std::chrono::steady_clock::time_point> last_updated_time = std::chrono::steady_clock::now();
|
||||
static std::shared_mutex nf_mtx;
|
||||
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_updated_time.load()).count() > NET_INTERFACE_VALID_PERIOD_MS)
|
||||
{
|
||||
std::unique_lock lock(nf_mtx);
|
||||
/// It's possible that last_updated_time after we get lock
|
||||
if (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_updated_time.load()).count() > NET_INTERFACE_VALID_PERIOD_MS)
|
||||
{
|
||||
nf = std::make_shared<const NetworkInterfaces>();
|
||||
last_updated_time.store(now);
|
||||
}
|
||||
return nf;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::shared_lock lock(nf_mtx);
|
||||
return nf;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -143,7 +116,8 @@ bool isLocalAddress(const Poco::Net::IPAddress & address)
|
||||
}
|
||||
}
|
||||
|
||||
return NetworkInterfaces::instance()->hasAddress(address);
|
||||
static NetworkInterfaces network_interfaces;
|
||||
return network_interfaces.hasAddress(address);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user