]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
MDS: EMetaBlob::dirlump more modernization for encoder
authorGreg Farnum <greg@inktank.com>
Fri, 1 Feb 2013 23:51:59 +0000 (15:51 -0800)
committerGreg Farnum <greg@inktank.com>
Fri, 8 Feb 2013 21:17:52 +0000 (13:17 -0800)
Signed-off-by: Greg Farnum <greg@inktank.com>
src/mds/events/EMetaBlob.h
src/mds/journal.cc
src/test/encoding/types.h

index 8549d22be64f2014a62a6cc0a2ac880bf90bc651..3cf77d091eba037b9414cdd8d506c3ebc03102cb 100644 (file)
@@ -226,11 +226,11 @@ public:
   public:
     dirlump() : state(0), nfull(0), nremote(0), nnull(0), dn_decoded(true) { }
     
-    bool is_complete() { return state & STATE_COMPLETE; }
+    bool is_complete() const { return state & STATE_COMPLETE; }
     void mark_complete() { state |= STATE_COMPLETE; }
-    bool is_dirty() { return state & STATE_DIRTY; }
+    bool is_dirty() const { return state & STATE_DIRTY; }
     void mark_dirty() { state |= STATE_DIRTY; }
-    bool is_new() { return state & STATE_NEW; }
+    bool is_new() const { return state & STATE_NEW; }
     void mark_new() { state |= STATE_NEW; }
     bool is_importing() { return state & STATE_IMPORTING; }
     void mark_importing() { state |= STATE_IMPORTING; }
@@ -253,8 +253,26 @@ public:
        p->print(out);
     }
 
+    string state_string() const {
+      string state_string;
+      bool marked_already = false;
+      if (is_complete()) {
+       state_string.append("complete");
+       marked_already = true;
+      }
+      if (is_dirty()) {
+       state_string.append(marked_already ? "+dirty" : "dirty");
+       marked_already = true;
+      }
+      if (is_new()) {
+       state_string.append(marked_already ? "+new" : "new");
+      }
+      return state_string;
+    }
+
     // if this changes, update the versioning in encode for it!
     void _encode_bits() const {
+      if (!dn_decoded) return;
       ::encode(dfull, dnbl);
       ::encode(dremote, dnbl);
       ::encode(dnull, dnbl);
@@ -268,28 +286,10 @@ public:
       dn_decoded = true;
     }
 
-    void encode(bufferlist& bl) const {
-      ENCODE_START(2, 2, bl);
-      ::encode(fnode, bl);
-      ::encode(state, bl);
-      ::encode(nfull, bl);
-      ::encode(nremote, bl);
-      ::encode(nnull, bl);
-      _encode_bits();
-      ::encode(dnbl, bl);
-      ENCODE_FINISH(bl);
-    }
-    void decode(bufferlist::iterator &bl) {
-      DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl)
-      ::decode(fnode, bl);
-      ::decode(state, bl);
-      ::decode(nfull, bl);
-      ::decode(nremote, bl);
-      ::decode(nnull, bl);
-      ::decode(dnbl, bl);
-      dn_decoded = false;      // don't decode bits unless we need them.
-      DECODE_FINISH(bl);
-    }
+    void encode(bufferlist& bl) const;
+    void decode(bufferlist::iterator &bl);
+    void dump(Formatter *f) const;
+    static void generate_test_instances(list<dirlump*>& ls);
   };
   WRITE_CLASS_ENCODER(dirlump)
 
index 6915ea7187114898a4d945d32323cda6752b55d8..7d049c2055a33b6761490444e05205cedd5a2c0a 100644 (file)
@@ -644,8 +644,81 @@ void EMetaBlob::nullbit::generate_test_instances(list<nullbit*>& ls)
   ls.push_back(sample2);
 }
 
+// EMetaBlob::dirlump
+
+void EMetaBlob::dirlump::encode(bufferlist& bl) const
+{
+  ENCODE_START(2, 2, bl);
+  ::encode(fnode, bl);
+  ::encode(state, bl);
+  ::encode(nfull, bl);
+  ::encode(nremote, bl);
+  ::encode(nnull, bl);
+  _encode_bits();
+  ::encode(dnbl, bl);
+  ENCODE_FINISH(bl);
+}
+
+void EMetaBlob::dirlump::decode(bufferlist::iterator &bl)
+{
+  DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl)
+  ::decode(fnode, bl);
+  ::decode(state, bl);
+  ::decode(nfull, bl);
+  ::decode(nremote, bl);
+  ::decode(nnull, bl);
+  ::decode(dnbl, bl);
+  dn_decoded = false;      // don't decode bits unless we need them.
+  DECODE_FINISH(bl);
+}
+
+void EMetaBlob::dirlump::dump(Formatter *f) const
+{
+  if (!dn_decoded) {
+    dirlump *me = const_cast<dirlump*>(this);
+    me->_decode_bits();
+  }
+  f->open_object_section("fnode");
+  fnode.dump(f);
+  f->close_section(); // fnode
+  f->dump_string("state", state_string());
+  f->dump_int("nfull", nfull);
+  f->dump_int("nremote", nremote);
+  f->dump_int("nnull", nnull);
+
+  f->open_array_section("full bits");
+  for (list<std::tr1::shared_ptr<fullbit> >::const_iterator
+      iter = dfull.begin(); iter != dfull.end(); ++iter) {
+    f->open_object_section("fullbit");
+    (*iter)->dump(f);
+    f->close_section(); // fullbit
+  }
+  f->close_section(); // full bits
+  f->open_array_section("remote bits");
+  for (list<remotebit>::const_iterator
+      iter = dremote.begin(); iter != dremote.end(); ++iter) {
+    f->open_object_section("remotebit");
+    (*iter).dump(f);
+    f->close_section(); // remotebit
+  }
+  f->close_section(); // remote bits
+  f->open_array_section("null bits");
+  for (list<nullbit>::const_iterator
+      iter = dnull.begin(); iter != dnull.end(); ++iter) {
+    f->open_object_section("null bit");
+    (*iter).dump(f);
+    f->close_section(); // null bit
+  }
+  f->close_section(); // null bits
+}
+
+void EMetaBlob::dirlump::generate_test_instances(list<dirlump*>& ls)
+{
+  ls.push_back(new dirlump());
+}
+
 /**
- *
+ * EMetaBlob proper
  */
 
 void EMetaBlob::replay(MDS *mds, LogSegment *logseg, MDSlaveUpdate *slaveup)
index b4d36c45aea811c74e991e390e916b8458b91041..2b47296b248f508d703e3a78848a6f0c1a6d1d1e 100644 (file)
@@ -137,7 +137,7 @@ TYPE(EImportStart)
 TYPE(EMetaBlob::fullbit)
 TYPE(EMetaBlob::remotebit)
 TYPE(EMetaBlob::nullbit)
-
+TYPE(EMetaBlob::dirlump)
 
 #ifdef WITH_RADOSGW