提交 f20f3f21 编写于 作者: V Vitaliy Lyudvichenko

Update clusters in SYSTEM DROP DNS query. [#CLICKHOUSE-3478]

上级 9ed1fdbb
......@@ -1348,15 +1348,21 @@ std::shared_ptr<Cluster> Context::tryGetCluster(const std::string & cluster_name
}
void Context::reloadClusterConfig()
{
std::lock_guard<std::mutex> lock(shared->clusters_mutex);
auto & config = shared->clusters_config ? *shared->clusters_config : getConfigRef();
shared->clusters = std::make_unique<Clusters>(config, settings);
}
Clusters & Context::getClusters() const
{
std::lock_guard<std::mutex> lock(shared->clusters_mutex);
if (!shared->clusters)
{
std::lock_guard<std::mutex> lock(shared->clusters_mutex);
if (!shared->clusters)
{
auto & config = shared->clusters_config ? *shared->clusters_config : getConfigRef();
shared->clusters = std::make_unique<Clusters>(config, settings);
}
auto & config = shared->clusters_config ? *shared->clusters_config : getConfigRef();
shared->clusters = std::make_unique<Clusters>(config, settings);
}
return *shared->clusters;
......
......@@ -318,6 +318,7 @@ public:
Clusters & getClusters() const;
std::shared_ptr<Cluster> getCluster(const std::string & cluster_name) const;
std::shared_ptr<Cluster> tryGetCluster(const std::string & cluster_name) const;
void reloadClusterConfig();
void setClustersConfig(const ConfigurationPtr & config);
Compiler & getCompiler();
......
......@@ -75,6 +75,8 @@ BlockIO InterpreterSystemQuery::execute()
break;
case Type::DROP_DNS_CACHE:
DNSCache::instance().drop();
/// Reinitialize clusters to update their resolved_addresses
context.reloadClusterConfig();
break;
case Type::DROP_MARK_CACHE:
context.dropMarkCache();
......
......@@ -9,6 +9,7 @@ from contextlib import contextmanager
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import TSV
from helpers.client import QueryRuntimeException
@pytest.fixture(scope="module")
......@@ -24,10 +25,12 @@ def started_cluster():
instance.query('CREATE DATABASE dictionaries ENGINE = Dictionary')
instance.query('CREATE TABLE dictionary_source (id UInt64, value UInt8) ENGINE = Memory')
#print instance.query('SELECT * FROM system.dictionaries FORMAT Vertical')
print "Started ", instance.ip_address
yield cluster
finally:
pass
cluster.shutdown()
......@@ -54,13 +57,21 @@ def test_SYSTEM_RELOAD_DICTIONARY(started_cluster):
def test_DROP_DNS_CACHE(started_cluster):
instance = cluster.instances['ch1']
with pytest.raises(Exception):
instance.query("SELECT * FROM remote('aperol', 'system', 'one')")
instance.exec_in_container(['bash', '-c', 'echo 127.255.255.255 lost_host > /etc/hosts'], privileged=True, user='root')
instance.exec_in_container(['bash', '-c', 'echo 127.0.0.1 aperol >> /etc/hosts'], privileged=True, user='root')
with pytest.raises(QueryRuntimeException):
instance.query("SELECT * FROM remote('lost_host', 'system', 'one')")
instance.query("CREATE TABLE distributed_lost_host (dummy UInt8) ENGINE = Distributed(lost_host_cluster, 'system', 'one')")
with pytest.raises(QueryRuntimeException):
instance.query("SELECT * FROM distributed_lost_host")
instance.exec_in_container(['bash', '-c', 'echo 127.0.0.1 lost_host > /etc/hosts'], privileged=True, user='root')
instance.query("SYSTEM DROP DNS CACHE")
instance.query("SELECT * FROM remote('aperol', 'system', 'one')")
instance.query("SELECT * FROM remote('lost_host', 'system', 'one')")
instance.query("SELECT * FROM distributed_lost_host")
assert TSV(instance.query("SELECT DISTINCT host_name, host_address FROM system.clusters")) == TSV("lost_host\t127.0.0.1\n")
if __name__ == '__main__':
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册