]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: use single helper for [near]full sets
authorSage Weil <sage@inktank.com>
Fri, 13 Jul 2012 14:27:36 +0000 (07:27 -0700)
committerSage Weil <sage@inktank.com>
Fri, 13 Jul 2012 14:28:08 +0000 (07:28 -0700)
Use a single helper to add/remove osds from the [near]full sets.  This
keeps the logic in a single place, and simplifies the code somewhat.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/PGMap.cc
src/mon/PGMap.h

index 1382e186929e03ec8016a43ca46e948f82712a35..e56e4925e53bc076834f93991b950b057d9b294c 100644 (file)
@@ -189,29 +189,15 @@ void PGMap::apply_incremental(const Incremental& inc)
     if (t == osd_stat.end()) {
       hash_map<int,osd_stat_t>::value_type v(osd, new_stats);
       osd_stat.insert(v);
-    }
-    else {
+    } else {
       stat_osd_sub(t->second);
       t->second = new_stats;
     }
-    
+
     stat_osd_add(new_stats);
     
-    //update the full/nearful_osd sets
-    int from = p->first;
-    float ratio = ((float)p->second.kb_used) / (float) p->second.kb;
-    if ( ratio > full_ratio ) {
-      full_osds.insert(from);
-      //sets don't double-insert so this might be a (very expensive) null-op
-    }
-    else if ( ratio > nearfull_ratio ) {
-      nearfull_osds.insert(from);
-      full_osds.erase(from);
-    }
-    else {//it's not full or near-full
-      full_osds.erase(from);
-      nearfull_osds.erase(from);
-    }
+    // adjust [near]full status
+    register_nearfull_status(osd, new_stats);
   }
   for (set<pg_t>::const_iterator p = inc.pg_remove.begin();
        p != inc.pg_remove.end();
@@ -247,11 +233,26 @@ void PGMap::redo_full_sets()
   for (hash_map<int, osd_stat_t>::iterator i = osd_stat.begin();
        i != osd_stat.end();
        ++i) {
-    float ratio = ((float)i->second.kb_used) / ((float)i->second.kb);
-    if (full_ratio > 0 && ratio > full_ratio)
-      full_osds.insert(i->first);
-    else if (nearfull_ratio > 0 && ratio > nearfull_ratio)
-      nearfull_osds.insert(i->first);
+    register_nearfull_status(i->first, i->second);
+  }
+}
+
+void PGMap::register_nearfull_status(int osd, const osd_stat_t& s)
+{
+  float ratio = ((float)s.kb_used) / ((float)s.kb);
+
+  if (full_ratio > 0 && ratio > full_ratio) {
+    // full
+    full_osds.insert(osd);
+    nearfull_osds.erase(osd);
+  } else if (nearfull_ratio > 0 && ratio > nearfull_ratio) {
+    // nearfull
+    full_osds.erase(osd);
+    nearfull_osds.insert(osd);
+  } else {
+    // ok
+    full_osds.erase(osd);
+    nearfull_osds.erase(osd);
   }
 }
 
index 46d057c6335ca5cc86c4a0377645be275c47eb08..affe4ff0b1c820ef8615fe4628942e0c09a50239 100644 (file)
@@ -89,6 +89,7 @@ public:
 
   void apply_incremental(const Incremental& inc);
   void redo_full_sets();
+  void register_nearfull_status(int osd, const osd_stat_t& s);
   void calc_stats();
   void stat_pg_add(const pg_t &pgid, const pg_stat_t &s);
   void stat_pg_sub(const pg_t &pgid, const pg_stat_t &s);