From: Yingxin Cheng Date: Thu, 24 Jun 2021 07:50:18 +0000 (+0800) Subject: crimson/onode-staged-tree: reset root node after lookup X-Git-Tag: v17.1.0~1564^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d2454022f0d3254923074cc8d1d987c29a8e83a3;p=ceph-ci.git crimson/onode-staged-tree: reset root node after lookup Otherwise there could be unexpected references that will break the asserts when remove nodes during insert/delete. 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 6d75d58dfff..16cb1b7e214 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/node.cc @@ -311,12 +311,19 @@ eagain_future Node::lower_bound( } eagain_future, bool>> Node::insert( - context_t c, const key_hobj_t& key, value_config_t vconf) + context_t c, + const key_hobj_t& key, + value_config_t vconf, + Ref&& this_ref) { return seastar::do_with( - MatchHistory(), [this, c, &key, vconf](auto& history) { + MatchHistory(), [this, c, &key, vconf, + this_ref = std::move(this_ref)] (auto& history) mutable { return lower_bound_tracked(c, key, history - ).safe_then([c, &key, vconf, &history](auto result) { + ).safe_then([c, &key, vconf, &history, + this_ref = std::move(this_ref)] (auto result) mutable { + // the cursor in the result should already hold the root node upwards + this_ref.reset(); if (result.match() == MatchKindBS::EQ) { return eagain_ertr::make_ready_future, bool>>( std::make_pair(result.p_cursor, false)); @@ -335,9 +342,14 @@ eagain_future, bool>> Node::insert( } eagain_future Node::erase( - context_t c, const key_hobj_t& key) + context_t c, + const key_hobj_t& key, + Ref&& this_ref) { - return lower_bound(c, key).safe_then([c] (auto result) { + return lower_bound(c, key + ).safe_then([c, this_ref = std::move(this_ref)] (auto result) mutable { + // the cursor in the result should already hold the root node upwards + this_ref.reset(); if (result.match() != MatchKindBS::EQ) { return eagain_ertr::make_ready_future(0); } 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 bfa27cf2560..6434c3fc90b 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/node.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/node.h @@ -336,7 +336,7 @@ class Node * - If false, the returned cursor points to the conflicting element in tree; */ eagain_future, bool>> insert( - context_t, const key_hobj_t&, value_config_t); + context_t, const key_hobj_t&, value_config_t, Ref&&); /** * erase @@ -345,7 +345,7 @@ class Node * * Returns the number of erased key-value pairs (0 or 1). */ - eagain_future erase(context_t, const key_hobj_t&); + eagain_future erase(context_t, const key_hobj_t&, Ref&&); /// Recursively collects the statistics of the sub-tree formed by this node eagain_future get_tree_stats(context_t); diff --git a/src/crimson/os/seastore/onode_manager/staged-fltree/tree.h b/src/crimson/os/seastore/onode_manager/staged-fltree/tree.h index c1568461d4b..b75425935cd 100644 --- a/src/crimson/os/seastore/onode_manager/staged-fltree/tree.h +++ b/src/crimson/os/seastore/onode_manager/staged-fltree/tree.h @@ -268,7 +268,7 @@ class Btree { [this, &t, vconf](auto& key) -> eagain_future> { ceph_assert(key.is_valid()); return get_root(t).safe_then([this, &t, &key, vconf](auto root) { - return root->insert(get_context(t), key, vconf); + return root->insert(get_context(t), key, vconf, std::move(root)); }).safe_then([this](auto ret) { auto& [cursor, success] = ret; return std::make_pair(Cursor(this, cursor), success); @@ -282,7 +282,7 @@ class Btree { full_key_t(obj), [this, &t](auto& key) -> eagain_future { return get_root(t).safe_then([this, &t, &key](auto root) { - return root->erase(get_context(t), key); + return root->erase(get_context(t), key, std::move(root)); }); } );