mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-06 01:34:21 +01:00
Problems: 1. fill_cell_payload() is not re-entrant because it can yield IO on allocating a new overflow page, resulting in losing some of the input data. 2. fill_cell_payload() in its current form is not safe for cache spilling because the previous overflow page in the chain of allocated overflow pages can be evicted by a spill caused by the next overflow page allocation, invalidating the page pointer and causing corruption. 3. fill_cell_payload() uses raw pointers and `unsafe` as a workaround from a previous time when we used to clone `WriteState`, resulting in hard-to-read code. Solutions: 1. Introduce a new substate to the fill_cell_payload state machine to handle re-entrancy wrt. allocating overflow pages. 2. Always pin the current overflow page so that it cannot be evicted during the overflow chain construction. Also pin the regular page the overflow chain is attached to, because it is immediately accessed after fill_cell_payload is done. 3. Remove all explicit usages of `unsafe` from `fill_cell_payload` (although our pager is ofc still extremely unsafe under the hood :] ) Note that solution 2 addresses a problem that arose in the development of page cache spilling, which is not yet implemented, but will be soon. Miscellania: 1. Renamed a bunch of variables to be clearer 2. Added more comments about what is happening in fill_cell_payload