mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 05:24:22 +01:00
## Problem: Currently `WriteState`, usually triggered by an insert operation, "owns" the balancing state machine, even though a delete operation (tracked by a separate `DeleteState`) can also trigger balancing, which results in awkward back-and-forth switching between `CursorState::Write` and `CursorState::Delete` during balancing. ## Fix: 1. Extract `balance_state` as a separate state machine, since its state transitions are exactly the same regardless of whether an insert or a delete triggered the balancing. 2. This allows to remove the different 'Balance-xxx' variants from `WriteState`, as well as removing `WriteInfo` and `DeleteInfo`, as the delete&insert states become just simple enums now. Each of them now has a substate called `Balancing` which just delegates work to the balancing state machine. 3. This further allows us to remove the awkward switching between `CursorState::Delete` and `CursorState::Write` during a balance that happens as a result of a deletion. Reviewed-by: Nikita Sivukhin (@sivukhin) Reviewed-by: Avinash Sajjanshetty (@avinassh) Closes #2468