1414#include " crimson/os/seastore/seastore_types.h"
1515#include " crimson/os/seastore/btree/btree_range_pin.h"
1616#include " crimson/os/seastore/root_block.h"
17+ #include " crimson/os/seastore/linked_tree_node.h"
1718
1819namespace crimson ::os::seastore::lba_manager::btree {
1920struct lba_map_val_t ;
2021}
2122
2223namespace crimson ::os::seastore {
2324
24- bool is_valid_child_ptr (ChildableCachedExtent* child);
25-
26- bool is_reserved_ptr (ChildableCachedExtent* child);
27-
28- inline ChildableCachedExtent* get_reserved_ptr () {
29- return (ChildableCachedExtent*)0x1 ;
30- }
31-
3225template <typename T>
3326phy_tree_root_t & get_phy_tree_root (root_t & r);
3427
@@ -40,12 +33,6 @@ const get_phy_tree_root_node_ret get_phy_tree_root_node(
4033 const RootBlockRef &root_block,
4134 op_context_t <key_t > c);
4235
43- template <typename ROOT_T>
44- void link_phy_tree_root_node (RootBlockRef &root_block, ROOT_T* root_node);
45-
46- template <typename T>
47- void unlink_phy_tree_root_node (RootBlockRef &root_block);
48-
4936template <typename T>
5037Transaction::tree_stats_t & get_tree_stats (Transaction &t);
5138
@@ -351,7 +338,7 @@ class FixedKVBtree {
351338 template <typename T>
352339 void set_root_node (const TCachedExtentRef<T> &root_node) {
353340 static_assert (std::is_base_of_v<typename internal_node_t ::base_t , T>);
354- link_phy_tree_root_node (root_block, root_node.get ());
341+ TreeRootLinker<RootBlock, T>:: link_root (root_block, root_node.get ());
355342 }
356343
357344 auto get_root_node (op_context_t <node_key_t > c) const {
@@ -373,7 +360,7 @@ class FixedKVBtree {
373360 root_leaf->range = meta;
374361 get_tree_stats<self_type>(c.trans ).depth = 1u ;
375362 get_tree_stats<self_type>(c.trans ).extents_num_delta ++;
376- link_phy_tree_root_node (root_block, root_leaf.get ());
363+ TreeRootLinker<RootBlock, leaf_node_t >:: link_root (root_block, root_leaf.get ());
377364 return phy_tree_root_t {root_leaf->get_paddr (), 1u };
378365 }
379366
@@ -495,6 +482,7 @@ class FixedKVBtree {
495482 return upper_bound (c, min_max_t <node_key_t >::max);
496483 }
497484
485+ #ifdef UNIT_TESTS_BUILT
498486 template <typename child_node_t , typename node_t , bool lhc = leaf_has_children,
499487 typename std::enable_if<lhc, int >::type = 0 >
500488 void check_node (
@@ -532,8 +520,8 @@ class FixedKVBtree {
532520 if (node->is_pending ()) {
533521 auto &n = node->get_stable_for_key (i->get_key ());
534522 assert (cnode->get_parent_node ().get () == &n);
535- auto pos = n.lower_bound_offset (i->get_key ());
536- assert (pos < n.get_node_size ());
523+ auto pos = n.lower_bound (i->get_key ()). get_offset ( );
524+ assert (pos < n.get_size ());
537525 assert (n.children [pos] == cnode.get ());
538526 } else {
539527 assert (cnode->get_parent_node ().get () == node.get ());
@@ -547,8 +535,8 @@ class FixedKVBtree {
547535 if (node->is_mutation_pending ()) {
548536 auto &n = node->get_stable_for_key (i->get_key ());
549537 assert (prior.get_parent_node ().get () == &n);
550- auto pos = n.lower_bound_offset (i->get_key ());
551- assert (pos < n.get_node_size ());
538+ auto pos = n.lower_bound (i->get_key ()). get_offset ( );
539+ assert (pos < n.get_size ());
552540 assert (n.children [pos] == &prior);
553541 } else {
554542 assert (prior.get_parent_node ().get () == node.get ());
@@ -567,11 +555,12 @@ class FixedKVBtree {
567555 ceph_abort (" impossible" );
568556 }
569557 } else if (ret == Transaction::get_extent_ret::ABSENT) {
570- ChildableCachedExtent* child = nullptr ;
558+ BaseChildNode<std::remove_reference_t <decltype (*node)>,
559+ node_key_t >* child = nullptr ;
571560 if (node->is_pending ()) {
572561 auto &n = node->get_stable_for_key (i->get_key ());
573- auto pos = n.lower_bound_offset (i->get_key ());
574- assert (pos < n.get_node_size ());
562+ auto pos = n.lower_bound (i->get_key ()). get_offset ( );
563+ assert (pos < n.get_size ());
575564 child = n.children [pos];
576565 } else {
577566 child = node->children [i->get_offset ()];
@@ -601,7 +590,7 @@ class FixedKVBtree {
601590 }
602591 }
603592 } else {
604- auto c = ( child_node_t *) child;
593+ auto c = static_cast < child_node_t *>( child) ;
605594 assert (c->has_parent_tracker ());
606595 assert (c->get_parent_node ().get () == node.get ()
607596 || (node->is_pending () && c->is_stable ()
@@ -634,12 +623,16 @@ class FixedKVBtree {
634623 if (depth > 1 ) {
635624 auto &node = iter.get_internal (depth).node ;
636625 assert (node->is_valid ());
637- check_node<typename internal_node_t ::base_t >(c, node);
626+ if (depth > 2 ) {
627+ check_node<internal_node_t >(c, node);
628+ } else {
629+ check_node<leaf_node_t >(c, node);
630+ }
638631 } else {
639632 assert (depth == 1 );
640633 auto &node = iter.leaf .node ;
641634 assert (node->is_valid ());
642- check_node<LogicalCachedExtent >(c, node);
635+ check_node<typename leaf_node_t :: base_child_node_t >(c, node);
643636 }
644637 return seastar::now ();
645638 };
@@ -666,6 +659,7 @@ class FixedKVBtree {
666659 &checker);
667660 });
668661 }
662+ #endif
669663
670664 using iterate_repeat_ret_inner = base_iertr::future<
671665 seastar::stop_iteration>;
@@ -730,7 +724,7 @@ class FixedKVBtree {
730724 iterator iter,
731725 node_key_t laddr,
732726 node_val_t val,
733- LogicalCachedExtent * nextent
727+ leaf_node_t :: base_child_node_t * nextent
734728 ) {
735729 LOG_PREFIX (FixedKVBtree::insert);
736730 SUBTRACET (
@@ -780,7 +774,7 @@ class FixedKVBtree {
780774 op_context_t <node_key_t > c,
781775 node_key_t laddr,
782776 node_val_t val,
783- LogicalCachedExtent * nextent) {
777+ leaf_node_t :: base_child_node_t * nextent) {
784778 return lower_bound (
785779 c, laddr
786780 ).si_then ([this , c, laddr, val, nextent](auto iter) {
@@ -804,7 +798,7 @@ class FixedKVBtree {
804798 op_context_t <node_key_t > c,
805799 iterator iter,
806800 node_val_t val,
807- LogicalCachedExtent * nextent)
801+ leaf_node_t :: base_child_node_t * nextent)
808802 {
809803 LOG_PREFIX (FixedKVBtree::update);
810804 SUBTRACET (
@@ -1082,13 +1076,15 @@ class FixedKVBtree {
10821076
10831077 using update_internal_mapping_iertr = base_iertr;
10841078 using update_internal_mapping_ret = update_internal_mapping_iertr::future<>;
1079+ template <typename T>
1080+ requires std::is_same_v<internal_node_t , T> || std::is_same_v<leaf_node_t , T>
10851081 update_internal_mapping_ret update_internal_mapping (
10861082 op_context_t <node_key_t > c,
10871083 depth_t depth,
10881084 node_key_t laddr,
10891085 paddr_t old_addr,
10901086 paddr_t new_addr,
1091- typename internal_node_t ::base_ref nextent)
1087+ TCachedExtentRef<T> nextent)
10921088 {
10931089 LOG_PREFIX (FixedKVBtree::update_internal_mapping);
10941090 SUBTRACET (
@@ -1226,6 +1222,7 @@ class FixedKVBtree {
12261222 auto init_internal = [c, depth, begin, end,
12271223 parent_pos=std::move (parent_pos)]
12281224 (internal_node_t &node) {
1225+ using tree_root_linker_t = TreeRootLinker<RootBlock, internal_node_t >;
12291226 assert (!node.is_pending ());
12301227 assert (!node.is_linked ());
12311228 node.range = fixed_kv_node_meta_t <node_key_t >{begin, end, depth};
@@ -1237,10 +1234,10 @@ class FixedKVBtree {
12371234 auto root_block = c.cache .get_root_fast (c.trans );
12381235 if (root_block->is_mutation_pending ()) {
12391236 auto &stable_root = (RootBlockRef&)*root_block->get_prior_instance ();
1240- link_phy_tree_root_node (stable_root, &node);
1237+ tree_root_linker_t::link_root (stable_root, &node);
12411238 } else {
12421239 assert (!root_block->is_pending ());
1243- link_phy_tree_root_node (root_block, &node);
1240+ tree_root_linker_t::link_root (root_block, &node);
12441241 }
12451242 }
12461243 };
@@ -1311,6 +1308,7 @@ class FixedKVBtree {
13111308 auto init_leaf = [c, begin, end,
13121309 parent_pos=std::move (parent_pos)]
13131310 (leaf_node_t &node) {
1311+ using tree_root_linker_t = TreeRootLinker<RootBlock, leaf_node_t >;
13141312 assert (!node.is_pending ());
13151313 assert (!node.is_linked ());
13161314 node.range = fixed_kv_node_meta_t <node_key_t >{begin, end, 1 };
@@ -1322,10 +1320,10 @@ class FixedKVBtree {
13221320 auto root_block = c.cache .get_root_fast (c.trans );
13231321 if (root_block->is_mutation_pending ()) {
13241322 auto &stable_root = (RootBlockRef&)*root_block->get_prior_instance ();
1325- link_phy_tree_root_node (stable_root, &node);
1323+ tree_root_linker_t::link_root (stable_root, &node);
13261324 } else {
13271325 assert (!root_block->is_pending ());
1328- link_phy_tree_root_node (root_block, &node);
1326+ tree_root_linker_t::link_root (root_block, &node);
13291327 }
13301328 }
13311329 };
@@ -1493,7 +1491,8 @@ class FixedKVBtree {
14931491 return seastar::now ();
14941492 };
14951493
1496- auto v = parent->template get_child <internal_node_t >(c, node_iter);
1494+ auto v = parent->template get_child <internal_node_t >(
1495+ c.trans , c.cache , node_iter.get_offset (), node_iter.get_key ());
14971496 // checking the lba child must be atomic with creating
14981497 // and linking the absent child
14991498 if (v.has_child ()) {
@@ -1527,7 +1526,7 @@ class FixedKVBtree {
15271526 begin,
15281527 end,
15291528 std::make_optional<node_position_t <internal_node_t >>(
1530- child_pos.template get_parent < internal_node_t > (),
1529+ child_pos.get_parent (),
15311530 child_pos.get_pos ())
15321531 ).si_then ([on_found=std::move (on_found)](InternalNodeRef node) {
15331532 return on_found (node);
@@ -1563,7 +1562,8 @@ class FixedKVBtree {
15631562 return seastar::now ();
15641563 };
15651564
1566- auto v = parent->template get_child <leaf_node_t >(c, node_iter);
1565+ auto v = parent->template get_child <leaf_node_t >(
1566+ c.trans , c.cache , node_iter.get_offset (), node_iter.get_key ());
15671567 // checking the lba child must be atomic with creating
15681568 // and linking the absent child
15691569 if (v.has_child ()) {
@@ -1597,7 +1597,7 @@ class FixedKVBtree {
15971597 begin,
15981598 end,
15991599 std::make_optional<node_position_t <internal_node_t >>(
1600- child_pos.template get_parent < internal_node_t > (),
1600+ child_pos.get_parent (),
16011601 child_pos.get_pos ())
16021602 ).si_then ([on_found=std::move (on_found)](LeafNodeRef node) {
16031603 return on_found (node);
@@ -2118,7 +2118,8 @@ class FixedKVBtree {
21182118 return seastar::now ();
21192119 };
21202120
2121- auto v = parent_pos.node ->template get_child <NodeType>(c, donor_iter);
2121+ auto v = parent_pos.node ->template get_child <NodeType>(
2122+ c.trans , c.cache , donor_iter.get_offset (), donor_iter.get_key ());
21222123 // checking the lba child must be atomic with creating
21232124 // and linking the absent child
21242125 if (v.has_child ()) {
@@ -2150,7 +2151,7 @@ class FixedKVBtree {
21502151 begin,
21512152 end,
21522153 std::make_optional<node_position_t <internal_node_t >>(
2153- child_pos.template get_parent < internal_node_t > (),
2154+ child_pos.get_parent (),
21542155 child_pos.get_pos ())
21552156 ).si_then ([do_merge=std::move (do_merge)](typename NodeType::Ref donor) {
21562157 return do_merge (donor);
0 commit comments