From f165d4ca39b1edef4bf22a7597af79339c95026f Mon Sep 17 00:00:00 2001 From: David Zafman Date: Fri, 8 Nov 2019 16:23:14 -0800 Subject: [PATCH] tools: osdmaptool sync with balancer module behavior This can be backported only to nautilus Signed-off-by: David Zafman --- src/test/cli/osdmaptool/upmap-out.t | 4 +- src/test/cli/osdmaptool/upmap.t | 4 +- src/tools/osdmaptool.cc | 60 ++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/test/cli/osdmaptool/upmap-out.t b/src/test/cli/osdmaptool/upmap-out.t index 54a1def1a9603..8c0f43589773c 100644 --- a/src/test/cli/osdmaptool/upmap-out.t +++ b/src/test/cli/osdmaptool/upmap-out.t @@ -8,8 +8,8 @@ writing upmap command output to: c checking for upmap cleanups upmap, max-count 11, max deviation 0.01 - pools rbd - prepared 11/11 changes + prepared 11 changes for pools(s) rbd + prepared 11 changes in total $ cat c ceph osd pg-upmap-items 1.7 142 145 ceph osd pg-upmap-items 1.8 219 223 diff --git a/src/test/cli/osdmaptool/upmap.t b/src/test/cli/osdmaptool/upmap.t index 4ff14306fe113..17683eb4b25b7 100644 --- a/src/test/cli/osdmaptool/upmap.t +++ b/src/test/cli/osdmaptool/upmap.t @@ -7,8 +7,8 @@ writing upmap command output to: c checking for upmap cleanups upmap, max-count 11, max deviation 0.01 - pools rbd - prepared 11/11 changes + prepared 11 changes for pools(s) rbd + prepared 11 changes in total $ cat c ceph osd pg-upmap-items 1.7 142 147 ceph osd pg-upmap-items 1.8 219 223 diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index f50cfd626cd2c..cb9787dd691ff 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -147,6 +147,7 @@ int main(int argc, const char **argv) std::set upmap_pools; int64_t pg_num = -1; bool test_map_pgs_dump_all = false; + bool debug = false; std::string val; std::ostringstream err; @@ -186,6 +187,8 @@ int main(int argc, const char **argv) createsimple = true; } else if (ceph_argparse_flag(args, i, "--health", (char*)NULL)) { health = true; + } else if (ceph_argparse_flag(args, i, "--debug", (char*)NULL)) { + debug = true; } else if (ceph_argparse_flag(args, i, "--with-default-pool", (char*)NULL)) { createpool = true; } else if (ceph_argparse_flag(args, i, "--create-from-conf", (char*)NULL)) { @@ -399,27 +402,55 @@ int main(int argc, const char **argv) cout << "No pools available" << std::endl; goto skip_upmap; } + if (debug) { + cout << "pools "; + for (auto& i: pools) + cout << osdmap.get_pool_name(i) << " "; + cout << std::endl; + } + map< int, set > pools_by_rule; + for (auto&i: pools) { + const string& pool_name = osdmap.get_pool_name(i); + const pg_pool_t *p = osdmap.get_pg_pool(i); + const int rule = p->get_crush_rule(); + if (!osdmap.crush->rule_exists(rule)) { + cout << " pool " << pool_name << " does not exist" << std::endl; + continue; + } + if (p->get_pg_num() > p->get_pg_num_target()) { + cout << "pool " << pool_name << " has pending PG(s) for merging, skipping for now" << std::endl; + continue; + } + if (debug) { + cout << "pool " << i << " rule " << rule << std::endl; + } + pools_by_rule[rule].emplace(i); + } + vector rules; + for (auto& r: pools_by_rule) + rules.push_back(r.first); srand(time(0)); - random_shuffle (pools.begin(), pools.end()); - cout << "pools "; - for (auto& i: pools) - cout << osdmap.get_pool_name(i) << " "; - cout << std::endl; + random_shuffle (rules.begin(), rules.end()); + if (debug) { + for (auto& r: rules) + cout << "rule: " << r << " " << pools_by_rule[r] << std::endl; + } int total_did = 0; - int left = upmap_max; - for (auto& i: pools) { - set one_pool; - one_pool.insert(i); + int available = upmap_max; + for (auto& r: rules) { + // Assume all PGs are active+clean + // available = upmap_max - (num_pg - num_pg_active_clean) int did = osdmap.calc_pg_upmaps( g_ceph_context, upmap_deviation, - left, one_pool, + available, pools_by_rule[r], &pending_inc); + cout << "prepared " << did << " changes for pools(s) "; + for (auto i: pools_by_rule[r]) + cout << osdmap.get_pool_name(i) << " "; + cout << std::endl; total_did += did; - left -= did; - if (left <= 0) - break; } - cout << "prepared " << total_did << "/" << upmap_max << " changes" << std::endl; + cout << "prepared " << total_did << " changes in total" << std::endl; if (total_did > 0) { print_inc_upmaps(pending_inc, upmap_fd); if (upmap_save) { @@ -429,6 +460,7 @@ int main(int argc, const char **argv) } } else { cout << "Unable to find further optimization, " + << "or pool(s) pg_num is decreasing, " << "or distribution is already perfect" << std::endl; } -- 2.39.5