]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/os/seastore/btree: "templatize" btree leaf node to distinguish leaf nodes...
authorXuehan Xu <xxhdx1985126@gmail.com>
Thu, 27 Oct 2022 07:21:32 +0000 (15:21 +0800)
committerXuehan Xu <xxhdx1985126@gmail.com>
Tue, 9 May 2023 05:56:59 +0000 (05:56 +0000)
Signed-off-by: Xuehan Xu <xxhdx1985126@gmail.com>
14 files changed:
src/crimson/os/seastore/backref/backref_tree_node.h
src/crimson/os/seastore/backref/btree_backref_manager.h
src/crimson/os/seastore/btree/fixed_kv_btree.h
src/crimson/os/seastore/btree/fixed_kv_node.h
src/crimson/os/seastore/cache.cc
src/crimson/os/seastore/cache.h
src/crimson/os/seastore/cached_extent.h
src/crimson/os/seastore/lba_manager.cc
src/crimson/os/seastore/lba_manager.h
src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.cc
src/crimson/os/seastore/lba_manager/btree/btree_lba_manager.h
src/crimson/os/seastore/lba_manager/btree/lba_btree_node.h
src/crimson/os/seastore/seastore_types.h
src/test/crimson/seastore/test_btree_lba_manager.cc

index bebbc0aa4b2f5ddad143613f7cd24c86133316df..db9f1febff1251aca79291b248f04a9468f26814 100644 (file)
@@ -76,7 +76,8 @@ class BackrefLeafNode
       paddr_t, paddr_le_t,
       backref_map_val_t, backref_map_val_le_t,
       BACKREF_NODE_SIZE,
-      BackrefLeafNode> {
+      BackrefLeafNode,
+      false> {
 public:
   template <typename... T>
   BackrefLeafNode(T&&... t) :
index 95a1c03113db8f516f6d7e6a4db1a8041600a401..0306d0e8bbe3043c9a4f825c6f22e60d72801370 100644 (file)
@@ -33,7 +33,7 @@ public:
 
 using BackrefBtree = FixedKVBtree<
   paddr_t, backref_map_val_t, BackrefInternalNode,
-  BackrefLeafNode, BtreeBackrefPin, BACKREF_BLOCK_SIZE>;
+  BackrefLeafNode, BtreeBackrefPin, BACKREF_BLOCK_SIZE, false>;
 
 class BtreeBackrefManager : public BackrefManager {
 public:
index 0e51d00ed76787ce1d0e5328db08049334dcd5fd..6c3372819f32494eaa7ec13ee96a17a15fecd9f6 100644 (file)
@@ -57,7 +57,8 @@ template <
   typename internal_node_t,
   typename leaf_node_t,
   typename pin_t,
-  size_t node_size>
+  size_t node_size,
+  bool leaf_has_children>
 class FixedKVBtree {
   static constexpr size_t MAX_DEPTH = 16;
   using self_type = FixedKVBtree<
@@ -66,7 +67,8 @@ class FixedKVBtree {
     internal_node_t,
     leaf_node_t,
     pin_t,
-    node_size>;
+    node_size,
+    leaf_has_children>;
 public:
   using InternalNodeRef = TCachedExtentRef<internal_node_t>;
   using LeafNodeRef = TCachedExtentRef<leaf_node_t>;
@@ -866,7 +868,8 @@ public:
       n_fixed_kv_extent->set_modify_time(fixed_kv_extent.get_modify_time());
       n_fixed_kv_extent->pin.set_range(n_fixed_kv_extent->get_node_meta());
 
-      if (fixed_kv_extent.get_type() == internal_node_t::TYPE) {
+      if (fixed_kv_extent.get_type() == internal_node_t::TYPE ||
+          leaf_node_t::do_has_children) {
         if (!fixed_kv_extent.is_pending()) {
           n_fixed_kv_extent->copy_sources.emplace(&fixed_kv_extent);
           n_fixed_kv_extent->prior_instance = &fixed_kv_extent;
@@ -2008,7 +2011,8 @@ template <
   typename internal_node_t,
   typename leaf_node_t,
   typename pin_t,
-  size_t node_size>
+  size_t node_size,
+  bool leaf_has_children>
 struct is_fixed_kv_tree<
   FixedKVBtree<
     node_key_t,
@@ -2016,7 +2020,8 @@ struct is_fixed_kv_tree<
     internal_node_t,
     leaf_node_t,
     pin_t,
-    node_size>> : std::true_type {};
+    node_size,
+    leaf_has_children>> : std::true_type {};
 
 template <
   typename tree_type_t,
index bee5b2fa512ebafec10f16245a87e6802b92b9d0..202a270a336024efe26427f680cc2f27347bb27f 100644 (file)
@@ -915,7 +915,8 @@ template <
   typename VAL,
   typename VAL_LE,
   size_t node_size,
-  typename node_type_t>
+  typename node_type_t,
+  bool has_children>
 struct FixedKVLeafNode
   : FixedKVNode<NODE_KEY>,
     common::FixedKVNodeLayout<
@@ -942,6 +943,8 @@ struct FixedKVLeafNode
     : FixedKVNode<NODE_KEY>(rhs),
       node_layout_t(this->get_bptr().c_str()) {}
 
+  static constexpr bool do_has_children = has_children;
+
   uint16_t get_node_split_pivot() final {
     return this->get_split_pivot().get_offset();
   }
index b189b96c23848d0708f88952b1d681a6dbf5bdd4..65f7f1d400f3d0cbc97a0d305d82f74e6a4e2cf6 100644 (file)
@@ -146,6 +146,7 @@ void Cache::register_metrics()
     {extent_types_t::ROOT,                sm::label_instance("ext", "ROOT")},
     {extent_types_t::LADDR_INTERNAL,      sm::label_instance("ext", "LADDR_INTERNAL")},
     {extent_types_t::LADDR_LEAF,          sm::label_instance("ext", "LADDR_LEAF")},
+    {extent_types_t::DINK_LADDR_LEAF,     sm::label_instance("ext", "DINK_LADDR_LEAF")},
     {extent_types_t::OMAP_INNER,          sm::label_instance("ext", "OMAP_INNER")},
     {extent_types_t::OMAP_LEAF,           sm::label_instance("ext", "OMAP_LEAF")},
     {extent_types_t::ONODE_BLOCK_STAGED,  sm::label_instance("ext", "ONODE_BLOCK_STAGED")},
@@ -969,7 +970,8 @@ CachedExtentRef Cache::alloc_new_extent_by_type(
   case extent_types_t::LADDR_INTERNAL:
     return alloc_new_extent<lba_manager::btree::LBAInternalNode>(t, length, hint, gen);
   case extent_types_t::LADDR_LEAF:
-    return alloc_new_extent<lba_manager::btree::LBALeafNode>(t, length, hint, gen);
+    return alloc_new_extent<lba_manager::btree::LBALeafNode>(
+      t, length, hint, gen);
   case extent_types_t::ONODE_BLOCK_STAGED:
     return alloc_new_extent<onode::SeastoreNodeExtent>(t, length, hint, gen);
   case extent_types_t::OMAP_INNER:
index ec3c27b160674cdd3663c51b6fc80d3d6a89626a..0e004761bab8975848a81bbddb6f18b12fc6453a 100644 (file)
@@ -1119,6 +1119,8 @@ public:
     switch (type) {
     case extent_types_t::LADDR_INTERNAL:
       [[fallthrough]];
+    case extent_types_t::DINK_LADDR_LEAF:
+      [[fallthrough]];
     case extent_types_t::LADDR_LEAF:
       stats.lba_tree_extents_num += delta;
       ceph_assert(stats.lba_tree_extents_num >= 0);
index a2544d5e996b05bdbbeedb79e15358da4121f617..5ee08f9bbb6099de1d62b050b9945f0aeec10f81 100644 (file)
@@ -30,7 +30,8 @@ template <
   typename internal_node_t,
   typename leaf_node_t,
   typename pin_t,
-  size_t node_size>
+  size_t node_size,
+  bool leaf_has_children>
 class FixedKVBtree;
 
 // #define DEBUG_CACHED_EXTENT_REF
@@ -189,7 +190,8 @@ class CachedExtent
     typename internal_node_t,
     typename leaf_node_t,
     typename pin_t,
-    size_t node_size>
+    size_t node_size,
+    bool leaf_has_children>
   friend class FixedKVBtree;
   uint32_t last_committed_crc = 0;
 
index 3e3251f062a52562dc97b04524638f8d57e6b4aa..b35e2d0ead8c38d70ed283c3c63490b1b06b1d62 100644 (file)
@@ -22,8 +22,12 @@ LBAManager::update_mappings(
   });
 }
 
+template <bool leaf_has_children>
 LBAManagerRef lba_manager::create_lba_manager(Cache &cache) {
-  return LBAManagerRef(new btree::BtreeLBAManager(cache));
+  return LBAManagerRef(new btree::BtreeLBAManager<leaf_has_children>(cache));
 }
 
+template  LBAManagerRef lba_manager::create_lba_manager<true>(Cache &cache);
+template  LBAManagerRef lba_manager::create_lba_manager<false>(Cache &cache);
+
 }
index f512b73f677e11f2834532974dd7185fffca4382..f495eb0753483da5efb9a3b09b9b5b6505b298e4 100644 (file)
@@ -206,6 +206,7 @@ using LBAManagerRef = std::unique_ptr<LBAManager>;
 
 class Cache;
 namespace lba_manager {
+template <bool leaf_has_children>
 LBAManagerRef create_lba_manager(Cache &cache);
 }
 
index 2c159535f3874f5273a7e60ff2b9771eb93a4606..64dd3103ce2bfc55ddd6d50654c447c72eb6c6ac 100644 (file)
@@ -21,18 +21,27 @@ SET_SUBSYS(seastore_lba);
 
 namespace crimson::os::seastore {
 
-template<>
-Transaction::tree_stats_t& get_tree_stats<
-  crimson::os::seastore::lba_manager::btree::LBABtree>(Transaction &t) {
+template <typename T>
+Transaction::tree_stats_t& get_tree_stats(Transaction &t)
+{
   return t.get_lba_tree_stats();
 }
 
-template<>
-phy_tree_root_t& get_phy_tree_root<
-  crimson::os::seastore::lba_manager::btree::LBABtree>(root_t &r) {
+template Transaction::tree_stats_t&
+get_tree_stats<
+  crimson::os::seastore::lba_manager::btree::LBABtree>(
+  Transaction &t);
+
+template <typename T>
+phy_tree_root_t& get_phy_tree_root(root_t &r)
+{
   return r.lba_root;
 }
 
+template phy_tree_root_t&
+get_phy_tree_root<
+  crimson::os::seastore::lba_manager::btree::LBABtree>(root_t &r);
+
 template <>
 const get_phy_tree_root_node_ret get_phy_tree_root_node<
   crimson::os::seastore::lba_manager::btree::LBABtree>(
@@ -89,7 +98,8 @@ void unlink_phy_tree_root_node<laddr_t>(RootBlockRef &root_block) {
 
 namespace crimson::os::seastore::lba_manager::btree {
 
-BtreeLBAManager::mkfs_ret BtreeLBAManager::mkfs(
+BtreeLBAManager::mkfs_ret
+BtreeLBAManager::mkfs(
   Transaction &t)
 {
   LOG_PREFIX(BtreeLBAManager::mkfs);
@@ -125,7 +135,7 @@ BtreeLBAManager::get_mappings(
          if (pos.is_end() || pos.get_key() >= (offset + length)) {
            TRACET("{}~{} done with {} results",
                   c.trans, offset, length, ret.size());
-           return LBABtree::iterate_repeat_ret_inner(
+           return typename LBABtree::iterate_repeat_ret_inner(
              interruptible::ready_future_marker{},
              seastar::stop_iteration::yes);
          }
@@ -133,14 +143,13 @@ BtreeLBAManager::get_mappings(
                 c.trans, offset, length, pos.get_key(), pos.get_val());
          ceph_assert((pos.get_key() + pos.get_val().len) > offset);
          ret.push_back(pos.get_pin());
-         return LBABtree::iterate_repeat_ret_inner(
+         return typename LBABtree::iterate_repeat_ret_inner(
            interruptible::ready_future_marker{},
            seastar::stop_iteration::no);
        });
     });
 }
 
-
 BtreeLBAManager::get_mappings_ret
 BtreeLBAManager::get_mappings(
   Transaction &t,
@@ -155,7 +164,7 @@ BtreeLBAManager::get_mappings(
     l->begin(),
     l->end(),
     [this, &t, &ret](const auto &p) {
-      return get_mappings(t, p.first, p.second).si_then(
+      return this->get_mappings(t, p.first, p.second).si_then(
        [&ret](auto res) {
          ret.splice(ret.end(), res, res.begin(), res.end());
          return get_mappings_iertr::now();
@@ -205,8 +214,8 @@ BtreeLBAManager::alloc_extent(
   struct state_t {
     laddr_t last_end;
 
-    std::optional<LBABtree::iterator> insert_iter;
-    std::optional<LBABtree::iterator> ret;
+    std::optional<typename LBABtree::iterator> insert_iter;
+    std::optional<typename LBABtree::iterator> ret;
 
     state_t(laddr_t hint) : last_end(hint) {}
   };
@@ -232,7 +241,7 @@ BtreeLBAManager::alloc_extent(
                    stats.num_alloc_extents_iter_nexts - lookup_attempts,
                    state.last_end);
            state.insert_iter = pos;
-           return LBABtree::iterate_repeat_ret_inner(
+           return typename LBABtree::iterate_repeat_ret_inner(
              interruptible::ready_future_marker{},
              seastar::stop_iteration::yes);
          } else if (pos.get_key() >= (state.last_end + len)) {
@@ -243,7 +252,7 @@ BtreeLBAManager::alloc_extent(
                    state.last_end,
                    pos.get_val());
            state.insert_iter = pos;
-           return LBABtree::iterate_repeat_ret_inner(
+           return typename LBABtree::iterate_repeat_ret_inner(
              interruptible::ready_future_marker{},
              seastar::stop_iteration::yes);
          } else {
@@ -252,7 +261,7 @@ BtreeLBAManager::alloc_extent(
                    t, addr, len, hint,
                    pos.get_key(), pos.get_val().len,
                    pos.get_val());
-           return LBABtree::iterate_repeat_ret_inner(
+           return typename LBABtree::iterate_repeat_ret_inner(
              interruptible::ready_future_marker{},
              seastar::stop_iteration::no);
          }
@@ -280,7 +289,8 @@ static bool is_lba_node(const CachedExtent &e)
   return is_lba_node(e.get_type());
 }
 
-btree_range_pin_t<laddr_t> &BtreeLBAManager::get_pin(CachedExtent &e)
+btree_range_pin_t<laddr_t> &BtreeLBAManager::get_pin(
+  CachedExtent &e)
 {
   if (is_lba_node(e)) {
     return e.cast<LBANode>()->pin;
@@ -338,7 +348,8 @@ void BtreeLBAManager::complete_transaction(
   }
 }
 
-BtreeLBAManager::base_iertr::future<> _init_cached_extent(
+BtreeLBAManager::base_iertr::template future<>
+_init_cached_extent(
   op_context_t<laddr_t> c,
   const CachedExtentRef &e,
   LBABtree &btree,
@@ -377,7 +388,8 @@ BtreeLBAManager::base_iertr::future<> _init_cached_extent(
   }
 }
 
-BtreeLBAManager::init_cached_extent_ret BtreeLBAManager::init_cached_extent(
+BtreeLBAManager::init_cached_extent_ret
+BtreeLBAManager::init_cached_extent(
   Transaction &t,
   CachedExtentRef e)
 {
@@ -385,16 +397,19 @@ BtreeLBAManager::init_cached_extent_ret BtreeLBAManager::init_cached_extent(
   TRACET("{}", t, *e);
   return seastar::do_with(bool(), [this, e, &t](bool &ret) {
     auto c = get_context(t);
-    return with_btree<LBABtree>(cache, c, [c, e, &ret](auto &btree)
-      -> base_iertr::future<> {
-      LOG_PREFIX(BtreeLBAManager::init_cached_extent);
-      DEBUGT("extent {}", c.trans, *e);
-      return _init_cached_extent(c, e, btree, ret);
-    }).si_then([&ret] { return ret; });
+    return with_btree<LBABtree>(
+      cache, c,
+      [c, e, &ret](auto &btree) -> base_iertr::future<> {
+       LOG_PREFIX(BtreeLBAManager::init_cached_extent);
+       DEBUGT("extent {}", c.trans, *e);
+       return _init_cached_extent(c, e, btree, ret);
+      }
+    ).si_then([&ret] { return ret; });
   });
 }
 
-BtreeLBAManager::scan_mappings_ret BtreeLBAManager::scan_mappings(
+BtreeLBAManager::scan_mappings_ret
+BtreeLBAManager::scan_mappings(
   Transaction &t,
   laddr_t begin,
   laddr_t end,
@@ -413,20 +428,21 @@ BtreeLBAManager::scan_mappings_ret BtreeLBAManager::scan_mappings(
        btree.upper_bound_right(c, begin),
        [f=std::move(f), begin, end](auto &pos) {
          if (pos.is_end() || pos.get_key() >= end) {
-           return LBABtree::iterate_repeat_ret_inner(
+           return typename LBABtree::iterate_repeat_ret_inner(
              interruptible::ready_future_marker{},
              seastar::stop_iteration::yes);
          }
          ceph_assert((pos.get_key() + pos.get_val().len) > begin);
          f(pos.get_key(), pos.get_val().paddr, pos.get_val().len);
-         return LBABtree::iterate_repeat_ret_inner(
+         return typename LBABtree::iterate_repeat_ret_inner(
            interruptible::ready_future_marker{},
            seastar::stop_iteration::no);
        });
     });
 }
 
-BtreeLBAManager::rewrite_extent_ret BtreeLBAManager::rewrite_extent(
+BtreeLBAManager::rewrite_extent_ret
+BtreeLBAManager::rewrite_extent(
   Transaction &t,
   CachedExtentRef extent)
 {
@@ -504,18 +520,13 @@ BtreeLBAManager::get_physical_extent_if_live(
       if (type == extent_types_t::LADDR_INTERNAL) {
        return btree.get_internal_if_live(c, addr, laddr, len);
       } else {
-       assert(type == extent_types_t::LADDR_LEAF);
+       assert(type == extent_types_t::LADDR_LEAF ||
+              type == extent_types_t::DINK_LADDR_LEAF);
        return btree.get_leaf_if_live(c, addr, laddr, len);
       }
     });
 }
 
-BtreeLBAManager::BtreeLBAManager(Cache &cache)
-  : cache(cache)
-{
-  register_metrics();
-}
-
 void BtreeLBAManager::register_metrics()
 {
   LOG_PREFIX(BtreeLBAManager::register_metrics);
@@ -539,7 +550,8 @@ void BtreeLBAManager::register_metrics()
   );
 }
 
-BtreeLBAManager::update_refcount_ret BtreeLBAManager::update_refcount(
+BtreeLBAManager::update_refcount_ret
+BtreeLBAManager::update_refcount(
   Transaction &t,
   laddr_t addr,
   int delta)
@@ -565,7 +577,8 @@ BtreeLBAManager::update_refcount_ret BtreeLBAManager::update_refcount(
   });
 }
 
-BtreeLBAManager::_update_mapping_ret BtreeLBAManager::_update_mapping(
+BtreeLBAManager::_update_mapping_ret
+BtreeLBAManager::_update_mapping(
   Transaction &t,
   laddr_t addr,
   update_func_t &&f)
@@ -606,13 +619,4 @@ BtreeLBAManager::_update_mapping_ret BtreeLBAManager::_update_mapping(
     });
 }
 
-BtreeLBAManager::~BtreeLBAManager()
-{
-  pin_set.scan([](auto &i) {
-    LOG_PREFIX(BtreeLBAManager::~BtreeLBAManager);
-    ERROR("Found {}, has_ref={} -- {}",
-          i, i.has_ref(), i.get_extent());
-  });
-}
-
 }
index 3b0aa4aafd4edfc409d03fb8ee118acb64d3114f..58dbe1e0581f3b22ce0ba9e9d6c0e1ce9eadf45d 100644 (file)
@@ -42,7 +42,7 @@ public:
 
 using LBABtree = FixedKVBtree<
   laddr_t, lba_map_val_t, LBAInternalNode,
-  LBALeafNode, BtreeLBAPin, LBA_BLOCK_SIZE>;
+  LBALeafNode, BtreeLBAPin, LBA_BLOCK_SIZE, true>;
 
 /**
  * BtreeLBAManager
@@ -63,7 +63,11 @@ using LBABtree = FixedKVBtree<
  */
 class BtreeLBAManager : public LBAManager {
 public:
-  BtreeLBAManager(Cache &cache);
+  BtreeLBAManager(Cache &cache)
+    : cache(cache)
+  {
+    register_metrics();
+  }
 
   mkfs_ret mkfs(
     Transaction &t) final;
@@ -144,7 +148,13 @@ public:
     bpin->set_parent(nullptr);
   }
 
-  ~BtreeLBAManager();
+  ~BtreeLBAManager() {
+    pin_set.scan([](auto &i) {
+      LOG_PREFIX(BtreeLBAManager::~BtreeLBAManager);
+      SUBERROR(seastore_lba, "Found {}, has_ref={} -- {}",
+           i, i.has_ref(), i.get_extent());
+    });
+  }
 private:
   Cache &cache;
 
index 571e906fa8fedaf2460dc78b0450f9fcfb536303..ff61829cb2e944e98dee61530fb411ea8c40bc9c 100644 (file)
@@ -142,7 +142,8 @@ struct LBALeafNode
       laddr_t, laddr_le_t,
       lba_map_val_t, lba_map_val_le_t,
       LBA_BLOCK_SIZE,
-      LBALeafNode> {
+      LBALeafNode,
+      true> {
   using Ref = TCachedExtentRef<LBALeafNode>;
   using internal_iterator_t = const_iterator;
   template <typename... T>
index a1efc729b96fa2457ba94d8aca38b8524c65f31e..9b5e8801e31446cc1b27a0bf0bc51b2a5b1f163a 100644 (file)
@@ -1062,23 +1062,24 @@ enum class extent_types_t : uint8_t {
   ROOT = 0,
   LADDR_INTERNAL = 1,
   LADDR_LEAF = 2,
-  OMAP_INNER = 3,
-  OMAP_LEAF = 4,
-  ONODE_BLOCK_STAGED = 5,
-  COLL_BLOCK = 6,
-  OBJECT_DATA_BLOCK = 7,
-  RETIRED_PLACEHOLDER = 8,
+  DINK_LADDR_LEAF = 3,
+  OMAP_INNER = 4,
+  OMAP_LEAF = 5,
+  ONODE_BLOCK_STAGED = 6,
+  COLL_BLOCK = 7,
+  OBJECT_DATA_BLOCK = 8,
+  RETIRED_PLACEHOLDER = 9,
   // the following two types are not extent types,
   // they are just used to indicates paddr allocation deltas
-  ALLOC_INFO = 9,
-  JOURNAL_TAIL = 10,
+  ALLOC_INFO = 10,
+  JOURNAL_TAIL = 11,
   // Test Block Types
-  TEST_BLOCK = 11,
-  TEST_BLOCK_PHYSICAL = 12,
-  BACKREF_INTERNAL = 13,
-  BACKREF_LEAF = 14,
+  TEST_BLOCK = 12,
+  TEST_BLOCK_PHYSICAL = 13,
+  BACKREF_INTERNAL = 14,
+  BACKREF_LEAF = 15,
   // None and the number of valid extent_types_t
-  NONE = 15,
+  NONE = 16,
 };
 using extent_types_le_t = uint8_t;
 constexpr auto EXTENT_TYPES_MAX = static_cast<uint8_t>(extent_types_t::NONE);
@@ -1108,7 +1109,8 @@ constexpr bool is_retired_placeholder(extent_types_t type)
 constexpr bool is_lba_node(extent_types_t type)
 {
   return type == extent_types_t::LADDR_INTERNAL ||
-    type == extent_types_t::LADDR_LEAF;
+    type == extent_types_t::LADDR_LEAF ||
+    type == extent_types_t::DINK_LADDR_LEAF;
 }
 
 constexpr bool is_backref_node(extent_types_t type)
index 3853d53e7a4ff70622904f3e0e9f500ca3d7e971..64a847f30a72993377248c45595802d70015c765 100644 (file)
@@ -324,7 +324,7 @@ TEST_F(lba_btree_test, basic)
 }
 
 struct btree_lba_manager_test : btree_test_base {
-  BtreeLBAManagerRef lba_manager;
+  BtreeLBAManagerRef<false> lba_manager;
 
   btree_lba_manager_test() = default;