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

Use sys_pgcon for long-term advisory locks #8320

Merged
merged 2 commits into from
Feb 10, 2025
Merged

Conversation

fantix
Copy link
Member

@fantix fantix commented Feb 8, 2025

  • Fixes the issue of advisory locks getting leaked back to the connection pool.
  • Fixes the test_ext_ai_indexing_* failures in CI.

Refs #7183, sample run

@fantix fantix added the to-backport-6.x PRs that *should* be backported to 6.x label Feb 8, 2025
Comment on lines 390 to 391
await pgconn.sql_execute(b"ROLLBACK TO SAVEPOINT " + sp)
async with tenant.use_sys_pgcon() as syscon:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the try-lock for?
And couldn't it get taken by another connection after the ROLLBACK but before the lock?
Is that a problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the try-lock for?

It checks if the lock is being held by another worker (through sys_pgcon). We cannot acquire this lock directly in sys_pgcon because, say if another worker is already holding this lock through sys_pgcon, re-acquiring the lock will not block (or fail with the try_* method) from the same sys_pgcon session.

And couldn't it get taken by another connection after the ROLLBACK but before the lock?

That's guaranteed not to happen by the outter/first lock, unless other code misused the same advisory lock ID.

Copy link
Member

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I understand.
Probably could use some more comments, because the protocol here is subtle.
(Or are you changing the protocol per @mmastrac's comments?)

@fantix fantix merged commit 39083b6 into master Feb 10, 2025
23 checks passed
@fantix fantix deleted the long-term-advisory-lock branch February 10, 2025 18:46
@msullivan msullivan added backported-6.x PRs that *have* been backported to 6.x and removed to-backport-6.x PRs that *should* be backported to 6.x labels Feb 10, 2025
msullivan pushed a commit that referenced this pull request Feb 10, 2025
* Fixes the issue of advisory locks getting leaked back to the
connection pool.
* Fixes the `test_ext_ai_indexing_*` failures in CI.
fantix added a commit that referenced this pull request Feb 14, 2025
deepbuzin pushed a commit that referenced this pull request Feb 18, 2025
* Fixes the issue of advisory locks getting leaked back to the
connection pool.
* Fixes the `test_ext_ai_indexing_*` failures in CI.
@msullivan msullivan added backported-5.x PRs that *have* been backported to 5.x (starting with 5.3) and removed to-backport-5.x labels Feb 20, 2025
msullivan pushed a commit that referenced this pull request Feb 20, 2025
* Fixes the issue of advisory locks getting leaked back to the
connection pool.
* Fixes the `test_ext_ai_indexing_*` failures in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported-5.x PRs that *have* been backported to 5.x (starting with 5.3) backported-6.x PRs that *have* been backported to 6.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants