]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: give PGMonitor and MgrMonitor their own PGStatService implementations
authorGreg Farnum <gfarnum@redhat.com>
Tue, 9 May 2017 20:06:56 +0000 (13:06 -0700)
committerSage Weil <sage@redhat.com>
Fri, 2 Jun 2017 16:59:43 +0000 (12:59 -0400)
Right now they pretty much just copy the PGMapStatService, but it'll
let us slim down the MgrMonitor's one more easily.

Signed-off-by: Greg Farnum <gfarnum@redhat.com>
src/mon/MgrMonitor.cc
src/mon/MgrMonitor.h
src/mon/PGMonitor.cc
src/mon/PGMonitor.h
src/mon/PGStatService.h

index db748af167fb7352c33ff8ed049f1e487d79b76f..ab8a533c580fdb40bef401f64c74326543883e72 100644 (file)
@@ -34,6 +34,102 @@ static ostream& _prefix(std::ostream *_dout, Monitor *mon,
                << ").mgr e" << mgrmap.get_epoch() << " ";
 }
 
+
+class MgrPGStatService : public PGMap, public PGStatService {
+  PGMap& parent;
+public:
+  MgrPGStatService() : PGMap(), PGStatService(),
+                   parent(*static_cast<PGMap*>(this)) {}
+  MgrPGStatService(const PGMap& o) : PGMap(o), PGStatService(),
+                                 parent(*static_cast<PGMap*>(this)) {}
+  void reset(const PGMap& o) {
+    parent = o;
+  }
+
+  const pool_stat_t* get_pool_stat(int poolid) const {
+    auto i = parent.pg_pool_sum.find(poolid);
+    if (i != parent.pg_pool_sum.end()) {
+      return &i->second;
+    }
+    return NULL;
+  }
+
+  const pool_stat_t& get_pg_sum() const { return parent.pg_sum; }
+  const osd_stat_t& get_osd_sum() const { return parent.osd_sum; }
+
+  const osd_stat_t *get_osd_stat(int osd) const {
+    auto i = parent.osd_stat.find(osd);
+    if (i == parent.osd_stat.end()) {
+      return NULL;
+    }
+    return &i->second;
+  }
+  const ceph::unordered_map<int32_t,osd_stat_t> *get_osd_stat() const {
+    return &parent.osd_stat;
+  }
+  const ceph::unordered_map<pg_t,pg_stat_t> *get_pg_stat() const {
+    return &parent.pg_stat;
+  }
+  float get_full_ratio() const { return parent.full_ratio; }
+  float get_nearfull_ratio() const { return parent.nearfull_ratio; }
+
+  bool have_creating_pgs() const { return !parent.creating_pgs.empty(); }
+  bool is_creating_pg(pg_t pgid) const { return parent.creating_pgs.count(pgid); }
+  virtual void maybe_add_creating_pgs(epoch_t scan_epoch,
+                                     creating_pgs_t *pending_creates) const {
+    if (parent.last_pg_scan >= scan_epoch) {
+      for (auto& pgid : parent.creating_pgs) {
+      auto st = parent.pg_stat.find(pgid);
+      assert(st != parent.pg_stat.end());
+      auto created = make_pair(st->second.created, st->second.last_scrub_stamp);
+      // no need to add the pg, if it already exists in creating_pgs
+      pending_creates->pgs.emplace(pgid, created);
+      }
+    }
+  }
+  epoch_t get_min_last_epoch_clean() const { return parent.get_min_last_epoch_clean(); }
+
+  bool have_full_osds() const { return !parent.full_osds.empty(); }
+  bool have_nearfull_osds() const { return !parent.nearfull_osds.empty(); }
+
+  size_t get_num_pg_by_osd(int osd) const { return parent.get_num_pg_by_osd(osd); }
+
+  void print_summary(Formatter *f, ostream *out) const { parent.print_summary(f, out); }
+  void dump_fs_stats(stringstream *ss, Formatter *f, bool verbose) const {
+    parent.dump_fs_stats(ss, f, verbose);
+  }
+  void dump_pool_stats(const OSDMap& osdm, stringstream *ss, Formatter *f,
+                      bool verbose) const {
+    parent.dump_pool_stats(osdm, ss, f, verbose);
+  }
+
+  int process_pg_command(const string& prefix,
+                        const map<string,cmd_vartype>& cmdmap,
+                        const OSDMap& osdmap,
+                        Formatter *f,
+                        stringstream *ss,
+                        bufferlist *odata) {
+    return process_pg_map_command(prefix, cmdmap, parent, osdmap, f, ss, odata);
+  }
+
+  int reweight_by_utilization(const OSDMap &osd_map,
+                             int oload,
+                             double max_changef,
+                             int max_osds,
+                             bool by_pg, const set<int64_t> *pools,
+                             bool no_increasing,
+                             mempool::osdmap::map<int32_t, uint32_t>* new_weights,
+                             std::stringstream *ss,
+                             std::string *out_str,
+                             Formatter *f) {
+    return reweight::by_utilization(osd_map, parent, oload, max_changef,
+                                   max_osds, by_pg, pools, no_increasing,
+                                   new_weights, ss, out_str, f);
+  }
+
+};
+
+
 void MgrMonitor::create_initial()
 {
 }
@@ -626,15 +722,15 @@ void MgrMonitor::on_shutdown()
   cancel_timer();
 }
 
+MgrMonitor::~MgrMonitor()
+{
+  delete pgservice;
+}
+
 PGStatService *MgrMonitor::get_pg_stat_service()
 {
   if (!pgservice) {
-    pgservice = new PGMapStatService();
+    pgservice = new MgrPGStatService();
   }
   return pgservice;
 }
-
-MgrMonitor::~MgrMonitor()
-{
-  delete pgservice;
-}
index 45ef04b7435e2719e0bebb492ba0db9d0357d886..f53f5b08f6a525c0621a4fbeed9bc62f970a86b0 100644 (file)
@@ -19,6 +19,7 @@
 #include "PaxosService.h"
 
 class PGStatService;
+class MgrPGStatService;
 
 class MgrMonitor: public PaxosService
 {
@@ -27,7 +28,7 @@ class MgrMonitor: public PaxosService
 
   utime_t first_seen_inactive;
 
-  PGStatService *pgservice = nullptr;
+  MgrPGStatService *pgservice = nullptr;
 
   std::map<uint64_t, ceph::coarse_mono_clock::time_point> last_beacon;
 
@@ -49,8 +50,7 @@ class MgrMonitor: public PaxosService
 public:
   MgrMonitor(Monitor *mn, Paxos *p, const string& service_name)
     : PaxosService(mn, p, service_name)
-    : PaxosService(mn, p, service_name),
-      digest_event(nullptr)
+    : PaxosService(mn, p, service_name)
   {}
   ~MgrMonitor() override;
 
index b5443c2293b461093c3868798682a3649ac571e7..f9ae1d9fbe1fe121f35c10143dc8651ec4636617 100644 (file)
@@ -1671,11 +1671,109 @@ bool PGMonitor::check_sub(Subscription *sub)
   }
   return true;
 }
+class PGMapStatService : public PGMap, public PGStatService {
+  PGMap& parent;
+  PGMonitor *pgmon;
+public:
+  PGMapStatService() : PGMap(), PGStatService(),
+                      parent(*static_cast<PGMap*>(this)), pgmon(nullptr) {}
+  PGMapStatService(const PGMap& o,
+                  PGMonitor *pgm) : PGMap(o), PGStatService(),
+                                    parent(*static_cast<PGMap*>(this)),
+                                    pgmon(pgm) {}
+  void reset(const PGMap& o) {
+    parent = o;
+  }
+
+  bool is_readable() const { return pgmon->is_readable(); }
+
+  const pool_stat_t* get_pool_stat(int poolid) const {
+    auto i = parent.pg_pool_sum.find(poolid);
+    if (i != parent.pg_pool_sum.end()) {
+      return &i->second;
+    }
+    return NULL;
+  }
+
+  const pool_stat_t& get_pg_sum() const { return parent.pg_sum; }
+  const osd_stat_t& get_osd_sum() const { return parent.osd_sum; }
+
+  const osd_stat_t *get_osd_stat(int osd) const {
+    auto i = parent.osd_stat.find(osd);
+    if (i == parent.osd_stat.end()) {
+      return NULL;
+    }
+    return &i->second;
+  }
+  const ceph::unordered_map<int32_t,osd_stat_t> *get_osd_stat() const {
+    return &parent.osd_stat;
+  }
+  const ceph::unordered_map<pg_t,pg_stat_t> *get_pg_stat() const {
+    return &parent.pg_stat;
+  }
+  float get_full_ratio() const { return parent.full_ratio; }
+  float get_nearfull_ratio() const { return parent.nearfull_ratio; }
+
+  bool have_creating_pgs() const { return !parent.creating_pgs.empty(); }
+  bool is_creating_pg(pg_t pgid) const { return parent.creating_pgs.count(pgid); }
+  virtual void maybe_add_creating_pgs(epoch_t scan_epoch,
+                                     creating_pgs_t *pending_creates) const {
+    if (parent.last_pg_scan >= scan_epoch) {
+      for (auto& pgid : parent.creating_pgs) {
+      auto st = parent.pg_stat.find(pgid);
+      assert(st != parent.pg_stat.end());
+      auto created = make_pair(st->second.created, st->second.last_scrub_stamp);
+      // no need to add the pg, if it already exists in creating_pgs
+      pending_creates->pgs.emplace(pgid, created);
+      }
+    }
+  }
+  epoch_t get_min_last_epoch_clean() const { return parent.get_min_last_epoch_clean(); }
+
+  bool have_full_osds() const { return !parent.full_osds.empty(); }
+  bool have_nearfull_osds() const { return !parent.nearfull_osds.empty(); }
+
+  size_t get_num_pg_by_osd(int osd) const { return parent.get_num_pg_by_osd(osd); }
+
+  void print_summary(Formatter *f, ostream *out) const { parent.print_summary(f, out); }
+  void dump_fs_stats(stringstream *ss, Formatter *f, bool verbose) const {
+    parent.dump_fs_stats(ss, f, verbose);
+  }
+  void dump_pool_stats(const OSDMap& osdm, stringstream *ss, Formatter *f,
+                      bool verbose) const {
+    parent.dump_pool_stats(osdm, ss, f, verbose);
+  }
+
+  int process_pg_command(const string& prefix,
+                        const map<string,cmd_vartype>& cmdmap,
+                        const OSDMap& osdmap,
+                        Formatter *f,
+                        stringstream *ss,
+                        bufferlist *odata) {
+    return process_pg_map_command(prefix, cmdmap, parent, osdmap, f, ss, odata);
+  }
+
+  int reweight_by_utilization(const OSDMap &osd_map,
+                             int oload,
+                             double max_changef,
+                             int max_osds,
+                             bool by_pg, const set<int64_t> *pools,
+                             bool no_increasing,
+                             mempool::osdmap::map<int32_t, uint32_t>* new_weights,
+                             std::stringstream *ss,
+                             std::string *out_str,
+                             Formatter *f) {
+    return reweight::by_utilization(osd_map, parent, oload, max_changef,
+                                   max_osds, by_pg, pools, no_increasing,
+                                   new_weights, ss, out_str, f);
+  }
+
+};
 
 PGStatService *PGMonitor::get_pg_stat_service()
 {
   if (!pgservice) {
-    pgservice = new PGMapStatService(pg_map);
+    pgservice = new PGMapStatService(pg_map, this);
   }
   return pgservice;
 }
index 021e91ab81352e39d75dd58088ea397e4eed6564..f2bf342d20aeb1138930e631b23875fdd26c7564 100644 (file)
@@ -39,11 +39,12 @@ class MGetPoolStats;
 class TextTable;
 class MPGStats;
 class PGStatService;
+class PGMapStatService;
 
 class PGMonitor : public PaxosService {
 public:
   PGMap pg_map;
-  PGStatService *pgservice;
+  PGMapStatService *pgservice;
 
 private:
   PGMap::Incremental pending_inc;
index a2914ae6a97d5a68486a68d65d0fb0f754bf7a7a..a23614bfac9e51d823d4770ba96176a6c87e7dd7 100644 (file)
@@ -33,8 +33,11 @@ class PGStatService {
 public:
   PGStatService() {}
   virtual ~PGStatService() {}
-  virtual void reset(const PGMap& o) = 0;
-  virtual bool is_readable() const = 0;
+  // FIXME: Kill this once we rip out PGMonitor post-luminous
+  /** returns true if the underlying data is readable. Always true
+   *  post-luminous, but not when we are redirecting to the PGMonitor
+   */
+  virtual bool is_readable() const { return true; }
   virtual const pool_stat_t* get_pool_stat(int poolid) const = 0;
   virtual const pool_stat_t& get_pg_sum() const = 0;
   virtual const osd_stat_t& get_osd_sum() const = 0;
@@ -82,105 +85,4 @@ public:
                              Formatter *f) = 0;
 };
 
-class PGMapStatService : public PGMap, public PGStatService {
-  PGMap& parent;
-public:
-  PGMapStatService() : PGMap(), PGStatService(),
-                   parent(*static_cast<PGMap*>(this)) {}
-  PGMapStatService(const PGMap& o) : PGMap(o), PGStatService(),
-                                 parent(*static_cast<PGMap*>(this)) {}
-  void reset(const PGMap& o) {
-    parent = o;
-  }
-
-  // FIXME: Kill this once we rip out PGMonitor post-luminous
-  /** returns true if the underlying data is readable. Always true
-   * post-luminous, but not when we are redirecting to the PGMonitor
-   */
-  bool is_readable() const { return true; }
-
-  const pool_stat_t* get_pool_stat(int poolid) const {
-    auto i = parent.pg_pool_sum.find(poolid);
-    if (i != parent.pg_pool_sum.end()) {
-      return &i->second;
-    }
-    return NULL;
-  }
-
-  const pool_stat_t& get_pg_sum() const { return parent.pg_sum; }
-  const osd_stat_t& get_osd_sum() const { return parent.osd_sum; }
-
-  const osd_stat_t *get_osd_stat(int osd) const {
-    auto i = parent.osd_stat.find(osd);
-    if (i == parent.osd_stat.end()) {
-      return NULL;
-    }
-    return &i->second;
-  }
-  const ceph::unordered_map<int32_t,osd_stat_t> *get_osd_stat() const {
-    return &parent.osd_stat;
-  }
-  const ceph::unordered_map<pg_t,pg_stat_t> *get_pg_stat() const {
-    return &parent.pg_stat;
-  }
-  float get_full_ratio() const { return parent.full_ratio; }
-  float get_nearfull_ratio() const { return parent.nearfull_ratio; }
-
-  bool have_creating_pgs() const { return !parent.creating_pgs.empty(); }
-  bool is_creating_pg(pg_t pgid) const { return parent.creating_pgs.count(pgid); }
-  virtual void maybe_add_creating_pgs(epoch_t scan_epoch,
-                                     creating_pgs_t *pending_creates) const {
-    if (parent.last_pg_scan >= scan_epoch) {
-      for (auto& pgid : parent.creating_pgs) {
-       auto st = parent.pg_stat.find(pgid);
-       assert(st != parent.pg_stat.end());
-       auto created = make_pair(st->second.created, st->second.last_scrub_stamp);
-       // no need to add the pg, if it already exists in creating_pgs
-       pending_creatings->pgs.emplace(pgid, created);
-      }
-    }
-  }
-  epoch_t get_min_last_epoch_clean() const { return parent.get_min_last_epoch_clean(); }
-
-  bool have_full_osds() const { return !parent.full_osds.empty(); }
-  bool have_nearfull_osds() const { return !parent.nearfull_osds.empty(); }
-
-  size_t get_num_pg_by_osd(int osd) const { return parent.get_num_pg_by_osd(osd); }
-
-  void print_summary(Formatter *f, ostream *out) const { parent.print_summary(f, out); }
-  void dump_fs_stats(stringstream *ss, Formatter *f, bool verbose) const {
-    parent.dump_fs_stats(ss, f, verbose);
-  }
-  void dump_pool_stats(const OSDMap& osdm, stringstream *ss, Formatter *f,
-                      bool verbose) const {
-    parent.dump_pool_stats(osdm, ss, f, verbose);
-  }
-
-  int process_pg_command(const string& prefix,
-                        const map<string,cmd_vartype>& cmdmap,
-                        const OSDMap& osdmap,
-                        Formatter *f,
-                        stringstream *ss,
-                        bufferlist *odata) {
-    return process_pg_map_command(prefix, cmdmap, parent, osdmap, f, ss, odata);
-  }
-
-  int reweight_by_utilization(const OSDMap &osd_map,
-                             int oload,
-                             double max_changef,
-                             int max_osds,
-                             bool by_pg, const set<int64_t> *pools,
-                             bool no_increasing,
-                             mempool::osdmap::map<int32_t, uint32_t>* new_weights,
-                             std::stringstream *ss,
-                             std::string *out_str,
-                             Formatter *f) {
-    return reweight::by_utilization(osd_map, parent, oload, max_changef,
-                                   max_osds, by_pg, pools, no_increasing,
-                                   new_weights, ss, out_str, f);
-  }
-
-};
-
-
 #endif