-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
PgLock state inspection is not isolated to current database #431
Comments
Just wanted to chime in about the chance of collisions here for documentation's sake for others. Since the advisory lock keys are constrained to 64 bits of information (via 2 32-bit columns), we don't get the full benefit of a UUID's 122 bits of randomness (for UUID version 4). Given the birthday problem, we would expect a 1% chance of collision of lock keys after 610 million UUIDs and a 50% collision of lock keys after 5.1 billion UUIDs (assuming no issues with UUID generation or md5 hashing). I'm not sure if this has any practical impact here... I just find the birthday problem academically fascinating! |
@reczy love it! Thank you for sharing that. I appreciate you doing the math! And I am also curious about any randomness loss in the In practice, given how GoodJob uses advisory locks, the operation (e.g. running jobs) impact of a collision is that that the two colliding jobs could not be worked at the same time. I don't believe it would impact the most important (to me) contract of a job not being executed twice. |
Going from MD5 -> BIGINT is just taking 16 hexadecimal characters and converting from base 16 to base 10 so no loss there. But as for UUID -> MD5, I'm not sure. MD5 has been cryptographically broken for a while now, but I'm not sure what implications that has for its specific purpose in GoodJob. If you did want to address, I think two potential alternatives are:
Agreed. |
@reczy that is clever! Unfortunately the concurrency-locks rely on an arbitrary string as the lock key. I also keep wanting to extract |
Discovered that in #430 that when GoodJob explicitly looks at the lock state of a job by joining on
pg_locks
, it does not scope down to the current database, but rather looks across the cluster for that particular lock key. GoodJob does this on the Dashboard, to filter on which jobs are running. This does not affect the executing of jobs, because that uses Postgres locking functions.GoodJob locks against a job's UUID, so it should be globally unique. The scenarios I imagine this biting someone is:
...which seems somewhat farfetched and non-material.
I am documenting this here just in case someone believes they experience a side effect of this, but I don't think it warrants action, and maybe it's actually a feature e.g. if someone is sharding the
good_jobs
table maybe inspecting global lock state is a good thing.The text was updated successfully, but these errors were encountered: