2018-07-24 14:42:52 +00:00
|
|
|
#include <Common/DNSResolver.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/Cluster.h>
|
|
|
|
#include <Interpreters/Context.h>
|
2018-07-24 14:28:56 +00:00
|
|
|
#include <Storages/System/StorageSystemClusters.h>
|
2015-04-30 12:43:16 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2018-07-24 18:46:23 +00:00
|
|
|
|
2018-07-24 14:28:56 +00:00
|
|
|
NamesAndTypesList StorageSystemClusters::getNamesAndTypes()
|
2018-01-25 14:42:39 +00:00
|
|
|
{
|
2018-07-24 14:28:56 +00:00
|
|
|
return {
|
|
|
|
{"cluster", std::make_shared<DataTypeString>()},
|
|
|
|
{"shard_num", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"shard_weight", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"replica_num", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"host_name", std::make_shared<DataTypeString>()},
|
|
|
|
{"host_address", std::make_shared<DataTypeString>()},
|
|
|
|
{"port", std::make_shared<DataTypeUInt16>()},
|
|
|
|
{"is_local", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"user", std::make_shared<DataTypeString>()},
|
|
|
|
{"default_database", std::make_shared<DataTypeString>()},
|
|
|
|
};
|
2015-04-30 12:43:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-24 14:28:56 +00:00
|
|
|
void StorageSystemClusters::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
|
2015-04-30 12:43:16 +00:00
|
|
|
{
|
2018-07-24 18:46:23 +00:00
|
|
|
auto updateColumns = [&](const std::string & cluster_name, const Cluster::ShardInfo & shard_info, const Cluster::Address & address)
|
|
|
|
{
|
2017-12-16 00:49:03 +00:00
|
|
|
size_t i = 0;
|
|
|
|
res_columns[i++]->insert(cluster_name);
|
2018-10-22 08:54:54 +00:00
|
|
|
res_columns[i++]->insert(shard_info.shard_num);
|
|
|
|
res_columns[i++]->insert(shard_info.weight);
|
|
|
|
res_columns[i++]->insert(address.replica_num);
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(address.host_name);
|
2018-04-19 13:56:14 +00:00
|
|
|
res_columns[i++]->insert(DNSResolver::instance().resolveHost(address.host_name).toString());
|
2018-10-22 08:54:54 +00:00
|
|
|
res_columns[i++]->insert(address.port);
|
|
|
|
res_columns[i++]->insert(shard_info.isLocal());
|
2017-12-16 00:49:03 +00:00
|
|
|
res_columns[i++]->insert(address.user);
|
|
|
|
res_columns[i++]->insert(address.default_database);
|
2017-04-01 07:20:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto clusters = context.getClusters().getContainer();
|
|
|
|
for (const auto & entry : clusters)
|
|
|
|
{
|
|
|
|
const std::string cluster_name = entry.first;
|
|
|
|
const ClusterPtr cluster = entry.second;
|
2017-08-11 15:02:07 +00:00
|
|
|
const auto & addresses_with_failover = cluster->getShardsAddresses();
|
2017-04-01 07:20:54 +00:00
|
|
|
const auto & shards_info = cluster->getShardsInfo();
|
|
|
|
|
2017-08-11 15:02:07 +00:00
|
|
|
if (!addresses_with_failover.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
auto it1 = addresses_with_failover.cbegin();
|
|
|
|
auto it2 = shards_info.cbegin();
|
|
|
|
|
|
|
|
while (it1 != addresses_with_failover.cend())
|
|
|
|
{
|
|
|
|
const auto & addresses = *it1;
|
|
|
|
const auto & shard_info = *it2;
|
|
|
|
|
|
|
|
for (const auto & address : addresses)
|
|
|
|
updateColumns(cluster_name, shard_info, address);
|
|
|
|
|
|
|
|
++it1;
|
|
|
|
++it2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 12:43:16 +00:00
|
|
|
}
|
|
|
|
}
|