-
Notifications
You must be signed in to change notification settings - Fork 10
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
Improve replication object clean-up on failure. #59
Merged
ettanany
merged 2 commits into
main
from
kathiabarahona/improve_exception_handling_on_cleanup
Feb 11, 2025
Merged
Improve replication object clean-up on failure. #59
ettanany
merged 2 commits into
main
from
kathiabarahona/improve_exception_handling_on_cleanup
Feb 11, 2025
Conversation
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
b5e7be4
to
cb5e018
Compare
cb5e018
to
edf4e64
Compare
kathia-barahona
commented
Jan 27, 2025
edf4e64
to
424c9b1
Compare
ettanany
reviewed
Jan 29, 2025
Added some improvements on error handling whenever pg_migrate is cleaning any replication object (publication, subscription, replication slot). As our current implementation does not drop objects whenever create_<repl_object_type> fails (raises an exception). Current clean-up is dependent on the object name returned by those functions, but if nothing is returned then nothing will be cleaned. The improvement makes the cleanup independent from the return of such functions, as it nows fetches the replication object name and verifies it exists or not, instead of relying on return values.
424c9b1
to
0159aaf
Compare
ettanany
reviewed
Feb 11, 2025
Comment on lines
+621
to
+637
try: | ||
if replication_object_type is ReplicationObjectType.PUBLICATION: | ||
delete_query = f"DROP PUBLICATION {rep_obj_name};" | ||
args = () | ||
elif replication_object_type is ReplicationObjectType.REPLICATION_SLOT: | ||
delete_query = f"SELECT 1 FROM pg_catalog.pg_drop_replication_slot(%s)" | ||
args = (rep_obj_name, ) | ||
else: | ||
# cleanup only handles publications and replication slots in source. | ||
return | ||
|
||
self.log.info( | ||
"Dropping %r %r from database %r", | ||
rep_obj_type_display_name, | ||
rep_obj_name, | ||
dbname, | ||
) |
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.
Suggested change
try: | |
if replication_object_type is ReplicationObjectType.PUBLICATION: | |
delete_query = f"DROP PUBLICATION {rep_obj_name};" | |
args = () | |
elif replication_object_type is ReplicationObjectType.REPLICATION_SLOT: | |
delete_query = f"SELECT 1 FROM pg_catalog.pg_drop_replication_slot(%s)" | |
args = (rep_obj_name, ) | |
else: | |
# cleanup only handles publications and replication slots in source. | |
return | |
self.log.info( | |
"Dropping %r %r from database %r", | |
rep_obj_type_display_name, | |
rep_obj_name, | |
dbname, | |
) | |
if replication_object_type is ReplicationObjectType.PUBLICATION: | |
delete_query = f"DROP PUBLICATION {rep_obj_name}" | |
args = () | |
elif replication_object_type is ReplicationObjectType.REPLICATION_SLOT: | |
delete_query = f"SELECT 1 FROM pg_catalog.pg_drop_replication_slot(%s)" | |
args = (rep_obj_name, ) | |
else: | |
# cleanup only handles publications and replication slots in source. | |
return | |
self.log.info( | |
"Dropping %r %r from database %r", | |
rep_obj_type_display_name, | |
rep_obj_name, | |
dbname, | |
) | |
try: |
ettanany
approved these changes
Feb 11, 2025
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.
Added some improvements on error handling whenever pg_migrate is cleaning any replication object (publication, subscription, replication slot). As our current implementation does not drop objects whenever create_<repl_object_type> fails (raises an exception). Current clean-up is dependent on the object name returned by those functions, but if nothing is returned then nothing will be cleaned. The improvement makes the cleanup independent from the return of such functions, as it nows fetches the replication object name and verifies it exists or not, instead of relying on return values.
Also updated git workflow, for testing against newer versions (PG13-PG17) and use >= Python 3.10
Proposed changes in this pull request
Type (put an
x
where ever applicable)Checklist
Please put an
x
against the checkboxes. Write a small comment explaining if itsN/A
(not applicable)Optional extra information