From edc3a420fbeb7f46d2dc789dabdcc28b79d31bd1 Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Wed, 9 Apr 2025 11:02:49 +0200 Subject: [PATCH] comment how page count is decreased while balancing --- core/storage/btree.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/storage/btree.rs b/core/storage/btree.rs index befb43189..b843440cc 100644 --- a/core/storage/btree.rs +++ b/core/storage/btree.rs @@ -1657,7 +1657,6 @@ impl BTreeCursor { while new_page_sizes[i] > usable_space as i64 { let needs_new_page = i + 1 >= sibling_count_new; if needs_new_page { - // FIXME: this doesn't remove pages if not needed sibling_count_new += 1; new_page_sizes.push(0); cell_array @@ -1715,16 +1714,24 @@ impl BTreeCursor { new_page_sizes[i + 1] -= size_of_cell_to_remove_from_right; } - let we_still_need_another_page = + // Check if this page contains up to the last cell. If this happens it means we really just need up to this page. + // Let's update the number of new pages to be up to this page (i+1) + let page_completes_all_cells = cell_array.number_of_cells_per_page[i] >= cell_array.cells.len() as u16; - if we_still_need_another_page { + if page_completes_all_cells { sibling_count_new = i + 1; + break; } i += 1; if i >= sibling_count_new { break; } } + new_page_sizes.truncate(sibling_count_new); + cell_array + .number_of_cells_per_page + .truncate(sibling_count_new); + tracing::debug!( "balance_non_root(sibling_count={}, sibling_count_new={}, cells={})", balance_info.sibling_count,