Transaction isolation #48
-
I'm porting my code from AbsurdSQL leveraging full transaction isolation (because it's sync) and I'm not sure how transaction isolation works in wa-sqlite IDB. What if I need to select a row, update it, and then save it without some other thread changing it meanwhile. What I need is a lock on a specific row. Do I need Web Locks? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
SQLite calls the database VFS xLock/xUnlock methods at the beginning and end of each transaction (assuming you don't change the default locking mode), so it's up to you (you being the VFS author) to implement the locking mechanism. All the example IndexedDB classes use Web Locks for locking, which provides safe shared locking for read-only transactions and exclusive locking for read-write transactions. As long as (1) your browser supports Web Locks (quite recent for Safari, and I found a bug that they fixed but hasn't reached production yet) and (2) your critical SQL is within a transaction, isolation is satisfied. Web Locks is the easiest (by far) way to implement locking, but not the only way. You can also do it with a service worker) if you have to. Be aware that because the SQLite locking model only upgrades locks when it has to, it can deadlock in certain cases. On a different topic, you posted and then deleted a message about having trouble with the benchmarks page. I assume you deleted it because you resolved the issue but I'm curious what it was. |
Beta Was this translation helpful? Give feedback.
SQLite calls the database VFS xLock/xUnlock methods at the beginning and end of each transaction (assuming you don't change the default locking mode), so it's up to you (you being the VFS author) to implement the locking mechanism. All the example IndexedDB classes use Web Locks for locking, which provides safe shared locking for read-only transactions and exclusive locking for read-write transactions. As long as (1) your browser supports Web Locks (quite recent for Safari, and I found a bug that they fixed but hasn't reached production yet) and (2) your critical SQL is within a transaction, isolation is satisfied.
Web Locks is the easiest (by far) way to implement locking, but not the on…