]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-dencoder: PGMap[::Incremental]
authorSage Weil <sage@newdream.net>
Mon, 6 Feb 2012 23:10:21 +0000 (15:10 -0800)
committerSage Weil <sage@newdream.net>
Wed, 8 Feb 2012 21:12:18 +0000 (13:12 -0800)
Signed-off-by: Sage Weil <sage@newdream.net>
src/Makefile.am
src/mon/PGMap.cc
src/mon/PGMap.h
src/test/encoding/types.h

index b6ec3a54c654de870653cec86f0e7883b1bb8562..b72e06a7a24557f10564231972f06dc8fb81a440 100644 (file)
@@ -109,7 +109,7 @@ osdmaptool_LDADD = $(LIBGLOBAL_LDA)
 bin_PROGRAMS += monmaptool crushtool osdmaptool
 
 ceph_dencoder_SOURCES = test/encoding/ceph_dencoder.cc
-ceph_dencoder_LDADD = $(LIBGLOBAL_LDA) libosd.la libmds.a libos.la
+ceph_dencoder_LDADD = $(LIBGLOBAL_LDA) libosd.la libmds.a libos.la libmon.la
 bin_PROGRAMS += ceph-dencoder
 
 mount_ceph_SOURCES = mount/mount.ceph.c common/armor.c common/safe_io.c common/secret.c include/addr_parsing.c
index 1acc0e43fd2ed83992e455d24cc3fa6188693a1d..552c331314302877908730776b82e3cb15329024 100644 (file)
@@ -4,6 +4,118 @@
 #define DOUT_SUBSYS mon
 #include "common/debug.h"
 
+#include "common/Formatter.h"
+
+// --
+
+void PGMap::Incremental::encode(bufferlist &bl) const
+{
+  __u8 v = 3;
+  ::encode(v, bl);
+  ::encode(version, bl);
+  ::encode(pg_stat_updates, bl);
+  ::encode(osd_stat_updates, bl);
+  ::encode(osd_stat_rm, bl);
+  ::encode(osdmap_epoch, bl);
+  ::encode(pg_scan, bl);
+  ::encode(full_ratio, bl);
+  ::encode(nearfull_ratio, bl);
+  ::encode(pg_remove, bl);
+}
+
+void PGMap::Incremental::decode(bufferlist::iterator &bl)
+{
+  __u8 v;
+  ::decode(v, bl);
+  ::decode(version, bl);
+  if (v < 3) {
+    pg_stat_updates.clear();
+    __u32 n;
+    ::decode(n, bl);
+    while (n--) {
+      old_pg_t opgid;
+      ::decode(opgid, bl);
+      pg_t pgid = opgid;
+      ::decode(pg_stat_updates[pgid], bl);
+    }
+      } else {
+    ::decode(pg_stat_updates, bl);
+  }
+  ::decode(osd_stat_updates, bl);
+  ::decode(osd_stat_rm, bl);
+  ::decode(osdmap_epoch, bl);
+  ::decode(pg_scan, bl);
+  if (v >= 2) {
+    ::decode(full_ratio, bl);
+    ::decode(nearfull_ratio, bl);
+  }
+  if (v < 3) {
+    pg_remove.clear();
+    __u32 n;
+    ::decode(n, bl);
+    while (n--) {
+      old_pg_t opgid;
+      ::decode(opgid, bl);
+      pg_remove.insert(pg_t(opgid));
+    }
+  } else {
+    ::decode(pg_remove, bl);
+  }
+}
+
+void PGMap::Incremental::dump(Formatter *f) const
+{
+  f->dump_unsigned("version", version);
+  f->dump_unsigned("osdmap_epoch", osdmap_epoch);
+  f->dump_unsigned("pg_scan_epoch", pg_scan);
+  f->dump_float("full_ratio", full_ratio);
+  f->dump_float("nearfull_ratio", nearfull_ratio);
+
+  f->open_array_section("pg_stat_updates");
+  for (map<pg_t,pg_stat_t>::const_iterator p = pg_stat_updates.begin(); p != pg_stat_updates.end(); ++p) {
+    f->open_object_section("pg_stat");
+    f->dump_stream("pgid") << p->first;
+    p->second.dump(f);
+    f->close_section();
+  }
+  f->close_section();
+
+  f->open_array_section("osd_stat_updates");
+  for (map<int,osd_stat_t>::const_iterator p = osd_stat_updates.begin(); p != osd_stat_updates.end(); ++p) {
+    f->open_object_section("osd_stat");
+    f->dump_int("osd", p->first);
+    p->second.dump(f);
+    f->close_section();
+  }
+  f->close_section();
+
+  f->open_array_section("osd_stat_removals");
+  for (set<int>::const_iterator p = osd_stat_rm.begin(); p != osd_stat_rm.end(); ++p)
+    f->dump_int("osd", *p);
+  f->close_section();
+
+  f->open_array_section("pg_removals");
+  for (set<pg_t>::const_iterator p = pg_remove.begin(); p != pg_remove.end(); ++p)
+    f->dump_stream("pgid") << *p;
+  f->close_section();
+}
+
+void PGMap::Incremental::generate_test_instances(list<PGMap::Incremental*>& o)
+{
+  o.push_back(new Incremental);
+  o.push_back(new Incremental);
+  o.back()->version = 12;
+  o.back()->osdmap_epoch = 1;
+  o.back()->pg_scan = 2;
+  o.back()->full_ratio = .2;
+  o.back()->nearfull_ratio = .3;
+  o.back()->pg_stat_updates[pg_t(1,2,3)] = pg_stat_t();
+  o.back()->osd_stat_updates[5] = osd_stat_t();  
+}
+
+
+// --
+
 void PGMap::apply_incremental(const Incremental& inc)
 {
   assert(inc.version == version+1);
@@ -167,7 +279,7 @@ epoch_t PGMap::calc_min_last_epoch_clean() const
   return min;
 }
 
-void PGMap::encode(bufferlist &bl)
+void PGMap::encode(bufferlist &bl) const
 {
   __u8 v = 3;
   ::encode(v, bl);
@@ -406,3 +518,15 @@ void PGMap::print_summary(ostream& out) const
     out << "; " << ssr.str();
 }
 
+void PGMap::generate_test_instances(list<PGMap*>& o)
+{
+  o.push_back(new PGMap);
+  o.push_back(new PGMap);
+  o.back()->version = 888;
+  o.back()->last_osdmap_epoch = 12;
+  o.back()->last_pg_scan = 34;
+  o.back()->full_osds.insert(3);
+  o.back()->nearfull_osds.insert(4);
+  o.back()->pg_stat[pg_t(1,2,3)] = pg_stat_t();  
+  o.back()->osd_stat[5] = osd_stat_t();  
+}
index 2a09373faee81ce8f5a2d4373a3bbf1f3eedb6b3..92ac8765239c32203798c76c7f28f6178e0c933a 100644 (file)
@@ -26,6 +26,8 @@
 #include "common/config.h"
 #include <sstream>
 
+namespace ceph { class Formatter; }
+
 class PGMap {
 public:
   // the map
@@ -49,57 +51,10 @@ public:
     float full_ratio;
     float nearfull_ratio;
 
-    void encode(bufferlist &bl) const {
-      __u8 v = 3;
-      ::encode(v, bl);
-      ::encode(version, bl);
-      ::encode(pg_stat_updates, bl);
-      ::encode(osd_stat_updates, bl);
-      ::encode(osd_stat_rm, bl);
-      ::encode(osdmap_epoch, bl);
-      ::encode(pg_scan, bl);
-      ::encode(full_ratio, bl);
-      ::encode(nearfull_ratio, bl);
-      ::encode(pg_remove, bl);
-    }
-    void decode(bufferlist::iterator &bl) {
-      __u8 v;
-      ::decode(v, bl);
-      ::decode(version, bl);
-      if (v < 3) {
-       pg_stat_updates.clear();
-       __u32 n;
-       ::decode(n, bl);
-       while (n--) {
-         old_pg_t opgid;
-         ::decode(opgid, bl);
-         pg_t pgid = opgid;
-         ::decode(pg_stat_updates[pgid], bl);
-       }
-      } else {
-       ::decode(pg_stat_updates, bl);
-      }
-      ::decode(osd_stat_updates, bl);
-      ::decode(osd_stat_rm, bl);
-      ::decode(osdmap_epoch, bl);
-      ::decode(pg_scan, bl);
-      if (v >= 2) {
-        ::decode(full_ratio, bl);
-        ::decode(nearfull_ratio, bl);
-      }
-      if (v < 3) {
-       pg_remove.clear();
-       __u32 n;
-       ::decode(n, bl);
-       while (n--) {
-         old_pg_t opgid;
-         ::decode(opgid, bl);
-         pg_remove.insert(pg_t(opgid));
-       }
-      } else {
-       ::decode(pg_remove, bl);
-      }
-    }
+    void encode(bufferlist &bl) const;
+    void decode(bufferlist::iterator &bl);
+    void dump(Formatter *f) const;
+    static void generate_test_instances(list<Incremental*>& o);
 
     Incremental() : version(0), osdmap_epoch(0), pg_scan(0),
         full_ratio(0), nearfull_ratio(0) {}
@@ -133,7 +88,7 @@ public:
   void stat_osd_add(const osd_stat_t &s);
   void stat_osd_sub(const osd_stat_t &s);
   
-  void encode(bufferlist &bl);
+  void encode(bufferlist &bl) const;
   void decode(bufferlist::iterator &bl);
 
   void dump(Formatter *f) const; 
@@ -148,7 +103,11 @@ public:
   void print_summary(ostream& out) const;
 
   epoch_t calc_min_last_epoch_clean() const;
+
+  static void generate_test_instances(list<PGMap*>& o);
 };
+WRITE_CLASS_ENCODER(PGMap::Incremental)
+WRITE_CLASS_ENCODER(PGMap)
 
 inline ostream& operator<<(ostream& out, const PGMap& m) {
   m.print_summary(out);
index 2c064b7836527aa87ae5ffd1a818dd45e2e36494..3049a4f73939ebe544d043244314e1f7e687fb48 100644 (file)
@@ -48,6 +48,9 @@ TYPE(ScrubMap)
 #include "os/ObjectStore.h"
 TYPE(ObjectStore::Transaction)
 
+#include "mon/PGMap.h"
+TYPE(PGMap::Incremental)
+TYPE(PGMap)
 
 // --- messages ---
 #include "messages/MAuth.h"