From: Yingxin Cheng Date: Wed, 16 Sep 2020 15:20:54 +0000 (+0800) Subject: crimson/onode-staged-tree: cleanup the end tree_cursor_t cstr X-Git-Tag: v16.1.0~359^2~42 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=75080e878d81e4a6604b832ac224513559be7cad;p=ceph.git crimson/onode-staged-tree: cleanup the end tree_cursor_t cstr Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc index bb2a850442ee..f68bc5174b3d 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc @@ -26,16 +26,19 @@ tree_cursor_t::tree_cursor_t( Ref 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 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::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 LeafNode::get_p_value( const search_position_t& pos) const { return {impl->get_p_value(pos), layout_version}; @@ -489,31 +496,27 @@ std::pair LeafNode::get_p_value( node_future> 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>( + 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>( get_or_track_cursor(pos, p_value)); } node_future> 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>( + 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>( get_or_track_cursor(pos, p_value)); } @@ -522,9 +525,15 @@ node_future 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 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{cursor_ref, result.match()}); + search_result_t{cursor, result.match()}); } node_future<> LeafNode::test_clone_root( @@ -622,13 +631,8 @@ node_future> LeafNode::allocate_root( Ref 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 p_cursor; auto found = tracked_cursors.find(position); if (found == tracked_cursors.end()) { diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/node.h b/src/crimson/os/seastore/onode_manager/staged-fltree/node.h index 0906ff0503aa..203b93b3c8be 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/node.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/node.h @@ -56,6 +56,8 @@ class tree_cursor_t final private: tree_cursor_t(Ref, const search_position_t&, const onode_t*, layout_version_t); + // lookup reaches the end, contain leaf node for further insert + tree_cursor_t(Ref); const search_position_t& get_position() const { return position; } Ref get_leaf_node() { return leaf_node; } void update_track(Ref, 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 get_p_value( const search_position_t&) const; diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/tree.cc b/src/crimson/os/seastore/onode_manager/staged-fltree/tree.cc index 80903ca1c7d2..67b68384621f 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/tree.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/tree.cc @@ -18,7 +18,7 @@ using Cursor = Btree::Cursor; Cursor::Cursor(Btree* p_tree, Ref _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; }