]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osdmap: filter out nonexistent osds from map
authorSage Weil <sage.weil@dreamhost.com>
Fri, 27 Apr 2012 00:42:12 +0000 (17:42 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Fri, 27 Apr 2012 00:42:29 +0000 (17:42 -0700)
It is possible that the crush map contains device ids that do not exist as
osds.  Filter them out of the CRUSH result.

Drop the max devices assert, as that is trivially violated by adding a new
item to the crush map beyond max_osd (via 'ceph osd crush add ...').

Signed-off-by: Sage Weil <sage@newdream.net>
src/osd/OSDMap.h

index 196c52e9261b69508c66b055776c52abcb4f7216..db5d0141d81e70a9c8f83f03769651d5a2cffbe4 100644 (file)
@@ -463,6 +463,27 @@ public:
 
   // pg -> (osd list)
 private:
+
+  /**
+   * remove any osds from the vector that do not exist in the map
+   *
+   * @param osds vector of osds to filter/modify
+   */
+  void _remove_nonexistent_osds(vector<int>& osds) const {
+    unsigned removed = 0;
+    for (unsigned i = 0; i < osds.size(); i++) {
+      if (!exists(osds[i])) {
+       removed++;
+       continue;
+      }
+      if (removed) {
+       osds[i - removed] = osds[i];
+      }
+    }
+    if (removed)
+      osds.resize(osds.size() - removed);
+  }
+
   int _pg_to_osds(const pg_pool_t& pool, pg_t pg, vector<int>& osds) const {
     // map to osds[]
     ps_t pps = pool.raw_pg_to_pps(pg);  // placement ps
@@ -472,14 +493,14 @@ private:
       if (preferred >= max_osd || preferred >= crush.get_max_devices())
        preferred = -1;
 
-      assert(get_max_osd() >= crush.get_max_devices());
-
       // what crush rule?
       int ruleno = crush.find_rule(pool.get_crush_ruleset(), pool.get_type(), size);
       if (ruleno >= 0)
        crush.do_rule(ruleno, pps, osds, size, preferred, osd_weight);
     }
   
+    _remove_nonexistent_osds(osds);
+
     return osds.size();
   }