pgsql: Fix publish_as_relid with multiple publications - Mailing list pgsql-committers

From Tomas Vondra
Subject pgsql: Fix publish_as_relid with multiple publications
Date
Msg-id E1nUXDm-000M1I-23@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix publish_as_relid with multiple publications

Commit 83fd4532a7 allowed publishing of changes via ancestors, for
publications defined with publish_via_partition_root. But the way
the ancestor was determined in get_rel_sync_entry() was incorrect,
simply updating the same variable. So with multiple publications,
replicating different ancestors, the outcome depended on the order
of publications in the list - the value from the last loop was used,
even if it wasn't the top-most ancestor.

This is a probably rare situation, as in most cases publications do
not overlap, so each partition has exactly one candidate ancestor
to replicate as and there's no ambiguity.

Fixed by tracking the "ancestor level" for each publication, and
picking the top-most ancestor. Adds a test case, verifying the
correct ancestor is used for publishing the changes and that this
does not depend on order of publications in the list.

Older releases have another bug in this loop - once all actions are
replicated, the loop is terminated, on the assumption that inspecting
additional publications is unecessary. But that misses the fact that
those additional applications may replicate different ancestors.

Fixed by removal of this break condition. We might still terminate the
loop in some cases (e.g. when replicating all actions and the ancestor
is the partition root).

Backpatch to 13, where publish_via_partition_root was introduced.

Initial report and fix by me, test added by Hou zj. Reviews and
improvements by Amit Kapila.

Author: Tomas Vondra, Hou zj, Amit Kapila
Reviewed-by: Amit Kapila, Hou zj
Discussion: https://postgr.es/m/d26d24dd-2fab-3c48-0162-2b7f84a9c893%40enterprisedb.com

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/677a1dc0ca0f33220ba1ea8067181a72b4aff536

Modified Files
--------------
src/backend/replication/pgoutput/pgoutput.c | 46 ++++++++++++++++++++---
src/test/subscription/t/013_partition.pl    | 57 ++++++++++++++++++++++++++++-
2 files changed, 95 insertions(+), 8 deletions(-)


pgsql-committers by date:

Previous
From: Tomas Vondra
Date:
Subject: pgsql: Fix publish_as_relid with multiple publications
Next
From: Tomas Vondra
Date:
Subject: pgsql: Fix publish_as_relid with multiple publications