-
Notifications
You must be signed in to change notification settings - Fork 733
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
Implementation to enforce convenient write locks on Postgres and Sqlite #8004
Implementation to enforce convenient write locks on Postgres and Sqlite #8004
Conversation
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.
We absolutely need the atomic transaction wrapping to make this work, so that's a must have.
In terms of testing, testing this is going to be a little bit tricky, so I think we should cohack on this to get this out the door!
…ng atomic transactions, for Sqlite created dummy operation to execute the task and for Postgres implemented advisory lock.
dbaa452
to
b4244f1
Compare
The errors are in affected code paths, so we may have something to unpick here. The strangest thing is that the test we created and tested locally was failing too. I'm rerunning the tests just to be sure. |
I run tests before pushing. |
Yeah, something seems to be behaving differently in CI - I'll check it out in the morning! |
with transaction.atomic(): | ||
operation = PostgresLock(key=lock_id) | ||
operation.execute() | ||
yield |
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.
I don't see operation.revert()
here? That seems necessary because the type of advisory lock obtained is a session level lock, which should remain locked for the duration of the connection. I would suggest changing pg_advisory_lock
to pg_advisory_xact_lock
(reference). Note that for the transaction level lock functions (xact
), there aren't corresponding unlock
functions because it would be cleared by COMMIT or ROLLBACK of the transaction, including if the connection is closed.
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.
Ah, thanks - that's my bad for misleading @apurva-modi here. I'll submit an update.
Summary
Created a simple context manager to implement database write lock using atomic transactions.
…
References
Fix for #7891
Reviewer guidance
Testing checklist
PR process