-
Notifications
You must be signed in to change notification settings - Fork 149
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
fix: sqlite write contention #1045
fix: sqlite write contention #1045
Conversation
i'm looking at the test failures and they seem to be related to testing this specific functionality. @JWCook let me know if you would like me to fix them, but as i'm new to the test suite it might better if you take over from here! |
Thank you for the PR! I think this will likely be a nice improvement. Before I merge this, I do need to study up on this a bit more to refresh my memory on SQLite locking, transactions, and journaling modes. A few questions, if you happen to know:
For the test failures, one is because users can currently pass SQLiteCache('http_cache', isolation_level='EXCLUSIVE') One way to handle this would be to log a warning and ignore For the other two failures ( |
no, iiuc it's the other way around -- exclusive lock prevents concurrent reads unless wal mode is set.
no, but there are a lot of pragmas and i can't say i'm familiar with all of them. i think the thing to do here is document that requests-cache acquires exclusive locks on the db during the normal course of its operation, and let users understand the implications here.
hmm i've never run into this but it sounds plausible that it could happen. i guess the commit might fail for some reason like a disk failure, which would presumably also cause the rollback to fail as well. my instinct here is to let the exception bubble up here rather than catching it, since it's probably some unrecoverable error that the user should know about, but happy to go with whatever you want here.
i will check on these, probably this weekend! |
d82e01b
to
1703d35
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1045 +/- ##
==========================================
- Coverage 99.13% 99.13% -0.01%
==========================================
Files 23 23
Lines 2084 2083 -1
Branches 332 331 -1
==========================================
- Hits 2066 2065 -1
Misses 9 9
Partials 9 9 ☔ View full report in Codecov by Sentry. |
@charles-cooper Are there more changes you'd like to make here? Otherwise I should have some time this weekend to finish this up. I think all that's needed is a bit more error handling and test coverage. |
nope - have at it! |
in the sqlite backend, the current strategy for writes is to write-with-retry. however, this can fail because our connection could be starved for a write if we are racing with other processes and sqlite keeps giving the write to other processes. this commit addresses the issue by acquiring an exclusive lock from sqlite before any write to the database. references: - https://stackoverflow.com/a/21888761 - https://www.sqlite.org/lockingv3.html update tests
219f0d0
to
d38a56d
Compare
in the sqlite backend, the current strategy for writes is to write-with-retry. however, this can fail because our connection could be starved for a write if we are racing with other processes and sqlite keeps giving the write to other processes.
this commit addresses the issue by acquiring an exclusive lock from sqlite before any write to the database.
references:
if my understanding is correct, this closes #820
Checklist