crimson/onode-staged-tree: introduce compile-time tree_conf_t
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 2 Jun 2021 03:52:33 +0000 (11:52 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Fri, 11 Jun 2021 14:43:58 +0000 (22:43 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/onode_manager/staged-fltree/fltree_onode_manager.h
src/crimson/os/seastore/onode_manager/staged-fltree/value.cc
src/crimson/os/seastore/onode_manager/staged-fltree/value.h
src/test/crimson/seastore/onode_tree/test_value.h

index c580defebc61b77001e226efe3563c6831d7de8d..fcb26b25b5ef5d1bc816c0409b19983638cc688b 100644 (file)
@@ -10,7 +10,9 @@
 namespace crimson::os::seastore::onode {
 
 struct FLTreeOnode final : Onode, Value {
-  static constexpr value_magic_t HEADER_MAGIC = value_magic_t::ONODE;
+  static constexpr tree_conf_t TREE_CONF = {
+    value_magic_t::ONODE
+  };
 
   enum class status_t {
     STABLE,
@@ -27,13 +29,11 @@ struct FLTreeOnode final : Onode, Value {
   template <typename... T>
   FLTreeOnode(T&&... args) : Value(std::forward<T>(args)...) {}
 
-
-
   struct Recorder : public ValueDeltaRecorder {
     Recorder(bufferlist &bl) : ValueDeltaRecorder(bl) {}
 
     value_magic_t get_header_magic() const final {
-      return value_magic_t::ONODE;
+      return TREE_CONF.value_magic;
     }
 
     void apply_value_delta(
index cd4bba0e39380a55078e87c1b01219f71477cbad..547872fdf09d62ca762f5dc447531fced2e56c3b 100644 (file)
@@ -85,12 +85,12 @@ build_value_recorder_by_type(ceph::bufferlist& encoded,
 {
   std::unique_ptr<ValueDeltaRecorder> ret;
   switch (magic) {
-  case value_magic_t::TEST:
-    ret = std::make_unique<TestValue::Recorder>(encoded);
-    break;
   case value_magic_t::ONODE:
     ret = std::make_unique<FLTreeOnode::Recorder>(encoded);
     break;
+  case value_magic_t::TEST:
+    ret = std::make_unique<TestValue::Recorder>(encoded);
+    break;
   default:
     ret = nullptr;
     break;
index 95f675d33ad903f621b9f1a685b8e214092cf929..bce1424b760a224452f67dee824f4171baf549a4 100644 (file)
@@ -16,15 +16,15 @@ namespace crimson::os::seastore::onode {
 // value size up to 64 KiB
 using value_size_t = uint16_t;
 enum class value_magic_t : uint8_t {
-  TEST = 0x52,
-  ONODE,
+  ONODE = 0x52,
+  TEST,
 };
 inline std::ostream& operator<<(std::ostream& os, const value_magic_t& magic) {
   switch (magic) {
-  case value_magic_t::TEST:
-    return os << "TEST";
   case value_magic_t::ONODE:
     return os << "ONODE";
+  case value_magic_t::TEST:
+    return os << "TEST";
   default:
     return os << "UNKNOWN(" << magic << ")";
   }
@@ -147,6 +147,15 @@ class ValueDeltaRecorder {
   ceph::bufferlist& encoded;
 };
 
+/**
+ * tree_conf_t
+ *
+ * Hard limits and compile-time configurations.
+ */
+struct tree_conf_t {
+  value_magic_t value_magic;
+};
+
 class tree_cursor_t;
 /**
  * Value
@@ -252,7 +261,7 @@ struct ValueBuilder {
 template <typename ValueImpl>
 struct ValueBuilderImpl final : public ValueBuilder {
   value_magic_t get_header_magic() const {
-    return ValueImpl::HEADER_MAGIC;
+    return ValueImpl::TREE_CONF.value_magic;
   }
 
   std::unique_ptr<ValueDeltaRecorder>
index b1a828e1f6e635121a0474b15c568365f0052fb0..f5aed8a20d3c5e80867de6da3f5f2b74a135bd76 100644 (file)
@@ -38,7 +38,10 @@ inline std::ostream& operator<<(std::ostream& os, const test_item_t& item) {
 
 class TestValue final : public Value {
  public:
-  static constexpr auto HEADER_MAGIC = value_magic_t::TEST;
+  static constexpr tree_conf_t TREE_CONF = {
+    value_magic_t::TEST
+  };
+
   using id_t = test_item_t::id_t;
   using magic_t = test_item_t::magic_t;
   struct magic_packed_t {
@@ -94,7 +97,7 @@ class TestValue final : public Value {
 
    protected:
     value_magic_t get_header_magic() const override {
-      return HEADER_MAGIC;
+      return TREE_CONF.value_magic;
     }
 
     void apply_value_delta(ceph::bufferlist::const_iterator& delta,