]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: handle sparse type names 15179/head
authorSage Weil <sage@redhat.com>
Fri, 19 May 2017 16:05:08 +0000 (12:05 -0400)
committerSage Weil <sage@redhat.com>
Fri, 19 May 2017 16:05:08 +0000 (12:05 -0400)
It's possible a type id isn't defined/used by crush.  Use the max id
instead and skip types without names.

Signed-off-by: Sage Weil <sage@redhat.com>
src/crush/CrushWrapper.h
src/mon/OSDMonitor.cc

index 57aa001cfb57b87db70a7456182961bd6e0551f6..8a5f4a41123233b93034d0bd173ad2a079e47572 100644 (file)
@@ -356,6 +356,11 @@ public:
   int get_num_type_names() const {
     return type_map.size();
   }
+  int get_max_type_id() const {
+    if (type_map.empty())
+      return 0;
+    return type_map.rbegin()->first;
+  }
   int get_type_id(const string& name) const {
     build_rmaps();
     if (type_rmap.count(name))
index b271855f019a80f6abe1138190fdacfb325c1e6b..e28621cffafda6770fdd6600f5232e85c7307fa7 100644 (file)
@@ -3486,7 +3486,7 @@ void OSDMonitor::get_health(list<pair<health_status_t,string> >& summary,
     set<int> subtree_up;
     unordered_map<int, set<int> > subtree_type_down;
     unordered_map<int, int> num_osds_subtree;
-    int max_type = osdmap.crush->get_num_type_names() - 1;
+    int max_type = osdmap.crush->get_max_type_id();
 
     for (int i = 0; i < osdmap.get_max_osd(); i++) {
       if (!osdmap.exists(i)) {
@@ -3505,6 +3505,8 @@ void OSDMonitor::get_health(list<pair<health_status_t,string> >& summary,
        int parent_id = 0;
        int current = i;
        for (int type = 0; type <= max_type; type++) {
+         if (!osdmap.crush->get_type_name(type))
+           continue;
          int r = osdmap.crush->get_immediate_parent_id(current, &parent_id);
          if (r == -ENOENT)
            break;
@@ -3524,6 +3526,8 @@ void OSDMonitor::get_health(list<pair<health_status_t,string> >& summary,
     // calculate the number of down osds in each down subtree and
     // store it in num_osds_subtree
     for (int type = 1; type <= max_type; type++) {
+      if (!osdmap.crush->get_type_name(type))
+       continue;
       for (auto j = subtree_type_down[type].begin();
           j != subtree_type_down[type].end();
           ++j) {
@@ -3551,6 +3555,8 @@ void OSDMonitor::get_health(list<pair<health_status_t,string> >& summary,
     if (num_down_in_osds > 0) {
       // summary of down subtree types and osds
       for (int type = max_type; type > 0; type--) {
+       if (!osdmap.crush->get_type_name(type))
+         continue;
        if (subtree_type_down[type].size() > 0) {
          ostringstream ss;
          ss << subtree_type_down[type].size() << " "
@@ -3575,6 +3581,8 @@ void OSDMonitor::get_health(list<pair<health_status_t,string> >& summary,
       if (detail) {
        // details of down subtree types
        for (int type = max_type; type > 0; type--) {
+         if (!osdmap.crush->get_type_name(type))
+           continue;
          for (auto j = subtree_type_down[type].rbegin();
               j != subtree_type_down[type].rend();
               ++j) {