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

Add advisory_lock utility from AWX #661

Merged
merged 10 commits into from
Dec 18, 2024
Merged

Conversation

AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Dec 2, 2024

This migrates advisory_lock from AWX to DAB. This is similar in spirit to #660

Importantly, 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

@AlanCoding AlanCoding changed the title Run linters and add docs Add advisory_lock utility from AWX Dec 2, 2024
@AlanCoding AlanCoding marked this pull request as ready for review December 2, 2024 19:37
Copy link
Member

@john-westcott-iv john-westcott-iv left a 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.

@AlanCoding
Copy link
Member Author

It might be nice to have vendor specific files in ansible_base/lib/utils/db i.e. something for postgres/mssql/sqlite

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.

@chrismeyersfsu
Copy link
Member

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 (lock_id in this code I think) --> lock name as a string.

@AlanCoding AlanCoding merged commit 1cf551b into ansible:devel Dec 18, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants