mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 04:24:21 +01:00
Merge 'refactor/btree: don't clone WriteState during balancing' from Jussi Saurio
## Beef Removes cloning of `WriteState` in `balance_non_root()` and removes the `Clone` implementation from `WriteState`. Not only is it unnecessary to clone the state, but even having the `Clone` implementation available is a real regression risk in `insert_into_page()` as it will deep clone vectors that we require stable raw pointers to in `fill_cell_payload()` ## Details In removing the cloning of `WriteState` in `balance_non_root()`, this replaces the `next_write_state` logic with a plain loop, which ends up looking like a lot of changes, but it's really not. Main things that were changed: - Loop and mutate state instead of create new state and return - Make `WriteInfo` an `Option` in `WriteState` for ergonomics so it can be `.take()`:n instead of `.clone()`:d - Clone a `Rc<Pager>` in `balance_non_root()` so that we can call `pager.do_allocate_page()` directly instead of `self.allocate_page()` which is just a facade for the pager method, and would violate borrowing rules. - assign `let usable_space = self.usable_space()` at the beginning of the balance loop for similar reasons. - Make the balance debug validation methods static so they don't require a reference to self, for similar reasons Reviewed-by: Nikita Sivukhin (@sivukhin) Reviewed-by: Avinash Sajjanshetty (@avinassh) Closes #2466
This commit is contained in: