-
Notifications
You must be signed in to change notification settings - Fork 50
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 advisory_lock utility from AWX #661
Conversation
da96425
to
20aead6
Compare
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.
It might be nice to have vendor specific files in ansible_base/lib/utils/db i.e. something for postgres/mssql/sqlite and then the db.py
would have "Generic methods" which would check the vendor and then call items from the DB specific files.
Maybe sometime, I just don't feel like we're really there yet. AWX has probably the most postgres-specific code, and it's just lying around scatter-shot. It might be nice to attempt sqlite solution, probably like this: https://stackoverflow.com/questions/6931342/system-wide-mutex-in-python-on-linux class Locker:
def __enter__ (self):
self.fp = open("./lockfile.lck")
fcntl.flock(self.fp.fileno(), fcntl.LOCK_EX)
def __exit__ (self, _type, value, tb):
fcntl.flock(self.fp.fileno(), fcntl.LOCK_UN)
self.fp.close() Then that would share a lot of feature and not share a lot of features. So then you have a lot of param handling logic to error if it's 1 vendor and not another. Definitely going in the opposite direction of django-pglocks where this comes from. And I do think that would be good for when we introduce a sqlite version, but that just seems too arbitrary and premature until we're at that point. |
8a5924b
to
b45ab06
Compare
Quality Gate passedIssues Measures |
I'll mention a real-world issue I've had. We had a lock that was held and not let go. Which lock? That was hard to find out. It was easy enough to surface the set of held locks from Postgres. The hard part was taking the integer ( |
This migrates
advisory_lock
from AWX to DAB. This is similar in spirit to #660Importantly, I went the route of not adding a new dependency, because there was only a single method from the library we were using, and I'm pretty confident that the MIT license lets you do whatever you want. In doing this, I deleted the use of
six
for python2 compatibility which further reduced the complexity of the code I ported.Additionally requested reviewers @Alex-Izquierdo @TheRealHaoLiu