This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Remove whole table locks on push rule add/delete #16051
Merged
erikjohnston
merged 11 commits into
matrix-org:develop
from
beeper:remove-push-rule-table-locks
Nov 13, 2023
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
32e0bd3
Remove whole table locks on push rule add/delete
Fizzadar 0938542
Add changelog
Fizzadar ab88d3f
Use `FOR SHARE` to lock selected push rule rows on relative update
Fizzadar d90cef1
Fix `FOR SHARE` handling of push rule transactions
Fizzadar 4dbee68
Use `FOR UPDATE` to ensure selects conflict
Fizzadar 2ec17da
Rewrite highest priority rule txn to use FOR UPDATE in one query
Fizzadar 3282065
Merge branch 'develop' into remove-push-rule-table-locks
Fizzadar 7d10544
Remove leftover quote
Fizzadar 576605e
Revert "Rewrite highest priority rule txn to use FOR UPDATE in one qu…
Fizzadar 376313e
Add missing `txn.execute` on `FOR UPDATE` statement
Fizzadar 7937ac0
Merge branch 'develop' into remove-push-rule-table-locks
Fizzadar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Remove whole table locks on push rule modifications. Contributed by Nick @ Beeper (@fizzadar). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wanted to describe the race to ensure we have a shared understanding. Given two rules
rule_A
andrule_B
with priorities 0 and 1, respectively. If you make two requests:rule_X
) afterrule_A
, this should makerule_B
a priority of 2;rule_X
priority 1; and leaverule_A
at 0.rule_Y
) afterrule_A
, this should makerule_B
a priority of 3;rule_X
priority 2;rule_Y
priority 1; and leaverule_A
at 0.This is in a transaction (I assume running at
READ COMMITTED
), so what happens if these race?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.
I believe the winner will be applied and the second transaction will be replayed using the new updated data, per (added some breaks to make it easier to read, my brain hurts!):
If my understanding is correct
READ COMMITTED
will effectively correct the issue by the replay.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.
That said! Synapse's default is actually one better,
REPEATABLE READ
, in which case things are much simpler:Which synapse automatically retries, which would replay the transaction as expected.
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.
Final note - there is an issue somewhere about switching to
READ COMMITTED
as the default, but it seems that would also suffice here in terms of the potential race conditions.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! I believe that you're correct (but my brain also hurts)!
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.
I'm not sure I agree here. As things stand I don't see why we'd necessarily replay the transactions, as we may not have updated/deleted/locked any of the rows we
SELECT
against (and inserting a new row that would have been picked up by aSELECT
isn't picked up by postgres except inSERIALIZABLE
isolation AIUI).I think what you want here is to run the selects with a
FOR SHARE
so that they do conflict with each other?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.
I guess most of the time the
UPDATE
will conflict, but if we have two requests to add a rule to the top of the push rules those transactions should conflict but won't?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.
Yeah that makes sense, will add
FOR SHARE
in 👍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.
Wait, we probably need a
FOR UPDATE
instead as we need theSELECT
statements to conflict with each other andFOR SHARE
won't do that https://www.postgresql.org/docs/current/explicit-locking.html#LOCKING-ROWS