Quite a long time ago I wrap all my transactions on multitread app (php scripts) that use the same sqlite database into BEGIN IMMEDIATE TRANSACTION. I remember, I read somewhere at SO that: need to wrap all transactions withBEGIN IMMEDIATEon multithread environment to avoidSQLITE_BUSY` state.
Now, I'm thinking about some optimization.
The Sqlite documentation said: After a BEGIN IMMEDIATE, no other database connection will be able to write to the database or do a BEGIN IMMEDIATE. Other processes can continue to read from the database, however.
So, maybe it's safe (or any pitfalls) to only wrap WRITE transactions with IMMEDIATE? And live READ transactions with the default "BEGIN TRANSACTION"? Or maybe to inspect my code and only avoid places where BEGIN IMMEDIATE starts, then goes WRITE, then READ, then WRITE etc. and to rewrite this circles like:
BEGIN IMMEDIATE
ALL READS
then
ALL WRITES
END
If I'm not mistaken in the latter case SQLite will lock whole database only when WRITE begin, not when BEGIN IMMEDIATE stars? And other threads will be able to read and start there BEGIN IMMEDIATE statements?
Aucun commentaire:
Enregistrer un commentaire