-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Switch pg backend to session-level advisory locking #20561
Conversation
…k of partial state updates
switch { | ||
case err == sql.ErrNoRows: | ||
// When the row does not yet exist in state, take | ||
// the `-1` lock to create the new row. | ||
innerRow := c.txn.QueryRow(`SELECT pg_try_advisory_xact_lock(-1)`) | ||
innerRow := c.Client.QueryRow(`SELECT pg_try_advisory_lock(-1)`) |
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.
Just to make sure I understand correctly the reason for the 2 lock attempts; this looks for an individual "workspace" entry with a lock, and if it didn't exist it takes a coarser lock on everything to make sure it's safe to create the workspace?
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.
Yes, that's right.
Although, what you've pointed out made me realize that there was a gap in this implementation. Once locked for creation [-1
], after a new workspace's DB row is inserted, another DB session would have been able to lock that now existant row [the row's id
], before the creation lock was unlocked.
I just pushed another rev that prevents taking a workspace-specific lock if already locked for creation.
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.
Thanks for the clarification, this makes sense now, especially with the latest update.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
…to avoid rollback of partial state updates.
Based on discussion following merge of Postgres backend with @jbardin
Acceptance tests are once again passing locally ✅ (updated for commit 34fa67c)
Also, have manually exercised
terraform apply
&destroy
with this revised backend ✅