]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools: osdmaptool: Perform upmap calculation as ceph-mgr does
authorDavid Zafman <dzafman@redhat.com>
Thu, 7 Nov 2019 04:32:48 +0000 (20:32 -0800)
committerDavid Zafman <dzafman@redhat.com>
Thu, 28 Nov 2019 00:29:29 +0000 (16:29 -0800)
This is the backportable commit that works with older balancer module.py

Signed-off-by: David Zafman <dzafman@redhat.com>
src/test/cli/osdmaptool/upmap-out.t
src/test/cli/osdmaptool/upmap.t
src/tools/osdmaptool.cc

index 18641b18e7abb19b9a45a19dd7753b3a81cab800..54a1def1a9603b848f23d1e33df4467c5b9a7b9a 100644 (file)
@@ -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
index fd6541c2f96f189f9ca6f4b8b27c53a46bee706b..4ff14306fe1136b3dbfc6c9058b72fded754720e 100644 (file)
@@ -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
index c918a2d44e329593f77579da1086df77489435c6..f50cfd626cd2ce291e2fe466132d59c7e0f2ecc4 100644 (file)
@@ -19,6 +19,7 @@
 #include "common/errno.h"
 #include "common/safe_io.h"
 #include "mon/health_check.h"
+#include <algorithm>
 
 #include "global/global_init.h"
 #include "osd/OSDMap.h"
@@ -376,23 +377,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<int64_t> pools;
+    vector<int64_t> 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<int64_t,pg_pool_t> 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<int64_t> 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);
@@ -400,9 +428,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);
   }