Comments (2)
This is a trickier issue than I initially thought. When SQLite returns SQLITE_BUSY
to the application, which it does when the VFS returns SQLITE_BUSY
from xLock()
, the application has to decide how to handle that. It can retry the same statement again, but this will end up in the same blocked state if that statement is part of a multi-statement transaction and the contention is with another multi-statement transaction that is also being stubbornly retried. In this case, all but one of the participants must ROLLBACK
and retry the transaction in its entirety, which allows the remaining participant to complete its transaction.
Ideally we want to return SQLITE_BUSY
to all the participants in the deadlock except one. That is doable because we can identify the connection that has made the most progress toward getting the exclusive lock and return SQLITE_BUSY
to all the others. Now who is responsible for doing the ROLLBACK
and retry part, the library or the application?
SQLite's policy is to have the application keep track of its transactions instead of caching them and doing retry automatically so it makes sense for wa-sqlite to do the same thing. We don't know what other code the application might be running alongside the transaction statements that also would need to be replayed so making the application responsible for rewinding everything seems best for now (maybe in the future there could be an API "transaction" call that takes an idempotent function argument). That does make application development when there is potential concurrency a little bit harder, which is unfortunate.
So what I'm going to do is change the default WebLocks.js to use only exclusive locking, which removes that deadlock possibility. This will remove the need for applications to handle SQLITE_BUSY
at the cost of not allowing concurrent read transactions (they will be executed sequentially). I will add an alternative WebLocksShared.js that is a drop-in replacement that does allow concurrent read transactions for applications that are willing to handle SQLITE_BUSY
.
An implementation note: We can do better than a timeout for WebLocksShared. We just need to distinguish when we can't get a RESERVED lock because someone else already has it versus because someone is just getting a SHARED lock. We can do that by adding another lock and polling it with LockManager.query() - it will really be used as a signal instead of as a lock (it won't block anything).
from wa-sqlite.
Completed as described.
from wa-sqlite.
Related Issues (20)
- Support concurrent access to multiple databases HOT 3
- RuntimeError: memory access out of bounds - IDBBatchAtomicVFS HOT 5
- Racy IDBBatchAtomicVFS behavior when calling methods directly HOT 6
- PRAGMA synchronous=0; causes `database disk image is malformed` for `IDBBatchAtomic` VFS HOT 4
- Replace sqlite with libsql
- Corruption in vlcn fork with FTS5 HOT 8
- IDBBatchAtomicVFS error: `TypeError: Cannot read properties of null (reading 'fileSize')` HOT 4
- Strange error stack trace: both "SQL error" and "journal file not found" HOT 7
- Trigger on multiple tabs HOT 3
- Slow Query Execution for Tables with Diverse Data HOT 1
- Error: database disk image is malformed HOT 10
- Error: no such module: rtree HOT 2
- Feature request: add last_insert_rowid method
- sqlite3.exec throws "RuntimeError: memory access out of bounds" HOT 11
- Yarn install `Packing the package failed exit code 1` HOT 2
- Empty blobs as bind parameters being returned as NULLs HOT 2
- Full text support HOT 2
- Which VFS is the best?
- Call stack size exceeded of wasm asyncify HOT 7
- Example VFS locking can have name collisions across filesystems HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wa-sqlite.