]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: factor out count_metadata w/ counter helper
authorSage Weil <sage@redhat.com>
Thu, 20 Jul 2017 20:25:42 +0000 (16:25 -0400)
committerSage Weil <sage@redhat.com>
Fri, 21 Jul 2017 15:25:04 +0000 (11:25 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/MDSMonitor.cc
src/mon/MDSMonitor.h
src/mon/MgrMonitor.cc
src/mon/MgrMonitor.h
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index 690e20571a480c417129fb56375ca70218681f5e..f265134feb09d0062df6738194284373afed118c 100644 (file)
@@ -1864,19 +1864,24 @@ int MDSMonitor::load_metadata(map<mds_gid_t, Metadata>& m)
   return 0;
 }
 
-void MDSMonitor::count_metadata(const string& field, Formatter *f)
+void MDSMonitor::count_metadata(const string& field, map<string,int> *out)
 {
-  map<string,int> by_val;
   map<mds_gid_t,Metadata> 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<string,int> 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);
index 05946b51c3c81abae0379639b40f682301fd7365..4850b1112b3fbe0ab63f6a98690a4d90b9a3db66 100644 (file)
@@ -139,6 +139,9 @@ class MDSMonitor : public PaxosService {
   void remove_from_metadata(MonitorDBStore::TransactionRef t);
   int load_metadata(map<mds_gid_t, Metadata>& m);
   void count_metadata(const string& field, Formatter *f);
+public:
+  void count_metadata(const string& field, map<string,int> *out);
+protected:
 
   // MDS daemon GID to latest health state from that GID
   std::map<uint64_t, MDSHealth> pending_daemon_health;
index 3e4562da0a5c4de03d9473b41ff8805448d61d70..5f1f06bdede67335117332cb1bcc42d9f2d7f93a 100644 (file)
@@ -897,20 +897,25 @@ int MgrMonitor::load_metadata(const string& name, std::map<string, string>& m,
   return 0;
 }
 
-void MgrMonitor::count_metadata(const string& field, Formatter *f)
+void MgrMonitor::count_metadata(const string& field, std::map<string,int> *out)
 {
-  std::map<string,int> by_val;
   std::set<string> ls = map.get_all_names();
   for (auto& name : ls) {
     std::map<string,string> 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<string,int> 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);
index 44f28379ccefb9db250fec0cfd382310b48b263d..f63fb714f795d6be8bb5d01eb207593225a09860 100644 (file)
@@ -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<string,int> *out);
 
   friend class C_Updated;
 };
index 9ec308d7832a06c744082785b104f2251a73a310..de7ec98960fb33e2868b459d37250f961daa7373 100644 (file)
@@ -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<string,int> *out)
 {
-  map<string,int> 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<string,int> 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);
index fafadada9984c96007bd8caa86f6dc1bcd74d996..2716f0cb5d0dcdbbe80ec61e50bf68165f686220 100644 (file)
@@ -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<string,int> *out);
 
   // features
   static CompatSet get_initial_supported_features();
index 96eabc5794233a17125836a524422167ba9e4d3c..82fd1cfae43821482eb561911a97642d61fe92fb 100644 (file)
@@ -1226,21 +1226,26 @@ int OSDMonitor::load_metadata(int osd, map<string, string>& m, ostream *err)
   return 0;
 }
 
-void OSDMonitor::count_metadata(const string& field, Formatter *f)
+void OSDMonitor::count_metadata(const string& field, map<string,int> *out)
 {
-  map<string,int> by_val;
   for (int osd = 0; osd < osdmap.get_max_osd(); ++osd) {
     if (osdmap.is_up(osd)) {
       map<string,string> 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<string,int> 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);
index ccc123188e72c13b28a22a66ba9836137b914856..37742af38c3308fbc5283bb981f7ad7451770540 100644 (file)
@@ -428,6 +428,9 @@ private:
 
   int load_metadata(int osd, map<string, string>& m, ostream *err);
   void count_metadata(const string& field, Formatter *f);
+public:
+  void count_metadata(const string& field, map<string,int> *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);