Add documentation and a very basic test for pool management commands

This commit is contained in:
Vitaliy Filippov
2024-02-28 13:08:04 +03:00
parent 86243b7101
commit 4eab26f968
11 changed files with 258 additions and 38 deletions
+10 -10
View File
@@ -121,15 +121,15 @@ static const char* help_text =
" Optional parameters:\n"
" --pg_minsize <number> R or N+K minus number of failures to tolerate without downtime\n"
" --failure_domain host Failure domain: host, osd or a level from placement_levels. Default: host\n"
" --root_node <node> Put pool on child OSDs of this placement tree node\n"
" --osd_tags <tag>[,<tag>]... Put pool on OSDs tagged with all specified tags\n"
" --block_size 128k Put pool on OSDs with this data block size\n"
" --bitmap_granularity 4k Put pool on OSDs with this logical sector size\n"
" --immediate_commit none Put pool on OSDs with this or larger immediate_commit (none < small < all)\n"
" --root_node <node> Put pool only on child OSDs of this placement tree node\n"
" --osd_tags <tag>[,<tag>]... Put pool only on OSDs tagged with all specified tags\n"
" --block_size 128k Put pool only on OSDs with this data block size\n"
" --bitmap_granularity 4k Put pool only on OSDs with this logical sector size\n"
" --immediate_commit none Put pool only on OSDs with this or larger immediate_commit (none < small < all)\n"
" --primary_affinity_tags tags Prefer to put primary copies on OSDs with all specified tags\n"
" --scrub_interval <time> Enable regular scrubbing for this pool. Format: number + unit s/m/h/d/M/y\n"
" --pg_stripe_size <number> Increase object grouping stripe. Default: block_size*data_parts\n"
" --max_osd_combinations 10000 Maximum number of random combinations for LP solver input. Default: 10000\n"
" --pg_stripe_size <number> Increase object grouping stripe\n"
" --max_osd_combinations 10000 Maximum number of random combinations for LP solver input\n"
" --wait Wait for the new pool to come online\n"
" -f|--force Do not check that cluster has enough OSDs to create the pool\n"
" Examples:\n"
@@ -151,13 +151,13 @@ static const char* help_text =
" vitastor-cli modify-pool 2 --pg_size 4 -n 128\n"
"\n"
"vitastor-cli rm-pool|pool-rm [--force] <id|name>\n"
" Remove existing pool. Refuses to remove pools with data without --force.\n"
" Remove a pool. Refuses to remove pools with images without --force.\n"
"\n"
"vitastor-cli ls-pools|pool-ls|ls-pool|pools [-l] [--detail] [--sort FIELD] [-r] [-n N] [--stats] [<glob> ...]\n"
" List pools (only matching <glob> patterns if passed).\n"
" -l|--long Also report PG states and I/O statistics\n"
" -l|--long Also report I/O statistics\n"
" --detail Use list format (not table), show all details\n"
" --sort FIELD Sort by specified field\n"
" --sort FIELD Sort by specified field (see fields in --json output)\n"
" -r|--reverse Sort in descending order\n"
" -n|--count N Only list first N items\n"
"\n"
+2 -1
View File
@@ -81,7 +81,8 @@ public:
std::string print_table(json11::Json items, json11::Json header, bool use_esc);
std::string print_detail(json11::Json item, std::vector<std::pair<std::string, std::string>> names, bool use_esc);
size_t print_detail_title_len(json11::Json item, std::vector<std::pair<std::string, std::string>> names, size_t prev_len);
std::string print_detail(json11::Json item, std::vector<std::pair<std::string, std::string>> names, size_t title_len, bool use_esc);
std::string format_lat(uint64_t lat);
+2 -1
View File
@@ -49,7 +49,7 @@ std::string validate_pool_config(json11::Json::object & new_cfg, json11::Json ol
// Default scheme
new_cfg["scheme"] = "replicated";
}
if (old_cfg.is_null() && !new_cfg["pg_minsize"].uint64_value())
if (new_cfg.find("pg_minsize") == new_cfg.end() && (old_cfg.is_null() || new_cfg.find("pg_size") != new_cfg.end()))
{
// Default pg_minsize
if (new_cfg["scheme"] == "replicated")
@@ -83,6 +83,7 @@ std::string validate_pool_config(json11::Json::object & new_cfg, json11::Json ol
{
return key+" must be a non-negative integer";
}
value = value.uint64_value();
}
else if (key == "name" || key == "scheme" || key == "immediate_commit" ||
key == "failure_domain" || key == "root_node" || key == "scrub_interval")
+15 -4
View File
@@ -562,11 +562,17 @@ resume_3:
{ "write_fmt", "Write" },
{ "delete_fmt", "Delete" },
};
for (auto & item: to_list())
auto list = to_list();
size_t title_len = 0;
for (auto & item: list)
{
title_len = print_detail_title_len(item, cols, title_len);
}
for (auto & item: list)
{
if (result.text != "")
result.text += "\n";
result.text += print_detail(item, cols, parent->color);
result.text += print_detail(item, cols, title_len, parent->color);
}
state = 100;
return;
@@ -631,9 +637,9 @@ resume_3:
}
};
std::string print_detail(json11::Json item, std::vector<std::pair<std::string, std::string>> names, bool use_esc)
size_t print_detail_title_len(json11::Json item, std::vector<std::pair<std::string, std::string>> names, size_t prev_len)
{
size_t title_len = 0;
size_t title_len = prev_len;
for (auto & kv: names)
{
if (!item[kv.first].is_null() && (!item[kv.first].is_string() || item[kv.first].string_value() != ""))
@@ -642,6 +648,11 @@ std::string print_detail(json11::Json item, std::vector<std::pair<std::string, s
title_len = title_len < len ? len : title_len;
}
}
return title_len;
}
std::string print_detail(json11::Json item, std::vector<std::pair<std::string, std::string>> names, size_t title_len, bool use_esc)
{
std::string str;
for (auto & kv: names)
{