]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/onode-staged-tree: cleanup the end tree_cursor_t cstr
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 16 Sep 2020 15:20:54 +0000 (23:20 +0800)
committerYingxin Cheng <yingxin.cheng@intel.com>
Tue, 1 Dec 2020 04:50:53 +0000 (12:50 +0800)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
src/crimson/os/seastore/onode_manager/staged-fltree/node.cc
src/crimson/os/seastore/onode_manager/staged-fltree/node.h
src/crimson/os/seastore/onode_manager/staged-fltree/tree.cc

index bb2a850442eedf423771a82026f0e9d639562764..f68bc5174b3d2ee58ef21f1b43e29831f80246c2 100644 (file)
@@ -26,16 +26,19 @@ tree_cursor_t::tree_cursor_t(
     Ref<LeafNode> node, const search_position_t& pos,
     const onode_t* _p_value, layout_version_t v)
       : leaf_node{node}, position{pos} {
-  if (!pos.is_end()) {
-    update_p_value(_p_value, v);
-    leaf_node->do_track_cursor(*this);
-  } else {
-    assert(!_p_value);
-  }
+  assert(!is_end());
+  update_p_value(_p_value, v);
+  leaf_node->do_track_cursor(*this);
+}
+
+tree_cursor_t::tree_cursor_t(Ref<LeafNode> node)
+      : leaf_node{node}, position{search_position_t::end()} {
+  assert(is_end());
+  assert(leaf_node->is_level_tail());
 }
 
 tree_cursor_t::~tree_cursor_t() {
-  if (!position.is_end()) {
+  if (!is_end()) {
     leaf_node->do_untrack_cursor(*this);
   }
 }
@@ -482,6 +485,10 @@ node_future<InternalNode::fresh_node_t> InternalNode::allocate(
 LeafNode::LeafNode(LeafNodeImpl* impl, NodeImplURef&& impl_ref)
   : Node(std::move(impl_ref)), impl{impl} {}
 
+bool LeafNode::is_level_tail() const {
+  return impl->is_level_tail();
+}
+
 std::pair<const onode_t*, layout_version_t> LeafNode::get_p_value(
     const search_position_t& pos) const {
   return {impl->get_p_value(pos), layout_version};
@@ -489,31 +496,27 @@ std::pair<const onode_t*, layout_version_t> LeafNode::get_p_value(
 
 node_future<Ref<tree_cursor_t>>
 LeafNode::lookup_smallest(context_t) {
-  search_position_t pos;
-  const onode_t* p_value;
   if (unlikely(impl->is_empty())) {
     assert(is_root());
-    pos = search_position_t::end();
-    p_value = nullptr;
-  } else {
-    pos = search_position_t::begin();
-    p_value = impl->get_p_value(pos);
+    return node_ertr::make_ready_future<Ref<tree_cursor_t>>(
+        new tree_cursor_t(this));
   }
+  auto pos = search_position_t::begin();
+  auto p_value = impl->get_p_value(pos);
   return node_ertr::make_ready_future<Ref<tree_cursor_t>>(
       get_or_track_cursor(pos, p_value));
 }
 
 node_future<Ref<tree_cursor_t>>
 LeafNode::lookup_largest(context_t) {
-  search_position_t pos;
-  const onode_t* p_value = nullptr;
   if (unlikely(impl->is_empty())) {
     assert(is_root());
-    pos = search_position_t::end();
-  } else {
-    impl->get_largest_value(pos, p_value);
-    assert(p_value != nullptr);
+    return node_ertr::make_ready_future<Ref<tree_cursor_t>>(
+        new tree_cursor_t(this));
   }
+  search_position_t pos;
+  const onode_t* p_value = nullptr;
+  impl->get_largest_value(pos, p_value);
   return node_ertr::make_ready_future<Ref<tree_cursor_t>>(
       get_or_track_cursor(pos, p_value));
 }
@@ -522,9 +525,15 @@ node_future<Node::search_result_t>
 LeafNode::lower_bound_tracked(
     context_t c, const key_hobj_t& key, MatchHistory& history) {
   auto result = impl->lower_bound(key, history);
-  auto cursor_ref = get_or_track_cursor(result.position, result.p_value);
+  Ref<tree_cursor_t> cursor;
+  if (result.position.is_end()) {
+    assert(!result.p_value);
+    cursor = new tree_cursor_t(this);
+  } else {
+    cursor = get_or_track_cursor(result.position, result.p_value);
+  }
   return node_ertr::make_ready_future<search_result_t>(
-      search_result_t{cursor_ref, result.match()});
+      search_result_t{cursor, result.match()});
 }
 
 node_future<> LeafNode::test_clone_root(
@@ -622,13 +631,8 @@ node_future<Ref<LeafNode>> LeafNode::allocate_root(
 
 Ref<tree_cursor_t> LeafNode::get_or_track_cursor(
     const search_position_t& position, const onode_t* p_value) {
-  if (position.is_end()) {
-    assert(impl->is_level_tail());
-    assert(!p_value);
-    // we need to return the leaf node to insert
-    return new tree_cursor_t(this, position, p_value, layout_version);
-  }
-
+  assert(!position.is_end());
+  assert(p_value);
   Ref<tree_cursor_t> p_cursor;
   auto found = tracked_cursors.find(position);
   if (found == tracked_cursors.end()) {
index 0906ff0503aa1e070ed6f4a118d92a38714a3bbd..203b93b3c8bef4a0ce6cf1c9d3b37b5a4ecdd064 100644 (file)
@@ -56,6 +56,8 @@ class tree_cursor_t final
  private:
   tree_cursor_t(Ref<LeafNode>, const search_position_t&,
                 const onode_t*, layout_version_t);
+  // lookup reaches the end, contain leaf node for further insert
+  tree_cursor_t(Ref<LeafNode>);
   const search_position_t& get_position() const { return position; }
   Ref<LeafNode> get_leaf_node() { return leaf_node; }
   void update_track(Ref<LeafNode>, const search_position_t&);
@@ -247,6 +249,7 @@ class LeafNode final : public Node {
   LeafNode& operator=(const LeafNode&) = delete;
   LeafNode& operator=(LeafNode&&) = delete;
 
+  bool is_level_tail() const;
   layout_version_t get_layout_version() const { return layout_version; }
   std::pair<const onode_t*, layout_version_t> get_p_value(
       const search_position_t&) const;
index 80903ca1c7d23b10f0f39ff75137b1b051b74f4b..67b68384621f7f45ea2ef0c58ebe53c4593a4907 100644 (file)
@@ -18,7 +18,7 @@ using Cursor = Btree::Cursor;
 Cursor::Cursor(Btree* p_tree, Ref<tree_cursor_t> _p_cursor)
   : p_tree(p_tree) {
   if (_p_cursor->is_end()) {
-    // for cursors indicating end of tree untrack the leaf node
+    // no need to hold the leaf node
   } else {
     p_cursor = _p_cursor;
   }