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

Using Postgres advisory locks #82

Closed
bymyslf opened this issue May 2, 2018 · 2 comments
Closed

Using Postgres advisory locks #82

bymyslf opened this issue May 2, 2018 · 2 comments

Comments

@bymyslf
Copy link
Contributor

bymyslf commented May 2, 2018

Is there anything that prevents the use of the advisory locks instead of the lock table?

IMO, it would be better to use the native functions. What do you think?

https://www.postgresql.org/docs/9.4/static/explicit-locking.html

@ahydrax
Copy link
Contributor

ahydrax commented May 7, 2018

Hi @bymyslf , there are several things preventing from using advisory locks:

  • pg_advisory_lock accepts only integer values whereas hangfire needs a string for the key
  • advisory locks are binded to current session whereas hangfire lock owner can release the lock via different connection/session

I had a long journey investigating the most "natural" way to implement distributed locks in pg and finally I came to this but it's applicable for pg versions 9.6 and above.

@bymyslf
Copy link
Contributor Author

bymyslf commented May 7, 2018

Hi @ahydrax, the first point is quite embarrassing for me. I was fully confident that the job ID was used as the resource and didn't check twice. Confused with another project that uses distributed locks.

However, even if the job ID was the resource, your second point invalidates the "native" locks.

Thank you for your thoughts.

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

No branches or pull requests

2 participants