ClickHouse/dbms/src/Storages/System/StorageSystemClusters.cpp

63 lines
2.5 KiB
C++
Raw Normal View History

#include <Common/DNSResolver.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/Cluster.h>
#include <Interpreters/Context.h>
#include <Storages/System/StorageSystemClusters.h>
2015-04-30 12:43:16 +00:00
namespace DB
{
2018-07-24 18:46:23 +00:00
NamesAndTypesList StorageSystemClusters::getNamesAndTypes()
{
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
}
void StorageSystemClusters::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
2015-04-30 12:43:16 +00:00
{
2018-12-02 02:17:08 +00:00
for (const auto & name_and_cluster : context.getClusters().getContainer())
2018-07-24 18:46:23 +00:00
{
2018-12-02 02:17:08 +00:00
const String & cluster_name = name_and_cluster.first;
const ClusterPtr & cluster = name_and_cluster.second;
const auto & shards_info = cluster->getShardsInfo();
2018-12-02 02:17:08 +00:00
const auto & addresses_with_failover = cluster->getShardsAddresses();
2018-12-02 02:17:08 +00:00
for (size_t shard_index = 0; shard_index < shards_info.size(); ++shard_index)
{
2018-12-02 02:17:08 +00:00
const auto & shard_info = shards_info[shard_index];
const auto & shard_addresses = addresses_with_failover[shard_index];
2018-12-02 02:17:08 +00:00
for (size_t replica_index = 0; replica_index < shard_addresses.size(); ++replica_index)
{
2018-12-02 02:17:08 +00:00
size_t i = 0;
const auto & address = shard_addresses[replica_index];
res_columns[i++]->insert(cluster_name);
res_columns[i++]->insert(shard_info.shard_num);
res_columns[i++]->insert(shard_info.weight);
res_columns[i++]->insert(replica_index + 1);
res_columns[i++]->insert(address.host_name);
auto resolved = address.getResolvedAddress();
res_columns[i++]->insert(resolved ? resolved->host().toString() : String());
2018-12-02 02:17:08 +00:00
res_columns[i++]->insert(address.port);
res_columns[i++]->insert(shard_info.isLocal());
res_columns[i++]->insert(address.user);
res_columns[i++]->insert(address.default_database);
}
}
}
2015-04-30 12:43:16 +00:00
}
}