Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add columns for table system.storage_policies #48167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/en/operations/system-tables/storage_policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ Columns:
- `volume_name` ([String](../../sql-reference/data-types/string.md)) — Volume name defined in the storage policy.
- `volume_priority` ([UInt64](../../sql-reference/data-types/int-uint.md)) — Volume order number in the configuration, the data fills the volumes according this priority, i.e. data during inserts and merges is written to volumes with a lower priority (taking into account other rules: TTL, `max_data_part_size`, `move_factor`).
- `disks` ([Array(String)](../../sql-reference/data-types/array.md)) — Disk names, defined in the storage policy.
- `volume_type` ([Enum8](../../sql-reference/data-types/enum.md)) — Type of volume. Can have one of the following values:
- `JBOD`
- `SINGLE_DISK`
- `UNKNOWN`
- `max_data_part_size` ([UInt64](../../sql-reference/data-types/int-uint.md)) — Maximum size of a data part that can be stored on volume disks (0 — no limit).
- `move_factor` ([Float64](../../sql-reference/data-types/float.md)) — Ratio of free disk space. When the ratio exceeds the value of configuration parameter, ClickHouse start to move data to the next volume in order.
- `prefer_not_to_merge` ([UInt8](../../sql-reference/data-types/int-uint.md)) — Value of the `prefer_not_to_merge` setting. When this setting is enabled, merging data on this volume is not allowed. This allows controlling how ClickHouse works with slow disks.
- `perform_ttl_move_on_insert` ([UInt8](../../sql-reference/data-types/int-uint.md)) — Value of the `perform_ttl_move_on_insert` setting. — Disables TTL move on data part INSERT. By default if we insert a data part that already expired by the TTL move rule it immediately goes to a volume/disk declared in move rule. This can significantly slowdown insert in case if destination volume/disk is slow (e.g. S3).
- `load_balancing` ([Enum8](../../sql-reference/data-types/enum.md)) — Policy for disk balancing. Can have one of the following values:
- `ROUND_ROBIN`
- `LEAST_USED`

If the storage policy contains more then one volume, then information for each volume is stored in the individual row of the table.
29 changes: 25 additions & 4 deletions src/Storages/System/StorageSystemStoragePolicies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <Columns/ColumnArray.h>
#include <Columns/ColumnNullable.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeEnum.h>
#include <DataTypes/DataTypeNullable.h>
#include <Processors/Sources/SourceFromSingleChunk.h>
#include <Interpreters/Context.h>
Expand All @@ -17,6 +18,18 @@ namespace ErrorCodes
{
}

namespace
{
template <typename Type>
DataTypeEnum8::Values getTypeEnumValues()
{
DataTypeEnum8::Values enum_values;
for (auto value : magic_enum::enum_values<Type>())
enum_values.emplace_back(magic_enum::enum_name(value), magic_enum::enum_integer(value));
return enum_values;
}
}


StorageSystemStoragePolicies::StorageSystemStoragePolicies(const StorageID & table_id_)
: IStorage(table_id_)
Expand All @@ -28,10 +41,12 @@ StorageSystemStoragePolicies::StorageSystemStoragePolicies(const StorageID & tab
{"volume_name", std::make_shared<DataTypeString>()},
{"volume_priority", std::make_shared<DataTypeUInt64>()},
{"disks", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
{"volume_type", std::make_shared<DataTypeString>()},
{"volume_type", std::make_shared<DataTypeEnum8>(getTypeEnumValues<VolumeType>())},
{"max_data_part_size", std::make_shared<DataTypeUInt64>()},
{"move_factor", std::make_shared<DataTypeFloat32>()},
{"prefer_not_to_merge", std::make_shared<DataTypeUInt8>()}
{"prefer_not_to_merge", std::make_shared<DataTypeUInt8>()},
{"perform_ttl_move_on_insert", std::make_shared<DataTypeUInt8>()},
{"load_balancing", std::make_shared<DataTypeEnum8>(getTypeEnumValues<VolumeLoadBalancing>())}
}));
// TODO: Add string column with custom volume-type-specific options
setInMemoryMetadata(storage_metadata);
Expand All @@ -52,10 +67,12 @@ Pipe StorageSystemStoragePolicies::read(
MutableColumnPtr col_volume_name = ColumnString::create();
MutableColumnPtr col_priority = ColumnUInt64::create();
MutableColumnPtr col_disks = ColumnArray::create(ColumnString::create());
MutableColumnPtr col_volume_type = ColumnString::create();
MutableColumnPtr col_volume_type = ColumnInt8::create();
MutableColumnPtr col_max_part_size = ColumnUInt64::create();
MutableColumnPtr col_move_factor = ColumnFloat32::create();
MutableColumnPtr col_prefer_not_to_merge = ColumnUInt8::create();
MutableColumnPtr col_perform_ttl_move_on_insert = ColumnUInt8::create();
MutableColumnPtr col_load_balancing = ColumnInt8::create();

for (const auto & [policy_name, policy_ptr] : context->getPoliciesMap())
{
Expand All @@ -70,10 +87,12 @@ Pipe StorageSystemStoragePolicies::read(
for (const auto & disk_ptr : volumes[i]->getDisks())
disks.push_back(disk_ptr->getName());
col_disks->insert(disks);
col_volume_type->insert(magic_enum::enum_name(volumes[i]->getType()));
col_volume_type->insert(static_cast<Int8>(volumes[i]->getType()));
col_max_part_size->insert(volumes[i]->max_data_part_size);
col_move_factor->insert(policy_ptr->getMoveFactor());
col_prefer_not_to_merge->insert(volumes[i]->areMergesAvoided() ? 1 : 0);
col_perform_ttl_move_on_insert->insert(volumes[i]->perform_ttl_move_on_insert);
col_load_balancing->insert(static_cast<Int8>(volumes[i]->load_balancing));
}
}

Expand All @@ -86,6 +105,8 @@ Pipe StorageSystemStoragePolicies::read(
res_columns.emplace_back(std::move(col_max_part_size));
res_columns.emplace_back(std::move(col_move_factor));
res_columns.emplace_back(std::move(col_prefer_not_to_merge));
res_columns.emplace_back(std::move(col_perform_ttl_move_on_insert));
res_columns.emplace_back(std::move(col_load_balancing));

UInt64 num_rows = res_columns.at(0)->size();
Chunk chunk(std::move(res_columns), num_rows);
Expand Down
32 changes: 32 additions & 0 deletions tests/integration/test_multiple_disks/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "small_jbod_with_external",
Expand All @@ -100,6 +102,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "small_jbod_with_external_no_merges",
Expand All @@ -110,6 +114,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "small_jbod_with_external_no_merges",
Expand All @@ -120,6 +126,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 1,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "one_more_small_jbod_with_external",
Expand All @@ -130,6 +138,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "one_more_small_jbod_with_external",
Expand All @@ -140,6 +150,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "jbods_with_external",
Expand All @@ -150,6 +162,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "10485760",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "jbods_with_external",
Expand All @@ -160,6 +174,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "moving_jbod_with_external",
Expand All @@ -170,6 +186,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.7,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "moving_jbod_with_external",
Expand All @@ -180,6 +198,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.7,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "default_disk_with_external",
Expand All @@ -190,6 +210,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "2097152",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "default_disk_with_external",
Expand All @@ -200,6 +222,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "20971520",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "special_warning_policy",
Expand All @@ -210,6 +234,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "special_warning_policy",
Expand All @@ -220,6 +246,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "0",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "special_warning_policy",
Expand All @@ -230,6 +258,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "1024",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
{
"policy_name": "special_warning_policy",
Expand All @@ -240,6 +270,8 @@ def test_system_tables(start_cluster):
"max_data_part_size": "1024000000",
"move_factor": 0.1,
"prefer_not_to_merge": 0,
"perform_ttl_move_on_insert": 1,
"load_balancing": "ROUND_ROBIN",
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,12 @@ CREATE TABLE system.storage_policies
`volume_name` String,
`volume_priority` UInt64,
`disks` Array(String),
`volume_type` String,
`volume_type` Enum8('JBOD' = 0, 'SINGLE_DISK' = 1, 'UNKNOWN' = 2),
`max_data_part_size` UInt64,
`move_factor` Float32,
`prefer_not_to_merge` UInt8
`prefer_not_to_merge` UInt8,
`perform_ttl_move_on_insert` UInt8,
`load_balancing` Enum8('ROUND_ROBIN' = 0, 'LEAST_USED' = 1)
)
ENGINE = SystemStoragePolicies
COMMENT 'SYSTEM TABLE is built on the fly.'
Expand Down