Replies: 3 comments 24 replies
-
I'm quite satisfied to get issue number 69, nice! 😄 Sorry, did you intend to mark this discussion "Closed as resolved"? |
Beta Was this translation helpful? Give feedback.
-
That's a great question, with a long answer. The simplest answer to your question is: yes, kinda. It could certainly help; but with its own set of caveats. I explicitly mention WAL in the README because it's considered best practice to use it, and as such, I'd really like to support it, to as full an extent as possible. As the README states, I created a from scratch VFS which has a bunch of advantages and compromises. So, in the current architecture, each SQLite connection lives in its own little sandbox, completely isolated from other connections. Through the VFS layer, Go acts like an OS kernel, managing these OS “processes.” There are no threads, no locks, no shared cache, etc. It's a good model. Unfortunately, SQLite expects to be able to share memory between these “processes” for the WAL index (just a few pages) which we can't do. With WASM shared memory another model is possible. We create a big (4GB) shared memory, and we run all our SQLite connections on it. But, if we want to have any concurrency, we need threads, locks, etc. At the time of this writing, this is possible to compile with wasi-sdk, and to run with wazero; go-re2 uses this model. But… it's complicated. The ABI to setup threads is far from obvious or stable. wazero APIs, are likewise, experimental. Moving to this model would for sure involve API redesign for this package. And support for platforms other than 64-bit Linux/Windows/macOS is dubious at best. Finally, this still won't allow our SQLite connections to share memory with SQLite connections from other processes, like Litestream. It's also an open question how to lock the database to ensure other processes couldn't access it while we have multiple connections open (it's a change to the locking protocol that needs a design). I've also considered other options. I could create a VFS where each connection thinks it's in memory journal mode, but then I send transactions to the WAL. Or I could look into the libSQL virtual WAL. All solutions are more work than I want to take in at the moment, and ultimately, maintain. |
Beta Was this translation helpful? Give feedback.
-
This is being worked on #71. |
Beta Was this translation helpful? Give feedback.
-
As of two months ago, wazero has symbols that mention shared memory. Could this be used to lift some of the caveats mentioned in the readme such as allowing locking mode
NORMAL
and connection pooling?Beta Was this translation helpful? Give feedback.
All reactions