SQLite Forum

Are the changes done after a transaction is performed always available to all connections to a database?
Login
Hi all,

in my application, I have multiple connections/thread to a database (I'm on linux, database stored on xfs and ext4) I'm using WAL.

Each thread "owns" one connection. There's one writer thread, which is the only one which writes in the database, doing transactions with usually hundreds of inserts/updates/deletes each.

All the other threads which access the database are read-only connections (mode=ro, and only allowed to perform query calls) with private cache each.

Every time the writer thread successfully commits a transaction, it notifies the reader threads about the updated data and the readers immediately read it after receiving such notification. 

I noticed that, when I have only one reader thread/connection, this schema works as expected and the reader thread can always see the updated database (even performing thousands of reads per second). But, when I increase the number of readers, they sometimes appear to see an old version of the database, before the transaction.

I've been relying in the fact that after a transaction is persisted, all connections will "see" the same database, but I confess I don't know if I understood sqlite well or if such guarantee actually exists.

It might also be a bug in my application as well, so before I spend more time debugging it, I'd like to know if sqlite offers such guarantee and, if, not, if you have any advice on how to proceed to achieve such results.

More technical details:

- The application itself is written in Go (and it's open source, at https://gitlab.com/lightmeter/controlcenter/ :-)).
- The writer thread notifies the reader threads via Go channels, and the readers are organized in a "thread pool", where the thread which will handle the "results" of a transaction chosen arbitrarily by reading the same channel.
- Im'm using go-sqlite3 (wrapping sqlite 3.34.0).

Thank you folks in advance for such amazing piece of software :-)