Hi!
I'm trying to use sqlx with an SqlitePool as a caching backend for an actix web application.
Several worker threads compute data, which can take a long time to produce and then store it into a table.
When this data is requested, the worker thread first queries the database before computing, to see if the result already has been computed, to save time. If the data isn't in the database, we recompute it and store it in the DB before sending it out.
The DB layout is basically just one table cache with key TEXT, data BLOB and I just use normal SELECT data from CACHE where key = ? prepared statements to retrieve and normal inserts to put the data into the DB.
I had hoped that the pool feature would just make my multithreading worries go away, but sadly I still got error 262 database table is locked.
Reading up a bit online I found documentation that usually enabling WAL should make the problem go away (it's already enabled) or that multithreading could cause it, which I thought unlikely, since that's sort of what a connection pool is for.
Anyhow, I wrapped the Pool in a Mutex and tried using that and the error still occured.
Any ideas what I am doing wrong? Do I need to use transactions for this?
Hi!
I'm trying to use sqlx with an SqlitePool as a caching backend for an actix web application.
Several worker threads compute data, which can take a long time to produce and then store it into a table.
When this data is requested, the worker thread first queries the database before computing, to see if the result already has been computed, to save time. If the data isn't in the database, we recompute it and store it in the DB before sending it out.
The DB layout is basically just one table cache with
key TEXT, data BLOBand I just use normalSELECT data from CACHE where key = ?prepared statements to retrieve and normal inserts to put the data into the DB.I had hoped that the pool feature would just make my multithreading worries go away, but sadly I still got error 262 database table is locked.
Reading up a bit online I found documentation that usually enabling WAL should make the problem go away (it's already enabled) or that multithreading could cause it, which I thought unlikely, since that's sort of what a connection pool is for.
Anyhow, I wrapped the Pool in a Mutex and tried using that and the error still occured.
Any ideas what I am doing wrong? Do I need to use transactions for this?