From 25301266bbb4e365ee07e4c680e0afc9d13a66a9 Mon Sep 17 00:00:00 2001 From: Xuehan Xu Date: Thu, 29 May 2025 10:28:56 +0800 Subject: [PATCH] crimson/os/seastore/omap_manager: add get_balance_pivot_idx to StringKVLeafNodeLayout Signed-off-by: Xuehan Xu --- .../btree/string_kv_node_layout.h | 42 +++++++++++++------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/crimson/os/seastore/omap_manager/btree/string_kv_node_layout.h b/src/crimson/os/seastore/omap_manager/btree/string_kv_node_layout.h index 7e6df63d257ac..9370213ef2a18 100644 --- a/src/crimson/os/seastore/omap_manager/btree/string_kv_node_layout.h +++ b/src/crimson/os/seastore/omap_manager/btree/string_kv_node_layout.h @@ -1380,21 +1380,14 @@ public: set_meta(omap_node_meta_t::merge_from(left.get_meta(), right.get_meta())); } - /** - * balance_into_new_nodes - * - * Takes the contents of left and right and copies them into - * replacement_left and replacement_right such that - * the size of replacement_left side just >= 1/2 of the total size (left + right). - */ - static std::string balance_into_new_nodes( + static std::optional get_balance_pivot_idx( const StringKVLeafNodeLayout &left, - const StringKVLeafNodeLayout &right, - StringKVLeafNodeLayout &replacement_left, - StringKVLeafNodeLayout &replacement_right) + const StringKVLeafNodeLayout &right) { - uint32_t left_size = omap_leaf_key_t(left.get_node_key_ptr()[left.get_size()-1]).key_off; - uint32_t right_size = omap_leaf_key_t(right.get_node_key_ptr()[right.get_size()-1]).key_off; + uint32_t left_size = omap_leaf_key_t( + left.get_node_key_ptr()[left.get_size()-1]).key_off; + uint32_t right_size = omap_leaf_key_t( + right.get_node_key_ptr()[right.get_size()-1]).key_off; uint32_t total = left_size + right_size; uint32_t pivot_size = total / 2; uint32_t pivot_idx = 0; @@ -1420,6 +1413,29 @@ public: } } } + return pivot_idx == left.get_size() + ? std::nullopt + : std::make_optional(pivot_idx); + } + + /** + * balance_into_new_nodes + * + * Takes the contents of left and right and copies them into + * replacement_left and replacement_right such that + * the size of replacement_left side just >= 1/2 of the total size (left + right). + */ + static std::string balance_into_new_nodes( + const StringKVLeafNodeLayout &left, + const StringKVLeafNodeLayout &right, + uint32_t pivot_idx, + StringKVLeafNodeLayout &replacement_left, + StringKVLeafNodeLayout &replacement_right) + { + uint32_t left_size = omap_leaf_key_t(left.get_node_key_ptr()[left.get_size()-1]).key_off; + uint32_t right_size = omap_leaf_key_t(right.get_node_key_ptr()[right.get_size()-1]).key_off; + uint32_t total = left_size + right_size; + uint32_t pivot_size = total / 2; auto replacement_pivot = pivot_idx >= left.get_size() ? right.iter_idx(pivot_idx - left.get_size())->get_key() : -- 2.39.5