From 4f1db4c4379cd4dc2e8eee2369388b30cfaed6ae Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 20 Jul 2017 16:25:42 -0400 Subject: [PATCH] mon: factor out count_metadata w/ counter helper Signed-off-by: Sage Weil --- src/mon/MDSMonitor.cc | 13 +++++++++---- src/mon/MDSMonitor.h | 3 +++ src/mon/MgrMonitor.cc | 13 +++++++++---- src/mon/MgrMonitor.h | 1 + src/mon/Monitor.cc | 13 +++++++++---- src/mon/Monitor.h | 1 + src/mon/OSDMonitor.cc | 13 +++++++++---- src/mon/OSDMonitor.h | 3 +++ 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index 690e20571a4..f265134feb0 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -1864,19 +1864,24 @@ int MDSMonitor::load_metadata(map& m) return 0; } -void MDSMonitor::count_metadata(const string& field, Formatter *f) +void MDSMonitor::count_metadata(const string& field, map *out) { - map by_val; map meta; load_metadata(meta); for (auto& p : meta) { auto q = p.second.find(field); if (q == p.second.end()) { - by_val["unknown"]++; + (*out)["unknown"]++; } else { - by_val[q->second]++; + (*out)[q->second]++; } } +} + +void MDSMonitor::count_metadata(const string& field, Formatter *f) +{ + map by_val; + count_metadata(field, &by_val); f->open_object_section(field.c_str()); for (auto& p : by_val) { f->dump_int(p.first.c_str(), p.second); diff --git a/src/mon/MDSMonitor.h b/src/mon/MDSMonitor.h index 05946b51c3c..4850b1112b3 100644 --- a/src/mon/MDSMonitor.h +++ b/src/mon/MDSMonitor.h @@ -139,6 +139,9 @@ class MDSMonitor : public PaxosService { void remove_from_metadata(MonitorDBStore::TransactionRef t); int load_metadata(map& m); void count_metadata(const string& field, Formatter *f); +public: + void count_metadata(const string& field, map *out); +protected: // MDS daemon GID to latest health state from that GID std::map pending_daemon_health; diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index 3e4562da0a5..5f1f06bdede 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -897,20 +897,25 @@ int MgrMonitor::load_metadata(const string& name, std::map& m, return 0; } -void MgrMonitor::count_metadata(const string& field, Formatter *f) +void MgrMonitor::count_metadata(const string& field, std::map *out) { - std::map by_val; std::set ls = map.get_all_names(); for (auto& name : ls) { std::map meta; load_metadata(name, meta, nullptr); auto p = meta.find(field); if (p == meta.end()) { - by_val["unknown"]++; + (*out)["unknown"]++; } else { - by_val[p->second]++; + (*out)[p->second]++; } } +} + +void MgrMonitor::count_metadata(const string& field, Formatter *f) +{ + std::map by_val; + count_metadata(field, &by_val); f->open_object_section(field.c_str()); for (auto& p : by_val) { f->dump_int(p.first.c_str(), p.second); diff --git a/src/mon/MgrMonitor.h b/src/mon/MgrMonitor.h index 44f28379cce..f63fb714f79 100644 --- a/src/mon/MgrMonitor.h +++ b/src/mon/MgrMonitor.h @@ -107,6 +107,7 @@ public: ostream *err); int dump_metadata(const string& name, Formatter *f, ostream *err); void count_metadata(const string& field, Formatter *f); + void count_metadata(const string& field, std::map *out); friend class C_Updated; }; diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 9ec308d7832..de7ec98960f 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -5011,17 +5011,22 @@ int Monitor::get_mon_metadata(int mon, Formatter *f, ostream& err) return 0; } -void Monitor::count_metadata(const string& field, Formatter *f) +void Monitor::count_metadata(const string& field, map *out) { - map by_val; for (auto& p : mon_metadata) { auto q = p.second.find(field); if (q == p.second.end()) { - by_val["unknown"]++; + (*out)["unknown"]++; } else { - by_val[q->second]++; + (*out)[q->second]++; } } +} + +void Monitor::count_metadata(const string& field, Formatter *f) +{ + map by_val; + count_metadata(field, &by_val); f->open_object_section(field.c_str()); for (auto& p : by_val) { f->dump_int(p.first.c_str(), p.second); diff --git a/src/mon/Monitor.h b/src/mon/Monitor.h index fafadada998..2716f0cb5d0 100644 --- a/src/mon/Monitor.h +++ b/src/mon/Monitor.h @@ -901,6 +901,7 @@ public: void update_mon_metadata(int from, Metadata&& m); int load_metadata(); void count_metadata(const string& field, Formatter *f); + void count_metadata(const string& field, map *out); // features static CompatSet get_initial_supported_features(); diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 96eabc57942..82fd1cfae43 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -1226,21 +1226,26 @@ int OSDMonitor::load_metadata(int osd, map& m, ostream *err) return 0; } -void OSDMonitor::count_metadata(const string& field, Formatter *f) +void OSDMonitor::count_metadata(const string& field, map *out) { - map by_val; for (int osd = 0; osd < osdmap.get_max_osd(); ++osd) { if (osdmap.is_up(osd)) { map meta; load_metadata(osd, meta, nullptr); auto p = meta.find(field); if (p == meta.end()) { - by_val["unknown"]++; + (*out)["unknown"]++; } else { - by_val[p->second]++; + (*out)[p->second]++; } } } +} + +void OSDMonitor::count_metadata(const string& field, Formatter *f) +{ + map by_val; + count_metadata(field, &by_val); f->open_object_section(field.c_str()); for (auto& p : by_val) { f->dump_int(p.first.c_str(), p.second); diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index ccc123188e7..37742af38c3 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -428,6 +428,9 @@ private: int load_metadata(int osd, map& m, ostream *err); void count_metadata(const string& field, Formatter *f); +public: + void count_metadata(const string& field, map *out); +protected: int get_osd_objectstore_type(int osd, std::string *type); bool is_pool_currently_all_bluestore(int64_t pool_id, const pg_pool_t &pool, ostream *err); -- 2.39.5