Repository navigation
Recover from a duplicate ALTER PUBLICATION ADD TABLE instead of retrying it forever - #5
Open
DamilShahzad7 wants to merge 1 commit into
Conversation
Contributor
|
Hi Damil, thanks so much for this! Great catch, and the regression test is really helpful. We're putting a CLA/contributor agreement in place before we merge outside code, so this will sit for a bit. We'll come back to you as soon as it's ready. |
Author
|
Hi Philip, Happy to contribute. Sounds good! Let me know when the agreement is ready. |
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.
Summary
publication_relations_add(src/cache/writer/publication.rs) issuesALTER PUBLICATION ... ADD TABLEfor each newly-active relation, then updates its localpublication_oidsbookkeeping once the statement succeeds. If Postgres rejects the statement because a named relation is already a publication member, the function currently returns the error before reaching that update — sopublication_oidsnever learns about the relation, and every later registration attempt against it recomputes the identicaladdedset and reissues the identical failing statement. There's no backoff, so this is a live-lock, not just a failed registration.I ran into this running the project's own
conformanceharness: it never completed, stuck repeating the same"relation \"onek\" is already member of publication ..."error indefinitely.Fix
Catch Postgres's
duplicate_object(42710) specifically on this statement and treat it as success: syncpublication_oidsfrom the attempted set and continue, instead of propagating the error. Any other error still propagates unchanged. This mirrors the existingSqlState-matching convention already used in this codebase (e.g.src/pg/event_trigger.rs).Testing
cargo check --workspace --locked --features proxy— clean.cargo clippy --workspace --locked --features proxy --all-targets— no new warnings from this change (8 pre-existing, unrelated warnings elsewhere, unchanged).tests/publication_registration_test.rs, which reproduces the race by adding the test table to the publication out-of-band before pgcache registers it, then asserts the query still gets cached:schema_change_test,eviction_test,admin_endpoint_test,source_txn_framing_test) alongside the new test; a couple of unrelated tests were intermittently flaky in my container, and I confirmed each one fails identically on unmodifiedmain, so they're pre-existing environment flakiness, not a regression from this change.