store: Do not use a fdw connection to check active_copies#5938
Merged
store: Do not use a fdw connection to check active_copies#5938
Conversation
Copying checks the active_copies table through the primary_public.active_copies foreign table to determine whether the copy has been cancelled and it should stop. With a large number of copies running, that causes a large number of postgres_fdw connections into the primary, which can overwhelm the primary. Instead, we now pass the connection pool for the primary into the copy code so that it can do this check without involving postgres_fdw.
zorancv
approved these changes
Apr 10, 2025
| } | ||
|
|
||
| fn unlock(&mut self, dst: &Site) -> Result<(), StoreError> { | ||
| if !self.has_lock { |
Contributor
There was a problem hiding this comment.
I guess here and in the two previous ifs if would be nice to get an error logged. Also in the else branch in switch().
Collaborator
Author
There was a problem hiding this comment.
I think only the ifs in lock and unlock need logging; the else in switch is not an issue; we basically just want to make sure we put the right connection back into other, not just any. Changing those two ifs
store/postgres/src/copy.rs
Outdated
| } | ||
|
|
||
| /// Put `self` into `other` if `self` has the lock. | ||
| fn switch(self, other: &mut Option<Self>) { |
Contributor
There was a problem hiding this comment.
Isn't extract more suitable name?
Collaborator
Author
There was a problem hiding this comment.
I was definitely struggling with the name. But I like extract better.
Otherwise, the lock will linger and can block an attempt to restart a copy that failed for transient reasons
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Copying checks the active_copies table through the primary_public.active_copies foreign table to determine whether the copy has been cancelled and it should stop.
With a large number of copies running, that causes a large number of postgres_fdw connections into the primary, which can overwhelm the primary.
Instead, we now pass the connection pool for the primary into the copy code so that it can do this check without involving postgres_fdw.