| From: | "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com> |
|---|---|
| To: | Robert Haas <robertmhaas(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
| Cc: | Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <akapila(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | RE: pgsql: Preserve conflict-relevant data during logical replication. |
| Date: | 2025-09-03 11:40:53 |
| Message-ID: | TY4PR01MB16907A6D1F3A6E1C333FF1BF29401A@TY4PR01MB16907.jpnprd01.prod.outlook.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers pgsql-hackers |
On Tuesday, September 2, 2025 11:03 PM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
> On Wed, Jul 23, 2025 at 11:44 PM Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
> wrote:
> > The fix looks good to me. I'll push your patch in sometime.
>
> The tests in this patch are insufficient to prove that this logic works properly. I
> tried with this patch:
>
> diff --git a/src/backend/access/transam/twophase.c
> b/src/backend/access/transam/twophase.c
> index 7918176fc58..7c1d0ef07b5 100644
> --- a/src/backend/access/transam/twophase.c
> +++ b/src/backend/access/transam/twophase.c
> @@ -2325,6 +2325,16 @@ RecordTransactionCommitPrepared(TransactionId
> xid,
> TimestampTz committs;
> bool replorigin;
>
> + /*
> + * Note it is important to set committs value after marking ourselves as
> + * in the commit critical section (DELAY_CHKPT_IN_COMMIT). This is
> because
> + * we want to ensure all transactions that have acquired commit
> timestamp
> + * are finished before we allow the logical replication client to advance
> + * its xid which is used to hold back dead rows for conflict detection.
> + * See comments atop worker.c.
> + */
> + committs = GetCurrentTimestamp();
> +
> /*
> * Are we using the replication origins feature? Or, in other words, are
> * we replaying remote actions?
> @@ -2344,16 +2354,6 @@ RecordTransactionCommitPrepared(TransactionId
> xid,
> */
> pg_write_barrier();
>
> - /*
> - * Note it is important to set committs value after marking ourselves as
> - * in the commit critical section (DELAY_CHKPT_IN_COMMIT). This is
> because
> - * we want to ensure all transactions that have acquired commit
> timestamp
> - * are finished before we allow the logical replication client to advance
> - * its xid which is used to hold back dead rows for conflict detection.
> - * See comments atop worker.c.
> - */
> - committs = GetCurrentTimestamp();
> -
> /*
> * Emit the XLOG commit record. Note that we mark 2PC commits as
> * potentially having AccessExclusiveLocks since we don't know whether
> or
>
> If it is in fact important to acquire the commit timestamp after setting
> delayChkptFlags, you'd hope this would lead to a test failure, but it doesn't for
> me. I understand it probably requires an injection point to be certain of hitting
> the race condition, but I think that would be worth doing. Otherwise, if
> something gets broken here by accident, it might be a long time before anyone
> notices.
Thanks for pointing it out!
I agree that adding a test is valuable to mitigate the risk of future code
changes. We added a similar safeguard for the RecordTransactionCommit() function
by adding Assert(xactStopTimestamp == 0) after marking the DELAY_CHKPT_xxx flag,
and did not do any precautionary check for RecordTransactionCommitPrepared as
the code to acquire the timestamp and setting flag was close by and had explicit
comments.
I'll prepare a test case that uses the injection point and share it in the
original thread.
Best Regards,
Hou zj
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jacob Champion | 2025-09-03 14:59:20 | pgsql: ci: Remove extra PG_TEST_EXTRA from NetBSD/OpenBSD |
| Previous Message | Peter Eisentraut | 2025-09-03 09:51:25 | pgsql: Fix mistake in new GUC tables source |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Daniel Gustafsson | 2025-09-03 11:42:56 | Re: Solaris compiler status |
| Previous Message | Andrew Dunstan | 2025-09-03 11:33:36 | Re: Solaris compiler status |