Revert "Implement system.dns_cache table (#59856)"

This reverts commit b5ef034697.
This commit is contained in:
Alexey Milovidov 2024-02-17 01:46:41 +01:00 committed by GitHub
parent b5ef034697
commit 731c484b3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 9 additions and 156 deletions

View File

@ -1,34 +0,0 @@
---
slug: /en/operations/system-tables/dns_cache
---
# dns_cache
Contains information about cached DNS records.
Columns:
- `hostname` ([String](../../sql-reference/data-types/string.md)) — cached hostname
- `ip_address` ([String](../../sql-reference/data-types/string.md)) — ip address for the hostname
- `family` ([String](../../sql-reference/data-types/string.md)) — family of the ip address: `IPv4`, `IPv6`, or `UNIX_LOCAL`.
- `cached_at` ([String](../../sql-reference/data-types/datetime.md)) - datetime when the record was cached
**Example**
Query:
```sql
SELECT * FROM system.dns_cache;
```
Result:
| hostname | ip\_address | ip\_family | cached\_at |
| :--- | :--- | :--- | :--- |
| localhost | ::1 | IPv6 | 2024-02-11 17:04:40 |
| localhost | 127.0.0.1 | IPv4 | 2024-02-11 17:04:40 |
**See also**
- [disable_internal_dns_cache setting](../../operations/server-configuration-parameters/settings.md#disable_internal_dns_cache)
- [dns_cache_update_period setting](../../operations/server-configuration-parameters/settings.md#dns_cache_update_period)
- [dns_max_consecutive_failures setting](../../operations/server-configuration-parameters/settings.md#dns_max_consecutive_failures)

View File

@ -4,10 +4,13 @@
#include <Common/ProfileEvents.h>
#include <Common/thread_local_rng.h>
#include <Common/logger_useful.h>
#include <Core/Names.h>
#include <base/types.h>
#include <Poco/Net/IPAddress.h>
#include <Poco/Net/DNS.h>
#include <Poco/Net/NetException.h>
#include <Poco/NumberParser.h>
#include <arpa/inet.h>
#include <atomic>
#include <optional>
#include <string_view>
@ -138,10 +141,10 @@ DNSResolver::IPAddresses resolveIPAddressImpl(const std::string & host)
return addresses;
}
DNSResolver::IPAddresses resolveIPAddressWithCache(CacheBase<std::string, DNSResolver::CacheEntry> & cache, const std::string & host)
DNSResolver::IPAddresses resolveIPAddressWithCache(CacheBase<std::string, DNSResolver::IPAddresses> & cache, const std::string & host)
{
auto [result, _ ] = cache.getOrSet(host, [&host]() {return std::make_shared<DNSResolver::CacheEntry>(resolveIPAddressImpl(host), std::chrono::system_clock::now());});
return result->addresses;
auto [result, _ ] = cache.getOrSet(host, [&host]() { return std::make_shared<DNSResolver::IPAddresses>(resolveIPAddressImpl(host)); });
return *result;
}
std::unordered_set<String> reverseResolveImpl(const Poco::Net::IPAddress & address)
@ -176,7 +179,7 @@ struct DNSResolver::Impl
using HostWithConsecutiveFailures = std::unordered_map<String, UInt32>;
using AddressWithConsecutiveFailures = std::unordered_map<Poco::Net::IPAddress, UInt32>;
CacheBase<std::string, DNSResolver::CacheEntry> cache_host{100};
CacheBase<std::string, DNSResolver::IPAddresses> cache_host{100};
CacheBase<Poco::Net::IPAddress, std::unordered_set<std::string>> cache_address{100};
std::mutex drop_mutex;
@ -408,7 +411,7 @@ bool DNSResolver::updateHost(const String & host)
const auto old_value = resolveIPAddressWithCache(impl->cache_host, host);
auto new_value = resolveIPAddressImpl(host);
const bool result = old_value != new_value;
impl->cache_host.set(host, std::make_shared<DNSResolver::CacheEntry>(std::move(new_value), std::chrono::system_clock::now()));
impl->cache_host.set(host, std::make_shared<DNSResolver::IPAddresses>(std::move(new_value)));
return result;
}
@ -435,19 +438,6 @@ void DNSResolver::addToNewAddresses(const Poco::Net::IPAddress & address)
impl->new_addresses.insert({address, consecutive_failures});
}
std::vector<std::pair<std::string, DNSResolver::CacheEntry>> DNSResolver::cacheEntries() const
{
std::lock_guard lock(impl->drop_mutex);
std::vector<std::pair<std::string, DNSResolver::CacheEntry>> entries;
for (auto & [key, entry] : impl->cache_host.dump())
{
entries.emplace_back(std::move(key), *entry);
}
return entries;
}
DNSResolver::~DNSResolver() = default;
DNSResolver & DNSResolver::instance()

View File

@ -20,11 +20,7 @@ class DNSResolver : private boost::noncopyable
{
public:
using IPAddresses = std::vector<Poco::Net::IPAddress>;
using CacheEntry = struct
{
IPAddresses addresses;
std::chrono::system_clock::time_point cached_at;
};
using IPAddressesPtr = std::shared_ptr<IPAddresses>;
static DNSResolver & instance();
@ -62,9 +58,6 @@ public:
/// Returns true if IP of any host has been changed or an element was dropped (too many failures)
bool updateCache(UInt32 max_consecutive_failures);
/// Returns a copy of cache entries
std::vector<std::pair<std::string, CacheEntry>> cacheEntries() const;
~DNSResolver();
private:

View File

@ -1,65 +0,0 @@
#include <Access/ContextAccess.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeDateTime.h>
#include <Interpreters/Context.h>
#include <Storages/System/StorageSystemDNSCache.h>
#include <Common/DNSResolver.h>
#include "StorageSystemDatabases.h"
namespace DB
{
ColumnsDescription StorageSystemDNSCache::getColumnsDescription()
{
return ColumnsDescription
{
{"hostname", std::make_shared<DataTypeString>(), "Hostname."},
{"ip_address", std::make_shared<DataTypeString>(), "IP address."},
{"ip_family", std::make_shared<DataTypeString>(), "IP address family."},
{"cached_at", std::make_shared<DataTypeDateTime>(), "Record cached timestamp."},
};
}
void StorageSystemDNSCache::fillData(MutableColumns & res_columns, ContextPtr, const SelectQueryInfo &) const
{
using HostIPPair = std::pair<std::string, std::string>;
std::set<HostIPPair> reported_elements;
for (const auto & [hostname, entry] : DNSResolver::instance().cacheEntries())
{
for (const auto &address : entry.addresses)
{
std::string ip = address.toString();
// Cache might report the same ip address multiple times. Report only one of them.
if (reported_elements.contains(HostIPPair(hostname, ip)))
continue;
reported_elements.insert(HostIPPair(hostname, ip));
std::string family_str;
switch (address.family())
{
case Poco::Net::AddressFamily::IPv4:
family_str = "IPv4";
break;
case Poco::Net::AddressFamily::IPv6:
family_str = "IPv6";
break;
case Poco::Net::AddressFamily::UNIX_LOCAL:
family_str = "UNIX_LOCAL";
break;
}
size_t i = 0;
res_columns[i++]->insert(hostname);
res_columns[i++]->insert(ip);
res_columns[i++]->insert(family_str);
res_columns[i++]->insert(static_cast<UInt32>(std::chrono::system_clock::to_time_t(entry.cached_at)));
}
}
}
}

View File

@ -1,25 +0,0 @@
#pragma once
#include <Storages/System/IStorageSystemOneBlock.h>
namespace DB
{
class Context;
/// system.dns_cache table.
class StorageSystemDNSCache final : public IStorageSystemOneBlock<StorageSystemDNSCache>
{
public:
std::string getName() const override { return "SystemDNSCache"; }
static ColumnsDescription getColumnsDescription();
protected:
using IStorageSystemOneBlock::IStorageSystemOneBlock;
void fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo & query_info) const override;
};
}

View File

@ -90,7 +90,6 @@
#include <Storages/System/StorageSystemS3Queue.h>
#include <Storages/System/StorageSystemDashboards.h>
#include <Storages/System/StorageSystemViewRefreshes.h>
#include <Storages/System/StorageSystemDNSCache.h>
#if defined(__ELF__) && !defined(OS_FREEBSD)
#include <Storages/System/StorageSystemSymbols.h>
@ -167,7 +166,6 @@ void attachSystemTablesServer(ContextPtr context, IDatabase & system_database, b
attach<StorageSystemDroppedTables>(context, system_database, "dropped_tables", "Contains a list of tables which were dropped from Atomic databases but not completely removed yet.");
attach<StorageSystemDroppedTablesParts>(context, system_database, "dropped_tables_parts", "Contains parts of system.dropped_tables tables ");
attach<StorageSystemScheduler>(context, system_database, "scheduler", "Contains information and status for scheduling nodes residing on the local server.");
attach<StorageSystemDNSCache>(context, system_database, "dns_cache", "Contains information about cached DNS records.");
#if defined(__ELF__) && !defined(OS_FREEBSD)
attach<StorageSystemSymbols>(context, system_database, "symbols", "Contains information for introspection of ClickHouse binary. This table is only useful for C++ experts and ClickHouse engineers.");
#endif

View File

@ -1,2 +0,0 @@
Ok.
localhost 127.0.0.1 IPv4 1

View File

@ -1,2 +0,0 @@
SELECT * FROM url('http://localhost:8123/ping', CSV, 'auto', headers());
SELECT hostname, ip_address, ip_family, (isNotNull(cached_at) AND cached_at > '1970-01-01 00:00:00') FROM system.dns_cache WHERE hostname = 'localhost' AND ip_family = 'IPv4';