From ce7e0be100f85e20cb21250cb59d4282f78fc041 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 13 Jul 2012 07:27:36 -0700 Subject: [PATCH] mon: use single helper for [near]full sets 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 --- src/mon/PGMap.cc | 47 ++++++++++++++++++++++++----------------------- src/mon/PGMap.h | 1 + 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 1382e186929e0..e56e4925e53bc 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -189,29 +189,15 @@ void PGMap::apply_incremental(const Incremental& inc) if (t == osd_stat.end()) { hash_map::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::const_iterator p = inc.pg_remove.begin(); p != inc.pg_remove.end(); @@ -247,11 +233,26 @@ void PGMap::redo_full_sets() for (hash_map::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); } } diff --git a/src/mon/PGMap.h b/src/mon/PGMap.h index 46d057c6335ca..affe4ff0b1c82 100644 --- a/src/mon/PGMap.h +++ b/src/mon/PGMap.h @@ -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); -- 2.47.3