Skip to content

Commit 2530126

Browse files
committed
crimson/os/seastore/omap_manager: add get_balance_pivot_idx to
StringKVLeafNodeLayout Signed-off-by: Xuehan Xu <[email protected]>
1 parent 33947d5 commit 2530126

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

src/crimson/os/seastore/omap_manager/btree/string_kv_node_layout.h

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,21 +1380,14 @@ class StringKVLeafNodeLayout {
13801380
set_meta(omap_node_meta_t::merge_from(left.get_meta(), right.get_meta()));
13811381
}
13821382

1383-
/**
1384-
* balance_into_new_nodes
1385-
*
1386-
* Takes the contents of left and right and copies them into
1387-
* replacement_left and replacement_right such that
1388-
* the size of replacement_left side just >= 1/2 of the total size (left + right).
1389-
*/
1390-
static std::string balance_into_new_nodes(
1383+
static std::optional<uint32_t> get_balance_pivot_idx(
13911384
const StringKVLeafNodeLayout &left,
1392-
const StringKVLeafNodeLayout &right,
1393-
StringKVLeafNodeLayout &replacement_left,
1394-
StringKVLeafNodeLayout &replacement_right)
1385+
const StringKVLeafNodeLayout &right)
13951386
{
1396-
uint32_t left_size = omap_leaf_key_t(left.get_node_key_ptr()[left.get_size()-1]).key_off;
1397-
uint32_t right_size = omap_leaf_key_t(right.get_node_key_ptr()[right.get_size()-1]).key_off;
1387+
uint32_t left_size = omap_leaf_key_t(
1388+
left.get_node_key_ptr()[left.get_size()-1]).key_off;
1389+
uint32_t right_size = omap_leaf_key_t(
1390+
right.get_node_key_ptr()[right.get_size()-1]).key_off;
13981391
uint32_t total = left_size + right_size;
13991392
uint32_t pivot_size = total / 2;
14001393
uint32_t pivot_idx = 0;
@@ -1420,6 +1413,29 @@ class StringKVLeafNodeLayout {
14201413
}
14211414
}
14221415
}
1416+
return pivot_idx == left.get_size()
1417+
? std::nullopt
1418+
: std::make_optional<uint32_t>(pivot_idx);
1419+
}
1420+
1421+
/**
1422+
* balance_into_new_nodes
1423+
*
1424+
* Takes the contents of left and right and copies them into
1425+
* replacement_left and replacement_right such that
1426+
* the size of replacement_left side just >= 1/2 of the total size (left + right).
1427+
*/
1428+
static std::string balance_into_new_nodes(
1429+
const StringKVLeafNodeLayout &left,
1430+
const StringKVLeafNodeLayout &right,
1431+
uint32_t pivot_idx,
1432+
StringKVLeafNodeLayout &replacement_left,
1433+
StringKVLeafNodeLayout &replacement_right)
1434+
{
1435+
uint32_t left_size = omap_leaf_key_t(left.get_node_key_ptr()[left.get_size()-1]).key_off;
1436+
uint32_t right_size = omap_leaf_key_t(right.get_node_key_ptr()[right.get_size()-1]).key_off;
1437+
uint32_t total = left_size + right_size;
1438+
uint32_t pivot_size = total / 2;
14231439

14241440
auto replacement_pivot = pivot_idx >= left.get_size() ?
14251441
right.iter_idx(pivot_idx - left.get_size())->get_key() :

0 commit comments

Comments
 (0)