Re: Conflict detection for multiple_unique_conflicts in logical replication

Nisha Moond <nisha.moond412@gmail.com>

From: Nisha Moond <nisha.moond412@gmail.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: Peter Smith <smithpb2250@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Date: 2025-03-19T05:41:11Z
Lists: pgsql-hackers

Attachments

On Mon, Mar 17, 2025 at 3:20 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Thu, Mar 13, 2025 at 4:30 PM Nisha Moond <nisha.moond412@gmail.com> wrote:
> >
> > Attached is the v4 patch (test case changes only).
> >
>
> Comments:
> =========
> 1.
> + /*
> + * Report an INSERT_EXISTS or UPDATE_EXISTS conflict when only one unique
> + * constraint is violated.
> + */
> + if (conflicts == 1)
> + {
> + Oid uniqueidx;
> + RepOriginId origin;
> + TimestampTz committs;
> + TransactionId xmin;
> +
> + uniqueidx = linitial_oid(conflictIndexes);
> + conflictslot = linitial(conflictSlots);
> +
> + GetTupleTransactionInfo(conflictslot, &xmin, &origin, &committs);
> + ReportApplyConflict(estate, resultRelInfo, ERROR, type,
> + searchslot, conflictslot, remoteslot,
> + uniqueidx, xmin, origin, committs);
> + }
> +
> + /*
> + * Report MULTIPLE_UNIQUE_CONFLICTS when two or more unique constraints
> + * are violated.
> + */
> + else if (conflicts > 1)
> + ReportMultipleUniqueConflict(estate, resultRelInfo, ERROR,
> + CT_MULTIPLE_UNIQUE_CONFLICTS,
> + searchslot, remoteslot,
> + conflictSlots, conflictIndexes);
>
> It looks a bit odd to have different functions for one or multiple
> conflicts. We can improve this coding pattern by extending the current
> function ReportApplyConflict to report one or multiple conflicts
> depending on the length of conflictSlots.
>

Modified the code to use the existing ReportApplyConflict function.

> 2. From the commit message: "Also, the patch adds a new column
> 'confl_multiple_unique_conflicts' in view pg_stat_subscription_stats
> to support stats collection for this conflict type.". This part can be
> split into a second patch. Let's try to get the core patch first.
>

I have separated the "stats" part from the core patch and will post it
as a separate patch in the next version.

Please find the attached v5-0001 patch without the stats part.

--
Thanks,
Nisha

Commits

  1. Stablize tests added in 3abe9dc188.

  2. Fix the typo in the test case added in 73eba5004a.

  3. Detect and Log multiple_unique_conflicts type conflict.