mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-23 01:44:33 +01:00
This PR fixes few issues in turso-sync-engine implementation: 1. One step of `pull` implementation works like this: a. Start write WAL session b. Revert local changes in WAL c. Replay WAL frames from remote DB d. Replay WAL frames produced by local changes applied to the remote DB copy (`synced`) My initial thinking was that by executing step (d) we will get the same schema as before (with same schema cookie) and everything will be fine. With more deep thinking we can see that it's not fine - as after step (d) tables created locally can change their root pages (if they were created locally, for example) - and DB will have "broken" schema 2. Sync engine execute few SQL statements and do not run them to completion - which basically created "orphaned" locks In order to fix (1) I decided to introduce another `conn_raw_api` extension which allows to read and write schema cookie directly in the transaction. So, the process described above adds step (e) which set schema cookie to the value strictly greater than the value before. In order to fix (2) I just fixed all places where statement were dropped before running to completion. These fixes are merged together because I explored them by fixing one new test: `test_sync_single_db_many_pulls_big_payloads` Closes #2561