From 8243dcbcc9822a591fc05b5fce9173d9f4d71a24 Mon Sep 17 00:00:00 2001 From: David Zafman Date: Wed, 6 Nov 2019 20:32:48 -0800 Subject: [PATCH] tools: osdmaptool: Perform upmap calculation as ceph-mgr does This is the backportable commit that works with older balancer module.py Signed-off-by: David Zafman (cherry picked from commit b946308f03f1798915fafe7878f34b4a234c2ae4) --- src/test/cli/osdmaptool/upmap-out.t | 2 ++ src/test/cli/osdmaptool/upmap.t | 2 ++ src/tools/osdmaptool.cc | 51 +++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/test/cli/osdmaptool/upmap-out.t b/src/test/cli/osdmaptool/upmap-out.t index 18641b18e7abb..54a1def1a9603 100644 --- a/src/test/cli/osdmaptool/upmap-out.t +++ b/src/test/cli/osdmaptool/upmap-out.t @@ -8,6 +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 $ 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 fd6541c2f96f1..4ff14306fe113 100644 --- a/src/test/cli/osdmaptool/upmap.t +++ b/src/test/cli/osdmaptool/upmap.t @@ -7,6 +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 $ 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 8a65c32797a73..94be3cb225c46 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -19,6 +19,7 @@ #include "common/errno.h" #include "common/safe_io.h" #include "mon/health_check.h" +#include #include "global/global_init.h" #include "osd/OSDMap.h" @@ -368,23 +369,50 @@ int main(int argc, const char **argv) << std::endl; OSDMap::Incremental pending_inc(osdmap.get_epoch()+1); pending_inc.fsid = osdmap.get_fsid(); - set pools; + vector pools; for (auto& s : upmap_pools) { int64_t p = osdmap.lookup_pg_pool_name(s); if (p < 0) { - cerr << " pool '" << s << "' does not exist" << std::endl; + cerr << " pool " << s << " does not exist" << std::endl; exit(1); } - pools.insert(p); + pools.push_back(p); } - if (!pools.empty()) + if (!pools.empty()) { cout << " limiting to pools " << upmap_pools << " (" << pools << ")" << std::endl; - int changed = osdmap.calc_pg_upmaps( - g_ceph_context, upmap_deviation, - upmap_max, pools, - &pending_inc); - if (changed) { + } else { + mempool::osdmap::map opools = osdmap.get_pools(); + for (auto& i : opools) { + pools.push_back(i.first); + } + } + if (pools.empty()) { + cout << "No pools available" << std::endl; + goto skip_upmap; + } + srand(time(0)); + random_shuffle (pools.begin(), pools.end()); + cout << "pools "; + for (auto& i: pools) + cout << osdmap.get_pool_name(i) << " "; + cout << std::endl; + int total_did = 0; + int left = upmap_max; + for (auto& i: pools) { + set one_pool; + one_pool.insert(i); + int did = osdmap.calc_pg_upmaps( + g_ceph_context, upmap_deviation, + left, one_pool, + &pending_inc); + total_did += did; + left -= did; + if (left <= 0) + break; + } + cout << "prepared " << total_did << "/" << upmap_max << " changes" << std::endl; + if (total_did > 0) { print_inc_upmaps(pending_inc, upmap_fd); if (upmap_save) { int r = osdmap.apply_incremental(pending_inc); @@ -392,9 +420,12 @@ int main(int argc, const char **argv) modified = true; } } else { - cout << "no upmaps proposed" << std::endl; + cout << "Unable to find further optimization, " + << "or distribution is already perfect" + << std::endl; } } +skip_upmap: if (upmap_file != "-") { ::close(upmap_fd); } -- 2.39.5