mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-25 12:04:21 +01:00
**Handle table ID / rootpages properly for both checkpointed and non- checkpointed tables** Table ID is an opaque identifier that is only meaningful to the MV store. Each checkpointed MVCC table corresponds to a single B-tree on the pager, which naturally has a root page. **We cannot use root page as the MVCC table ID directly because:** - We assign table IDs during MVCC commit, but - we commit pages to the pager only during checkpoint which means the root page is not easily knowable ahead of time. **Hence:** - MVCC table ids are always negative - sqlite_schema rows will have a negative rootpage column if the table has not been checkpointed yet. - on checkpoint when the table is allocated a real root page, we update the row in sqlite_schema and in MV store's internal mapping **On recovery:** - All sqlite_schema tables are read directly from disk and assigned `table_id = -1 * root_page` -- root_page on disk must be positive - Logical log is deserialized and inserted into MV store - Schema changes from logical_log are captured into the DB's global schema **Note about recovery:** I changed MVCC recovery to happen on DB initialization which should prevent any races, so no need for `recover_lock`, right @pereman2 ? Closes #3419