]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: osdmaptool sync with balancer module behavior
authorDavid Zafman <dzafman@redhat.com>
Sat, 9 Nov 2019 00:23:14 +0000 (16:23 -0800)
committerDavid Zafman <dzafman@redhat.com>
Thu, 28 Nov 2019 00:29:29 +0000 (16:29 -0800)
This can be backported only to nautilus

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 54a1def1a9603b848f23d1e33df4467c5b9a7b9a..8c0f43589773c721e26d8b14d06ea295573f14d3 100644 (file)
@@ -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
index 4ff14306fe1136b3dbfc6c9058b72fded754720e..17683eb4b25b785186005b9bd2e1111b22da4eb6 100644 (file)
@@ -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
index f50cfd626cd2ce291e2fe466132d59c7e0f2ecc4..cb9787dd691ff8f7defc9c185d6ad1d250713107 100644 (file)
@@ -147,6 +147,7 @@ int main(int argc, const char **argv)
   std::set<std::string> 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<int64_t> > 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<int> 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<int64_t> 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;
     }