2019-05-24 19:03:07 +00:00
|
|
|
#include <Columns/ColumnArray.h>
|
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <Storages/System/StorageSystemStoragePolicies.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemStoragePolicies::StorageSystemStoragePolicies(const std::string & name_)
|
2019-12-03 16:25:32 +00:00
|
|
|
: IStorage({"system", name_})
|
2019-05-24 19:03:07 +00:00
|
|
|
{
|
2019-09-09 13:50:19 +00:00
|
|
|
setColumns(
|
|
|
|
ColumnsDescription({
|
|
|
|
{"policy_name", std::make_shared<DataTypeString>()},
|
|
|
|
{"volume_name", std::make_shared<DataTypeString>()},
|
|
|
|
{"volume_priority", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"disks", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
|
|
|
|
{"max_data_part_size", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"move_factor", std::make_shared<DataTypeFloat32>()}
|
2019-05-24 19:03:07 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreams StorageSystemStoragePolicies::read(
|
|
|
|
const Names & column_names,
|
|
|
|
const SelectQueryInfo & /*query_info*/,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
|
|
|
const size_t /*max_block_size*/,
|
|
|
|
const unsigned /*num_streams*/)
|
|
|
|
{
|
|
|
|
check(column_names);
|
|
|
|
|
2019-09-09 13:50:19 +00:00
|
|
|
MutableColumnPtr col_policy_name = ColumnString::create();
|
|
|
|
MutableColumnPtr col_volume_name = ColumnString::create();
|
|
|
|
MutableColumnPtr col_priority = ColumnUInt64::create();
|
|
|
|
MutableColumnPtr col_disks = ColumnArray::create(ColumnString::create());
|
|
|
|
MutableColumnPtr col_max_part_size = ColumnUInt64::create();
|
|
|
|
MutableColumnPtr col_move_factor = ColumnFloat32::create();
|
2019-05-24 19:03:07 +00:00
|
|
|
|
|
|
|
const auto & policy_selector = context.getStoragePolicySelector();
|
|
|
|
|
2019-08-15 09:43:31 +00:00
|
|
|
for (const auto & [policy_name, policy_ptr] : policy_selector.getPoliciesMap())
|
2019-05-24 19:03:07 +00:00
|
|
|
{
|
|
|
|
const auto & volumes = policy_ptr->getVolumes();
|
|
|
|
for (size_t i = 0; i != volumes.size(); ++i)
|
|
|
|
{
|
2019-09-09 13:50:19 +00:00
|
|
|
col_policy_name->insert(policy_name);
|
|
|
|
col_volume_name->insert(volumes[i]->getName());
|
|
|
|
col_priority->insert(i + 1);
|
2019-05-24 19:03:07 +00:00
|
|
|
Array disks;
|
2019-07-23 13:34:17 +00:00
|
|
|
disks.reserve(volumes[i]->disks.size());
|
|
|
|
for (const auto & disk_ptr : volumes[i]->disks)
|
2019-05-24 19:03:07 +00:00
|
|
|
disks.push_back(disk_ptr->getName());
|
2019-09-09 13:50:19 +00:00
|
|
|
col_disks->insert(disks);
|
|
|
|
col_max_part_size->insert(volumes[i]->max_data_part_size);
|
|
|
|
col_move_factor->insert(policy_ptr->getMoveFactor());
|
2019-05-24 19:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Block res = getSampleBlock().cloneEmpty();
|
2019-09-09 13:50:19 +00:00
|
|
|
|
2019-05-24 19:03:07 +00:00
|
|
|
size_t col_num = 0;
|
2019-09-09 13:50:19 +00:00
|
|
|
res.getByPosition(col_num++).column = std::move(col_policy_name);
|
|
|
|
res.getByPosition(col_num++).column = std::move(col_volume_name);
|
|
|
|
res.getByPosition(col_num++).column = std::move(col_priority);
|
|
|
|
res.getByPosition(col_num++).column = std::move(col_disks);
|
|
|
|
res.getByPosition(col_num++).column = std::move(col_max_part_size);
|
|
|
|
res.getByPosition(col_num++).column = std::move(col_move_factor);
|
2019-05-24 19:03:07 +00:00
|
|
|
|
|
|
|
return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(res));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|