]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add json encoding of bucket layout types
authorCasey Bodley <cbodley@redhat.com>
Mon, 1 Feb 2021 19:39:39 +0000 (14:39 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Tue, 1 Feb 2022 15:28:30 +0000 (10:28 -0500)
adds a "layout" section to RGWBucketInfo

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_bucket_layout.cc
src/rgw/rgw_bucket_layout.h
src/rgw/rgw_json_enc.cc

index 22d75d0d30d3d914e4919c171726a737b902e786..499e8f0cd4374fc35a0a754ed1c960706aff0e1b 100644 (file)
  *
  */
 
+#include <boost/algorithm/string.hpp>
 #include "rgw_bucket_layout.h"
 
 namespace rgw {
 
+// BucketIndexType
+std::string_view to_string(const BucketIndexType& t)
+{
+  switch (t) {
+  case BucketIndexType::Normal: return "Normal";
+  case BucketIndexType::Indexless: return "Indexless";
+  default: return "Unknown";
+  }
+}
+bool parse(std::string_view str, BucketIndexType& t)
+{
+  if (boost::iequals(str, "Normal")) {
+    t = BucketIndexType::Normal;
+    return true;
+  }
+  if (boost::iequals(str, "Indexless")) {
+    t = BucketIndexType::Indexless;
+    return true;
+  }
+  return false;
+}
+void encode_json_impl(const char *name, const BucketIndexType& t, ceph::Formatter *f)
+{
+  encode_json(name, to_string(t), f);
+}
+void decode_json_obj(BucketIndexType& t, JSONObj *obj)
+{
+  std::string str;
+  decode_json_obj(str, obj);
+  parse(str, t);
+}
+
+// BucketHashType
+std::string_view to_string(const BucketHashType& t)
+{
+  switch (t) {
+  case BucketHashType::Mod: return "Mod";
+  default: return "Unknown";
+  }
+}
+bool parse(std::string_view str, BucketHashType& t)
+{
+  if (boost::iequals(str, "Mod")) {
+    t = BucketHashType::Mod;
+    return true;
+  }
+  return false;
+}
+void encode_json_impl(const char *name, const BucketHashType& t, ceph::Formatter *f)
+{
+  encode_json(name, to_string(t), f);
+}
+void decode_json_obj(BucketHashType& t, JSONObj *obj)
+{
+  std::string str;
+  decode_json_obj(str, obj);
+  parse(str, t);
+}
+
+// bucket_index_normal_layout
 void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(1, 1, bl);
@@ -31,7 +92,20 @@ void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl)
   decode(l.hash_type, bl);
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const bucket_index_normal_layout& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("num_shards", l.num_shards, f);
+  encode_json("hash_type", l.hash_type, f);
+  f->close_section();
+}
+void decode_json_obj(bucket_index_normal_layout& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("num_shards", l.num_shards, obj);
+  JSONDecoder::decode_json("hash_type", l.hash_type, obj);
+}
 
+// bucket_index_layout
 void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(1, 1, bl);
@@ -58,7 +132,20 @@ void decode(bucket_index_layout& l, bufferlist::const_iterator& bl)
   }
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const bucket_index_layout& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("type", l.type, f);
+  encode_json("normal", l.normal, f);
+  f->close_section();
+}
+void decode_json_obj(bucket_index_layout& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("type", l.type, obj);
+  JSONDecoder::decode_json("normal", l.normal, obj);
+}
 
+// bucket_index_layout_generation
 void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(1, 1, bl);
@@ -73,7 +160,47 @@ void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl)
   decode(l.layout, bl);
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const bucket_index_layout_generation& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("gen", l.gen, f);
+  encode_json("layout", l.layout, f);
+  f->close_section();
+}
+void decode_json_obj(bucket_index_layout_generation& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("gen", l.gen, obj);
+  JSONDecoder::decode_json("layout", l.layout, obj);
+}
+
+// BucketLogType
+std::string_view to_string(const BucketLogType& t)
+{
+  switch (t) {
+  case BucketLogType::InIndex: return "InIndex";
+  default: return "Unknown";
+  }
+}
+bool parse(std::string_view str, BucketLogType& t)
+{
+  if (boost::iequals(str, "InIndex")) {
+    t = BucketLogType::InIndex;
+    return true;
+  }
+  return false;
+}
+void encode_json_impl(const char *name, const BucketLogType& t, ceph::Formatter *f)
+{
+  encode_json(name, to_string(t), f);
+}
+void decode_json_obj(BucketLogType& t, JSONObj *obj)
+{
+  std::string str;
+  decode_json_obj(str, obj);
+  parse(str, t);
+}
 
+// bucket_index_log_layout
 void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(1, 1, bl);
@@ -88,7 +215,20 @@ void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl)
   decode(l.layout, bl);
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const bucket_index_log_layout& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("gen", l.gen, f);
+  encode_json("layout", l.layout, f);
+  f->close_section();
+}
+void decode_json_obj(bucket_index_log_layout& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("gen", l.gen, obj);
+  JSONDecoder::decode_json("layout", l.layout, obj);
+}
 
+// bucket_log_layout
 void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(1, 1, bl);
@@ -111,7 +251,22 @@ void decode(bucket_log_layout& l, bufferlist::const_iterator& bl)
   }
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const bucket_log_layout& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("type", l.type, f);
+  if (l.type == BucketLogType::InIndex) {
+    encode_json("in_index", l.in_index, f);
+  }
+  f->close_section();
+}
+void decode_json_obj(bucket_log_layout& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("type", l.type, obj);
+  JSONDecoder::decode_json("in_index", l.in_index, obj);
+}
 
+// bucket_log_layout_generation
 void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(1, 1, bl);
@@ -126,7 +281,53 @@ void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl)
   decode(l.layout, bl);
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const bucket_log_layout_generation& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("gen", l.gen, f);
+  encode_json("layout", l.layout, f);
+  f->close_section();
+}
+void decode_json_obj(bucket_log_layout_generation& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("gen", l.gen, obj);
+  JSONDecoder::decode_json("layout", l.layout, obj);
+}
 
+// BucketReshardState
+std::string_view to_string(const BucketReshardState& s)
+{
+  switch (s) {
+  case BucketReshardState::None: return "None";
+  case BucketReshardState::InProgress: return "InProgress";
+  default: return "Unknown";
+  }
+}
+bool parse(std::string_view str, BucketReshardState& s)
+{
+  if (boost::iequals(str, "None")) {
+    s = BucketReshardState::None;
+    return true;
+  }
+  if (boost::iequals(str, "InProgress")) {
+    s = BucketReshardState::InProgress;
+    return true;
+  }
+  return false;
+}
+void encode_json_impl(const char *name, const BucketReshardState& s, ceph::Formatter *f)
+{
+  encode_json(name, to_string(s), f);
+}
+void decode_json_obj(BucketReshardState& s, JSONObj *obj)
+{
+  std::string str;
+  decode_json_obj(str, obj);
+  parse(str, s);
+}
+
+
+// BucketLayout
 void encode(const BucketLayout& l, bufferlist& bl, uint64_t f)
 {
   ENCODE_START(2, 1, bl);
@@ -153,5 +354,27 @@ void decode(BucketLayout& l, bufferlist::const_iterator& bl)
   }
   DECODE_FINISH(bl);
 }
+void encode_json_impl(const char *name, const BucketLayout& l, ceph::Formatter *f)
+{
+  f->open_object_section(name);
+  encode_json("resharding", l.resharding, f);
+  encode_json("current_index", l.current_index, f);
+  if (l.target_index) {
+    encode_json("target_index", *l.target_index, f);
+  }
+  f->open_array_section("logs");
+  for (const auto& log : l.logs) {
+    encode_json("log", log, f);
+  }
+  f->close_section(); // logs[]
+  f->close_section();
+}
+void decode_json_obj(BucketLayout& l, JSONObj *obj)
+{
+  JSONDecoder::decode_json("resharding", l.resharding, obj);
+  JSONDecoder::decode_json("current_index", l.current_index, obj);
+  JSONDecoder::decode_json("target_index", l.target_index, obj);
+  JSONDecoder::decode_json("logs", l.logs, obj);
+}
 
 } // namespace rgw
index 09bbd1c142c05e3a1c7d4d60b8da5ca8312d5f55..6ca62e233a521585b4939e1e43b5a3f0580112ef 100644 (file)
@@ -18,6 +18,7 @@
 #include <optional>
 #include <string>
 #include "include/encoding.h"
+#include "common/ceph_json.h"
 
 namespace rgw {
 
@@ -26,21 +27,24 @@ enum class BucketIndexType : uint8_t {
   Indexless, // no bucket index, so listing is unsupported
 };
 
+std::string_view to_string(const BucketIndexType& t);
+bool parse(std::string_view str, BucketIndexType& t);
+void encode_json_impl(const char *name, const BucketIndexType& t, ceph::Formatter *f);
+void decode_json_obj(BucketIndexType& t, JSONObj *obj);
+
+inline std::ostream& operator<<(std::ostream& out, const BucketIndexType& t)
+{
+  return out << to_string(t);
+}
+
 enum class BucketHashType : uint8_t {
   Mod, // rjenkins hash of object name, modulo num_shards
 };
 
-inline std::ostream& operator<<(std::ostream& out, const BucketIndexType &index_type)
-{
-  switch (index_type) {
-    case BucketIndexType::Normal:
-      return out << "Normal";
-    case BucketIndexType::Indexless:
-      return out << "Indexless";
-    default:
-      return out << "Unknown";
-  }
-}
+std::string_view to_string(const BucketHashType& t);
+bool parse(std::string_view str, BucketHashType& t);
+void encode_json_impl(const char *name, const BucketHashType& t, ceph::Formatter *f);
+void decode_json_obj(BucketHashType& t, JSONObj *obj);
 
 struct bucket_index_normal_layout {
   uint32_t num_shards = 1;
@@ -50,7 +54,8 @@ struct bucket_index_normal_layout {
 
 void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f=0);
 void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl);
-
+void encode_json_impl(const char *name, const bucket_index_normal_layout& l, ceph::Formatter *f);
+void decode_json_obj(bucket_index_normal_layout& l, JSONObj *obj);
 
 struct bucket_index_layout {
   BucketIndexType type = BucketIndexType::Normal;
@@ -61,6 +66,8 @@ struct bucket_index_layout {
 
 void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f=0);
 void decode(bucket_index_layout& l, bufferlist::const_iterator& bl);
+void encode_json_impl(const char *name, const bucket_index_layout& l, ceph::Formatter *f);
+void decode_json_obj(bucket_index_layout& l, JSONObj *obj);
 
 
 struct bucket_index_layout_generation {
@@ -70,6 +77,8 @@ struct bucket_index_layout_generation {
 
 void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f=0);
 void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl);
+void encode_json_impl(const char *name, const bucket_index_layout_generation& l, ceph::Formatter *f);
+void decode_json_obj(bucket_index_layout_generation& l, JSONObj *obj);
 
 
 enum class BucketLogType : uint8_t {
@@ -77,6 +86,11 @@ enum class BucketLogType : uint8_t {
   InIndex,
 };
 
+std::string_view to_string(const BucketLogType& t);
+bool parse(std::string_view str, BucketLogType& t);
+void encode_json_impl(const char *name, const BucketLogType& t, ceph::Formatter *f);
+void decode_json_obj(BucketLogType& t, JSONObj *obj);
+
 inline std::ostream& operator<<(std::ostream& out, const BucketLogType &log_type)
 {
   switch (log_type) {
@@ -94,6 +108,8 @@ struct bucket_index_log_layout {
 
 void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f=0);
 void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl);
+void encode_json_impl(const char *name, const bucket_index_log_layout& l, ceph::Formatter *f);
+void decode_json_obj(bucket_index_log_layout& l, JSONObj *obj);
 
 struct bucket_log_layout {
   BucketLogType type = BucketLogType::InIndex;
@@ -103,6 +119,8 @@ struct bucket_log_layout {
 
 void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f=0);
 void decode(bucket_log_layout& l, bufferlist::const_iterator& bl);
+void encode_json_impl(const char *name, const bucket_log_layout& l, ceph::Formatter *f);
+void decode_json_obj(bucket_log_layout& l, JSONObj *obj);
 
 
 struct bucket_log_layout_generation {
@@ -112,6 +130,8 @@ struct bucket_log_layout_generation {
 
 void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f=0);
 void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl);
+void encode_json_impl(const char *name, const bucket_log_layout_generation& l, ceph::Formatter *f);
+void decode_json_obj(bucket_log_layout_generation& l, JSONObj *obj);
 
 // return a log layout that shares its layout with the index
 inline bucket_log_layout_generation log_layout_from_index(
@@ -138,6 +158,10 @@ enum class BucketReshardState : uint8_t {
   None,
   InProgress,
 };
+std::string_view to_string(const BucketReshardState& s);
+bool parse(std::string_view str, BucketReshardState& s);
+void encode_json_impl(const char *name, const BucketReshardState& s, ceph::Formatter *f);
+void decode_json_obj(BucketReshardState& s, JSONObj *obj);
 
 // describes the layout of bucket index objects
 struct BucketLayout {
@@ -156,6 +180,8 @@ struct BucketLayout {
 
 void encode(const BucketLayout& l, bufferlist& bl, uint64_t f=0);
 void decode(BucketLayout& l, bufferlist::const_iterator& bl);
+void encode_json_impl(const char *name, const BucketLayout& l, ceph::Formatter *f);
+void decode_json_obj(BucketLayout& l, JSONObj *obj);
 
 
 inline uint32_t num_shards(const bucket_index_normal_layout& index) {
index 62b29b3ed34aea715280089b5ed5f7e2cae38464..b8fe07d3e45c404e3a96fe29d8383700b2ef4668 100644 (file)
@@ -767,6 +767,7 @@ void RGWBucketInfo::dump(Formatter *f) const
   if (!empty_sync_policy()) {
     encode_json("sync_policy", *sync_policy, f);
   }
+  encode_json("layout", layout, f);
 }
 
 void RGWBucketInfo::decode_json(JSONObj *obj) {
@@ -810,6 +811,7 @@ void RGWBucketInfo::decode_json(JSONObj *obj) {
   if (!sp.empty()) {
     set_sync_policy(std::move(sp));
   }
+  JSONDecoder::decode_json("layout", layout, obj);
 }
 
 void rgw_sync_directional_rule::dump(Formatter *f) const