3 ms·
> Therefore, the modifications from a transaction will be applied in place in these pages. With mvsqlite it is applied to the transaction's own snapshot of the
by losfair 4y ago
> Therefore, the modifications from a transaction will be applied in place in these pages.
With mvsqlite it is applied to the transaction's own snapshot of the database. Changes are not visible globally until transaction commit. That's what we get from page-level MVCC.
> More over, without WAL, SQLite to the best of my knowledge would require read-lock on every read as well
Reads are also MVCC. Data is fetched from a consistent and clean snapshot of the database, without uncommitted data.
- rockwotj 4y agoThis approach provides SERIALIZABLE transaction isolation right? What happen if there are page conflicts during the write? The transaction fails and you retry? Does SQLite have a good way of of signalling that this is the case (vs for example a network failure or other write failures).
- losfair 4y agoYes it's the serializable isolation level. For applications targeting upstream SQLite, mvsqlite enables pessimistic locking by default - when a transaction is promoted to EXCLUSIVE, it acquires a one-minute lock lease from mvstore. At this point we have the chance to fail gracefully and return a "database is locked" error if multiple clients want to acquire lock on the same DB. This is a best-effort mechanism to prevent conflict on commit (which causes the process to abort). A future feature is "MVCC-aware clients". Compatible clients can opt-in to full, optimistic MVCC, and avoid pessimistic locking. After `COMMIT`, the client should call a SQLite custom function provided by mvsqlite to check whether the commit actually succeeds, and retry if not.
- Witness13 4y ago
- liuliu 4y agoRead a bit of your code. Seems most magic happens around xLock / xUnlock implementation (which were used to identify a txn). I wonder if SQLite should expose one layer up (on the actual pager level). A lot of attempts (such as yours, or LiteFS) try to construct the pager / txn concept from VFS layer as well, which seems to be one layer lower than actually is.