From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
Cc: | "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>, 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-02 15:03:15 |
Message-ID: | CA+TgmoaQtB=cnMJwCA33bDrGt7x5ysoW770uJ2Z56AU_NVNdbw@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers pgsql-hackers |
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.
--
Robert Haas
EDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Jacob Champion | 2025-09-02 15:18:42 | Re: pgsql: oauth: Add unit tests for multiplexer handling |
Previous Message | Michael Paquier | 2025-09-02 07:22:19 | pgsql: Generate pgstat_count_slru*() functions for slru using macros |
From | Date | Subject | |
---|---|---|---|
Next Message | Jacob Champion | 2025-09-02 15:18:42 | Re: pgsql: oauth: Add unit tests for multiplexer handling |
Previous Message | Andrew Dunstan | 2025-09-02 14:54:08 | Re: split func.sgml to separated individual sgml files |