mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-12 20:54:21 +01:00
This PR fixes sync engine bug which leads to the state of db going back in time. The mistake was made in the pull operation which before fetched information about last commited changes to the remote separately. This crates a problem since pull already works with fixed WAL updates received earlier from remote - and this WAL update can be inconsistent with more fresh value of last_change_id fetched from remote. The fix is to use only WAL update and "extract" necessary information from it. In order to do that sync now read meta sync table while pull operation is in progress (at the moment when local changes are rolled back and remote changes already applied) and do not use any external source to consume that information. Also, this PR fixes bug in the JS tursodatabase client and reset statement in the finally block opposed to the previous approach to reset statement at the beginning. The problem with previous approach were in cases when client do not fully consumed the statement (e.g. abort iteration and take only one row) in which case the statement will be kept active and can prevent another write transaction from starting or just occupy place as a read transaction. Closes #3860