]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/osd_types: print and encode empty PastIntervals
authorSage Weil <sage@redhat.com>
Tue, 11 Apr 2017 21:27:18 +0000 (17:27 -0400)
committerSage Weil <sage@redhat.com>
Fri, 28 Apr 2017 15:30:39 +0000 (11:30 -0400)
These happen when they are optionally sent across the
wire.

Signed-off-by: Sage Weil <sage@redhat.com>
src/osd/osd_types.cc
src/osd/osd_types.h

index 30009576834260629668e24f5506b3647d11fad4..d3d48965cc8002f6c9b5225fa3f6cda25faadf52 100644 (file)
@@ -3219,8 +3219,11 @@ PastIntervals &PastIntervals::operator=(const PastIntervals &rhs)
 
 ostream& operator<<(ostream& out, const PastIntervals &i)
 {
-  assert(i.past_intervals);
-  return i.past_intervals->print(out);
+  if (i.past_intervals) {
+    return i.past_intervals->print(out);
+  } else {
+    return out << "(empty)";
+  }
 }
 
 ostream& operator<<(ostream& out, const PastIntervals::PriorSet &i)
@@ -3237,14 +3240,20 @@ ostream& operator<<(ostream& out, const PastIntervals::PriorSet &i)
 void PastIntervals::decode(bufferlist::iterator &bl)
 {
   DECODE_START(1, bl);
-  __u8 classic = 0;
-  ::decode(classic, bl);
-  if (classic) {
+  __u8 type = 0;
+  ::decode(type, bl);
+  switch (type) {
+  case 0:
+    break;
+  case 1:
     past_intervals.reset(new pi_simple_rep);
-  } else {
+    past_intervals->decode(bl);
+    break;
+  case 2:
     past_intervals.reset(new pi_compact_rep);
+    past_intervals->decode(bl);
+    break;
   }
-  past_intervals->decode(bl);
   DECODE_FINISH(bl);
 }
 
index c95e24cbd391629c79c6ca3b63d39a8070e0c94a..c860f8cfe8cc9135d3bb14bc04e63e294b206746 100644 (file)
@@ -2572,17 +2572,24 @@ public:
   }
 
   void encode(bufferlist &bl) const {
-    assert(past_intervals);
     ENCODE_START(1, 1, bl);
-    __u8 classic = is_classic();
-    ::encode(classic, bl);
-    past_intervals->encode(bl);
+    if (past_intervals) {
+      __u8 type = is_classic() ? 1 : 2;
+      ::encode(type, bl);
+      past_intervals->encode(bl);
+    } else {
+      ::encode((__u8)0, bl);
+    }
     ENCODE_FINISH(bl);
   }
   void encode_classic(bufferlist &bl) const {
-    assert(past_intervals);
-    assert(past_intervals->is_classic());
-    past_intervals->encode(bl);
+    if (past_intervals) {
+      assert(past_intervals->is_classic());
+      past_intervals->encode(bl);
+    } else {
+      // it's a map<>
+      ::encode((uint32_t)0, bl);
+    }
   }
 
   void decode(bufferlist::iterator &bl);