-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add a db lock system to prevent race conditions #104
Conversation
cdde0f1
to
a5514c9
Compare
4c283d3
to
6fb2455
Compare
One could consider adding an easy way to get all expired locks. And as mentioned in an inline comment then adding a username may make it safer when manually removing locks. |
I have refactored the three locking functions into two (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great simplification - I only have a couple of small suggestions
Intent
Fixes #63
Approach
This PR adds the db locking system developed for
diseasystore
and expands and improves it.The original description from
diseasystore
:These locks are stored in a "locks" table in a given schema (set by the
schema
argument in the function calls).Each entry is also identified by a timestamp for the lock creation "lock_start", which is used to detect stale locks.
Going from there, the
remove_expired_locks()
was removed and instead we throw an error inis_lock_owner()
if there is a stale lock on the table.For example, if a process crashes mid
update_snapshot()
we may want to not release the lock and instead create a "rollback" method to fix the botched update.Tests were added for the functions which led to a number of fixes to the functions.
Finally, a simple implementation was made to
update_snapshot
where it attempts to gain lock on the table before starting the update.Known issues
This PR also contains the code being merged inDelete intermediate tables after use #89Once merged, this PR will be rebased and opened.Tests for PostgreSQL are showing as failing.
This is caused by an update to the Workflows so that previously undetected errors are now being explicitly shown.
The source of the error is being fixed in #98
Checklist
NEWS.md