Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SQLite in WAL mode, with IMMEDIATE transactions #412

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

djmitche
Copy link
Collaborator

@djmitche djmitche commented Jul 6, 2024

WAL mode is generally better, and allows concurrent reads to happen concurrently with other reads and writes. It does not allow writes concurrently with writes, though, failing with SQLITE_BUSY if that occurs.

SQLite's busy_timeout allows retrying on SQLITE_BUSY, but that does not work if a read-only transaction is upgraded to a write transaction, which is what TransactionBehavior::Deferred (a.k.a. BEGIN DEFERRED) does. TransactionBehavior::Immediate always begins a write transaction immediately, fails with SQLITE_BUSY if that is not allowed, and uses the busy_timeout logic to try to wait for the running transaction to finish.

This includes a unit test, but as the issue is a race condition, the test does not always fail without the fix. However, it reliably passes with the fix, which is really the important bit.

This fixes GothenburgBitFactory/taskwarrior#3325.

WAL mode is generally better, and allows concurrent reads to happen
concurrently with other reads and writes. It does not allow writes
concurrently with writes, though, failing with SQLITE_BUSY if that
occurs.

SQLite's `busy_timeout` allows retrying on SQLITE_BUSY, but that does
not work if a read-only transaction is upgraded to a write transaction,
which is what `TransactionBehavior::Deferred` (a.k.a. `BEGIN DEFERRED`)
does. `TransactionBehavior::Immediate` always begins a write transaction
immediately, fails with SQLITE_BUSY if that is not allowed, and uses the
`busy_timeout` logic to try to wait for the running transaction to
finish.

This includes a unit test, but as the issue is a race condition, the
test does not always fail without the fix. However, it reliably passes
with the fix, which is really the important bit.
taskchampion/src/storage/sqlite.rs Outdated Show resolved Hide resolved
Co-authored-by: ryneeverett <ryneeverett@gmail.com>
@djmitche djmitche enabled auto-merge (squash) July 11, 2024 17:14
@djmitche djmitche merged commit 8c3a582 into GothenburgBitFactory:main Jul 11, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Racing working-set updates cause "Clear working set query" errors
2 participants