mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
Switch to DEFERRED transactions
We do not make all transactions [IMMEDIATE](https://www.sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions) for more parallelism -- at least read transactions can be made DEFERRED to run in parallel w/o any drawbacks. But if we make write transactions DEFERRED also w/o any external locking, then they are upgraded from read to write ones on the first write statement. This has some drawbacks: - If there are other write transactions, we block the thread and the db connection until upgraded. Also if some reader comes then, it has to get next, less used connection with a worse per-connection page cache. - If a transaction is blocked for more than busy_timeout, it fails with SQLITE_BUSY. - Configuring busy_timeout is not the best way to manage transaction timeouts, we would prefer it to be integrated with Rust/tokio asyncs. Moreover, SQLite implements waiting using sleeps. - If upon a successful upgrade to a write transaction the db has been modified by another one, the transaction has to be rolled back and retried. It is an extra work in terms of CPU/battery. - Maybe minor, but we lose some fairness in servicing write transactions, i.e. we service them in the order of the first write statement, not in the order they come. The only pro of making write transactions DEFERRED w/o the external locking is some parallelism between them. Also we have an option to make write transactions IMMEDIATE, also w/o the external locking. But then the most of cons above are still valid. Instead, if we perform all write transactions under an async mutex, the only cons is losing some parallelism for write transactions.
This commit is contained in:
@@ -431,6 +431,7 @@ impl Context {
|
||||
async fn pop_smtp_status_update(
|
||||
&self,
|
||||
) -> Result<Option<(MsgId, StatusUpdateSerial, StatusUpdateSerial, String)>> {
|
||||
let _lock = self.sql.write_lock().await;
|
||||
let res = self
|
||||
.sql
|
||||
.query_row_optional(
|
||||
|
||||
Reference in New Issue
Block a user