]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/seastore: replace L_ADDR_MIN by hint in omap
authorchunmei-liu <chunmei.liu@intel.com>
Sat, 7 Aug 2021 20:39:45 +0000 (13:39 -0700)
committerChunmei Liu <chunmei.liu@intel.com>
Mon, 16 Aug 2021 20:54:48 +0000 (13:54 -0700)
Signed-off-by: chunmei-liu <chunmei.liu@intel.com>
src/crimson/os/seastore/omap_manager.h
src/crimson/os/seastore/omap_manager/btree/btree_omap_manager.cc
src/crimson/os/seastore/omap_manager/btree/btree_omap_manager.h
src/crimson/os/seastore/omap_manager/btree/omap_btree_node.h
src/crimson/os/seastore/omap_manager/btree/omap_btree_node_impl.cc
src/crimson/os/seastore/seastore.cc
src/crimson/os/seastore/seastore.h
src/crimson/os/seastore/seastore_types.h

index 86e4b2853090c87efeff6bfa2f236e258a89d3cd..4107cb2d40125f3c6972d712c86a969af66e130e 100644 (file)
@@ -37,7 +37,7 @@ public:
    */
   using initialize_omap_iertr = base_iertr;
   using initialize_omap_ret = initialize_omap_iertr::future<omap_root_t>;
-  virtual initialize_omap_ret initialize_omap(Transaction &t) = 0;
+  virtual initialize_omap_ret initialize_omap(Transaction &t, laddr_t hint) = 0;
 
   /**
    * get value(string) by key(string)
index 09c03aa43144d39313476391fef6ed928c208b45..8753ad403705d4f7c50c21bdfc8ed7bc9478bbd0 100644 (file)
@@ -22,17 +22,17 @@ BtreeOMapManager::BtreeOMapManager(
   : tm(tm) {}
 
 BtreeOMapManager::initialize_omap_ret
-BtreeOMapManager::initialize_omap(Transaction &t)
+BtreeOMapManager::initialize_omap(Transaction &t, laddr_t hint)
 {
 
   logger().debug("{}", __func__);
-  return tm.alloc_extent<OMapLeafNode>(t, L_ADDR_MIN, OMAP_BLOCK_SIZE)
-    .si_then([](auto&& root_extent) {
+  return tm.alloc_extent<OMapLeafNode>(t, hint, OMAP_BLOCK_SIZE)
+    .si_then([hint](auto&& root_extent) {
       root_extent->set_size(0);
       omap_node_meta_t meta{1};
       root_extent->set_meta(meta);
       omap_root_t omap_root;
-      omap_root.update(root_extent->get_laddr(), 1);
+      omap_root.update(root_extent->get_laddr(), 1, hint);
       return initialize_omap_iertr::make_ready_future<omap_root_t>(omap_root);
   });
 }
@@ -51,7 +51,7 @@ BtreeOMapManager::handle_root_split(
   omap_root_t &omap_root,
   const OMapNode::mutation_result_t& mresult)
 {
-  return oc.tm.alloc_extent<OMapInnerNode>(oc.t, L_ADDR_MIN, OMAP_BLOCK_SIZE)
+  return oc.tm.alloc_extent<OMapInnerNode>(oc.t, omap_root.hint, OMAP_BLOCK_SIZE)
     .si_then([&omap_root, mresult](auto&& nroot) -> handle_root_split_ret {
     auto [left, right, pivot] = *(mresult.split_tuple);
     omap_node_meta_t meta{omap_root.depth + 1};
@@ -60,7 +60,7 @@ BtreeOMapManager::handle_root_split(
                                 "", nroot->maybe_get_delta_buffer());
     nroot->journal_inner_insert(nroot->iter_begin() + 1, right->get_laddr(),
                                 pivot, nroot->maybe_get_delta_buffer());
-    omap_root.update(nroot->get_laddr(), omap_root.get_depth() + 1);
+    omap_root.update(nroot->get_laddr(), omap_root.get_depth() + 1, omap_root.hint);
     return seastar::now();
   });
 }
@@ -75,7 +75,8 @@ BtreeOMapManager::handle_root_merge(
   auto iter = root->cast<OMapInnerNode>()->iter_begin();
   omap_root.update(
     iter->get_val(),
-    omap_root.depth -= 1);
+    omap_root.depth -= 1,
+    omap_root.hint);
   return oc.tm.dec_ref(oc.t, root->get_laddr()
   ).si_then([](auto &&ret) -> handle_root_merge_ret {
     return seastar::now();
@@ -95,10 +96,10 @@ BtreeOMapManager::omap_get_value(
 {
   logger().debug("{}: {}", __func__, key);
   return get_omap_root(
-    get_omap_context(t),
+    get_omap_context(t, omap_root.hint),
     omap_root
-  ).si_then([this, &t, &key](auto&& extent) {
-    return extent->get_value(get_omap_context(t), key);
+  ).si_then([this, &t, &key, &omap_root](auto&& extent) {
+    return extent->get_value(get_omap_context(t, omap_root.hint), key);
   }).si_then([](auto &&e) {
     return omap_get_value_ret(
         interruptible::ready_future_marker{},
@@ -131,15 +132,15 @@ BtreeOMapManager::omap_set_key(
 {
   logger().debug("{}: {} -> {}", __func__, key, value);
   return get_omap_root(
-    get_omap_context(t),
+    get_omap_context(t, omap_root.hint),
     omap_root
-  ).si_then([this, &t, &key, &value](auto root) {
-    return root->insert(get_omap_context(t), key, value);
+  ).si_then([this, &t, &key, &value, &omap_root](auto root) {
+    return root->insert(get_omap_context(t, omap_root.hint), key, value);
   }).si_then([this, &omap_root, &t](auto mresult) -> omap_set_key_ret {
     if (mresult.status == mutation_status_t::SUCCESS)
       return seastar::now();
     else if (mresult.status == mutation_status_t::WAS_SPLIT)
-      return handle_root_split(get_omap_context(t), omap_root, mresult);
+      return handle_root_split(get_omap_context(t, omap_root.hint), omap_root, mresult);
     else
       return seastar::now();
   });
@@ -153,19 +154,19 @@ BtreeOMapManager::omap_rm_key(
 {
   logger().debug("{}: {}", __func__, key);
   return get_omap_root(
-    get_omap_context(t),
+    get_omap_context(t, omap_root.hint),
     omap_root
-  ).si_then([this, &t, &key](auto root) {
-    return root->rm_key(get_omap_context(t), key);
+  ).si_then([this, &t, &key, &omap_root](auto root) {
+    return root->rm_key(get_omap_context(t, omap_root.hint), key);
   }).si_then([this, &omap_root, &t](auto mresult) -> omap_rm_key_ret {
     if (mresult.status == mutation_status_t::SUCCESS) {
       return seastar::now();
     } else if (mresult.status == mutation_status_t::WAS_SPLIT) {
-      return handle_root_split(get_omap_context(t), omap_root, mresult);
+      return handle_root_split(get_omap_context(t, omap_root.hint), omap_root, mresult);
     } else if (mresult.status == mutation_status_t::NEED_MERGE) {
       auto root = *(mresult.need_merge);
       if (root->get_node_size() == 1 && omap_root.depth != 1) {
-        return handle_root_merge(get_omap_context(t), omap_root, mresult);
+        return handle_root_merge(get_omap_context(t, omap_root.hint), omap_root, mresult);
       } else {
         return seastar::now(); 
       }
@@ -185,11 +186,11 @@ BtreeOMapManager::omap_list(
 {
   logger().debug("{}", __func__);
   return get_omap_root(
-    get_omap_context(t),
+    get_omap_context(t, omap_root.hint),
     omap_root
-  ).si_then([this, config, &t, &start](auto extent) {
+  ).si_then([this, config, &t, &start, &omap_root](auto extent) {
     return extent->list(
-      get_omap_context(t),
+      get_omap_context(t, omap_root.hint),
       start,
       config);
   });
@@ -202,17 +203,17 @@ BtreeOMapManager::omap_clear(
 {
   logger().debug("{}", __func__);
   return get_omap_root(
-    get_omap_context(t),
+    get_omap_context(t, omap_root.hint),
     omap_root
-  ).si_then([this, &t](auto extent) {
-    return extent->clear(get_omap_context(t));
+  ).si_then([this, &t, &omap_root](auto extent) {
+    return extent->clear(get_omap_context(t, omap_root.hint));
   }).si_then([this, &omap_root, &t] {
     return tm.dec_ref(
       t, omap_root.get_location()
     ).si_then([&omap_root] (auto ret) {
       omap_root.update(
        L_ADDR_NULL,
-       0);
+       0, L_ADDR_MIN);
       return omap_clear_iertr::now();
     });
   }).handle_error_interruptible(
index 3f155d697074cc308ba9445e48efe59587cbd4f0..87ce68235a06be7fb7efced2cfd1427e5b34d147 100644 (file)
@@ -26,8 +26,8 @@ class BtreeOMapManager : public OMapManager {
   TransactionManager &tm;
 
   omap_context_t get_omap_context(
-    Transaction &t) {
-    return omap_context_t{tm, t};
+    Transaction &t, laddr_t addr_min) {
+    return omap_context_t{tm, t, addr_min};
   }
 
   /* get_omap_root
@@ -65,7 +65,7 @@ class BtreeOMapManager : public OMapManager {
 public:
   explicit BtreeOMapManager(TransactionManager &tm);
 
-  initialize_omap_ret initialize_omap(Transaction &t) final;
+  initialize_omap_ret initialize_omap(Transaction &t, laddr_t hint) final;
 
   omap_get_value_ret omap_get_value(
     const omap_root_t &omap_root,
index d59b82ca35a0098e898b1632dc8c37ca9a21b947..5280e73c49622d197c7eb791eefd188bc519c0df 100644 (file)
@@ -18,6 +18,7 @@ namespace crimson::os::seastore::omap_manager{
 struct omap_context_t {
   TransactionManager &tm;
   Transaction &t;
+  laddr_t hint;
 };
 
 enum class mutation_status_t : uint8_t {
index ad8e468bb54a304f99e409665adbd252b4c0945f..66aea6a44274bc219b2e47c62f813e972c73b51a 100644 (file)
@@ -281,7 +281,7 @@ OMapInnerNode::full_merge_ret
 OMapInnerNode::make_full_merge(omap_context_t oc, OMapNodeRef right)
 {
   logger().debug("OMapInnerNode: {}", __func__);
-  return oc.tm.alloc_extent<OMapInnerNode>(oc.t, L_ADDR_MIN, OMAP_BLOCK_SIZE)
+  return oc.tm.alloc_extent<OMapInnerNode>(oc.t, oc.hint, OMAP_BLOCK_SIZE)
     .si_then([this, right] (auto &&replacement) {
       replacement->merge_from(*this, *right->cast<OMapInnerNode>());
       return full_merge_ret(
@@ -569,7 +569,7 @@ OMapLeafNode::make_full_merge(omap_context_t oc, OMapNodeRef right)
 {
   ceph_assert(right->get_type() == TYPE);
   logger().debug("OMapLeafNode: {}", __func__);
-  return oc.tm.alloc_extent<OMapLeafNode>(oc.t, L_ADDR_MIN, OMAP_BLOCK_SIZE)
+  return oc.tm.alloc_extent<OMapLeafNode>(oc.t, oc.hint, OMAP_BLOCK_SIZE)
     .si_then([this, right] (auto &&replacement) {
       replacement->merge_from(*this, *right->cast<OMapLeafNode>());
       return full_merge_ret(
index 75140368351ded2c18efef1ca1f29c8e78ccd556..3973da181b2b53657e6d2931c7928ca8d401acd2 100644 (file)
@@ -301,7 +301,7 @@ SeaStore::get_attr_errorator::future<ceph::bufferlist> SeaStore::get_attr(
       }
       return _omap_get_value(
         t,
-        layout.xattr_root.get(),
+        layout.xattr_root.get(onode.get_hint()),
         name);
     }
   ).handle_error(crimson::ct_error::input_output_error::handle([FNAME] {
@@ -324,7 +324,7 @@ SeaStore::get_attrs_ertr::future<SeaStore::attrs_t> SeaStore::get_attrs(
     op_type_t::GET_ATTRS,
     [=](auto &t, auto& onode) {
       auto& layout = onode.get_layout();
-      return _omap_list(layout.xattr_root, t, std::nullopt,
+      return _omap_list(onode, layout.xattr_root, t, std::nullopt,
         OMapManager::omap_list_config_t::with_inclusive(false)
       ).si_then([&layout](auto p) {
         auto& attrs = std::get<1>(p);
@@ -396,7 +396,7 @@ SeaStore::omap_get_values(
     Transaction::src_t::READ,
     op_type_t::OMAP_GET_VALUES,
     [this, keys](auto &t, auto &onode) {
-      omap_root_t omap_root = onode.get_layout().omap_root.get();
+      omap_root_t omap_root = onode.get_layout().omap_root.get(onode.get_hint());
       return _omap_get_values(
        t,
        std::move(omap_root),
@@ -468,12 +468,13 @@ SeaStore::_omap_get_values_ret SeaStore::_omap_get_values(
 }
 
 SeaStore::_omap_list_ret SeaStore::_omap_list(
+  Onode &onode,
   const omap_root_le_t& omap_root,
   Transaction& t,
   const std::optional<std::string>& start,
   OMapManager::omap_list_config_t config) const
 {
-  auto root = omap_root.get();
+  auto root = omap_root.get(onode.get_hint());
   if (root.is_null()) {
     return seastar::make_ready_future<_omap_list_bare_ret>(
       true, omap_values_t{}
@@ -505,6 +506,7 @@ SeaStore::omap_get_values_ret_t SeaStore::omap_list(
     op_type_t::OMAP_LIST,
     [this, config, &start](auto &t, auto &onode) {
       return _omap_list(
+       onode,
        onode.get_layout().omap_root,
        t, start, config
       );
@@ -860,6 +862,7 @@ SeaStore::tm_ret SeaStore::_write(
 
 SeaStore::omap_set_kvs_ret
 SeaStore::_omap_set_kvs(
+  OnodeRef &onode,
   const omap_root_le_t& omap_root,
   Transaction& t,
   omap_root_le_t& mutable_omap_root,
@@ -867,13 +870,13 @@ SeaStore::_omap_set_kvs(
 {
   return seastar::do_with(
     BtreeOMapManager(*transaction_manager),
-    omap_root.get(),
+    omap_root.get(onode->get_hint()),
     [&, keys=std::move(kvs)](auto &omap_manager, auto &root) {
       tm_iertr::future<> maybe_create_root =
         !root.is_null() ?
         tm_iertr::now() :
         omap_manager.initialize_omap(
-          t
+          t, onode->get_hint()
         ).si_then([&root](auto new_root) {
           root = new_root;
         });
@@ -899,6 +902,7 @@ SeaStore::tm_ret SeaStore::_omap_set_values(
   LOG_PREFIX(SeaStore::_omap_set_values);
   DEBUGT("{} {} keys", *ctx.transaction, *onode, aset.size());
   return _omap_set_kvs(
+    onode,
     onode->get_layout().omap_root,
     *ctx.transaction,
     onode->get_mutable_layout(*ctx.transaction).omap_root,
@@ -923,13 +927,13 @@ SeaStore::tm_ret SeaStore::_omap_rmkeys(
 {
   LOG_PREFIX(SeaStore::_omap_rmkeys);
   DEBUGT("{} {} keys", *ctx.transaction, *onode, keys.size());
-  auto omap_root = onode->get_layout().omap_root.get();
+  auto omap_root = onode->get_layout().omap_root.get(onode->get_hint());
   if (omap_root.is_null()) {
     return seastar::now();
   } else {
     return seastar::do_with(
       BtreeOMapManager(*transaction_manager),
-      onode->get_layout().omap_root.get(),
+      onode->get_layout().omap_root.get(onode->get_hint()),
       std::move(keys),
       [&ctx, &onode](
        auto &omap_manager,
@@ -1027,6 +1031,7 @@ SeaStore::tm_ret SeaStore::_setattrs(
   }
 
   return _omap_set_kvs(
+    onode,
     onode->get_layout().xattr_root,
     *ctx.transaction,
     layout.xattr_root,
index f757d9b8a3aa7a3ee8858357a1a3cfc5a4cd7f0f..471328c8a3a211d88a5bde708a402bc05bd170d0 100644 (file)
@@ -250,6 +250,7 @@ private:
   using _omap_list_bare_ret = OMapManager::omap_list_bare_ret;
   using _omap_list_ret = OMapManager::omap_list_ret;
   _omap_list_ret _omap_list(
+    Onode &onode,
     const omap_root_le_t& omap_root,
     Transaction& t,
     const std::optional<std::string>& start,
@@ -319,6 +320,7 @@ private:
     const coll_t& cid);
   using omap_set_kvs_ret = tm_iertr::future<>;
   omap_set_kvs_ret _omap_set_kvs(
+    OnodeRef &onode,
     const omap_root_le_t& omap_root,
     Transaction& t,
     omap_root_le_t& mutable_omap_root,
index 7d485e7ccd35dbb7e0836844b2c6f20d02a9787e..43386a54a3b90e88255ae4ec0bc7d9e71b419abc 100644 (file)
@@ -484,12 +484,14 @@ struct __attribute__((packed)) object_data_le_t {
 struct omap_root_t {
   laddr_t addr = L_ADDR_NULL;
   depth_t depth = 0;
+  laddr_t hint = L_ADDR_MIN;
   bool mutated = false;
 
   omap_root_t() = default;
-  omap_root_t(laddr_t addr, depth_t depth)
+  omap_root_t(laddr_t addr, depth_t depth, laddr_t addr_min)
     : addr(addr),
-      depth(depth) {}
+      depth(depth),
+      hint(addr_min) {}
 
   omap_root_t(const omap_root_t &o) = default;
   omap_root_t(omap_root_t &&o) = default;
@@ -504,10 +506,11 @@ struct omap_root_t {
     return mutated;
   }
   
-  void update(laddr_t _addr, depth_t _depth) {
+  void update(laddr_t _addr, depth_t _depth, laddr_t _hint) {
     mutated = true;
     addr = _addr;
     depth = _depth;
+    hint = _hint;
   }
   
   laddr_t get_location() const {
@@ -517,6 +520,10 @@ struct omap_root_t {
   depth_t get_depth() const {
     return depth;
   }
+
+  laddr_t get_hint() const {
+    return hint;
+  }
 };
 
 class __attribute__((packed)) omap_root_le_t {
@@ -539,8 +546,8 @@ public:
     depth = init_depth_le(nroot.get_depth());
   }
   
-  omap_root_t get() const {
-    return omap_root_t(addr, depth);
+  omap_root_t get(laddr_t hint) const {
+    return omap_root_t(addr, depth, hint);
   }
 };