Clarification on what read concurrency + write serialization means in implementation? #142
-
I'm using IDBBatchAtomicVFS with the Shared Web Locks modification as described in the FAQ and documentation. However, I'm still a bit confused on what that means in practice. For example, the sqlite-api.js seems to enforce certain access patterns that confused me about how to write a SQL transaction correctly. In order to create an async write transaction I need:
The primary mechanism for accomplishing (2) seems to be the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
No, you don't need to do this at the application level if you are using a VFS that support multiple connections, like IDBBatchAtomicVFS.
Yes, any database connection that needs a lock to proceed will automatically try to acquire the necessary WebLocks. If it cannot my locking implementation will either suspend the caller until the lock is available or return SQLITE_BUSY. If it returns SQLITE_BUSY (which happens only with shared locks) then a deadlock has occurred and you must ROLLBACK your transaction and resubmit it to break the deadlock. |
Beta Was this translation helpful? Give feedback.
Ah, I can see how this could be confusing. The underlying SQLite C library API returns integer result codes from almost every function, but my JavaScript wrapper API throws an exception for most codes that are not SQLITE_OK, including SQLITE_BUSY. This is an opinionated policy to prevent lazy developers (e.g. me) from ignoring the return codes. The original code is available as the property "code" on the exception object.
You should handle this in a try/catch block or rejected Promise handler. So something like: