| From: | Masahiko Sawada <msawada(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Add an xid argument to the logical decoding message callbacks. |
| Date: | 2026-11-23 23:11:04 |
| Message-ID: | E1xVdBf-000000004jT-3rUl@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Add an xid argument to the logical decoding message callbacks.
Previously, when streaming an in-progress transaction, a transactional
logical decoding message emitted in a subtransaction was passed to the
stream_message callback with the top-level transaction only, and the
callback had no way to know which subtransaction had emitted it. The
change callbacks get that through ReorderBufferChange, but a message
has none. pgoutput therefore sent the message with the top-level XID,
and when the subtransaction was later rolled back and STREAM ABORT
arrived for it, the subscriber could not discard the message with
it. Oversight in commit 7259736a6e5.
To fix this, we add the XID of the (sub)transaction that emitted the
message as a new argument of both the message and stream_message
callbacks, and have pgoutput send it. Output plugins can now see which
subtransaction a message belongs to, as they already can for the other
change types, while still getting the top-level transaction as
before. Both callbacks get the argument so that a plugin can keep
implementing them with one function, as pgoutput does.
We considered fixing this in a backpatchable way, such as passing the
subtransaction's ReorderBufferTXN to the callback instead of the
top-level one, but that silently changes the meaning of an existing
argument, and an output plugin that keeps its state on the top-level
transaction would break. Adding an argument breaks the ABI, but it is
the cleaner interface, so we chose it and don't backpatch. The bug
exists in the back branches too, but there have been no reports, and
the built-in logical replication doesn't use logical messages there.
Author: Zhijie Hou <houzhijie22(at)gmail(dot)com>
Co-authored-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Reviewed-by: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
Discussion: https://postgr.es/m/b9b5bd27-6416-48b4-8f73-c5a60e2c97e2@gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7bb8cc295b538df21d854e55e12a32dbbd8609b1
Modified Files
--------------
contrib/test_decoding/expected/stream.out | 47 +++++++++++++++++++++++++
contrib/test_decoding/sql/stream.sql | 29 +++++++++++++++
contrib/test_decoding/test_decoding.c | 22 ++++++------
doc/src/sgml/logicaldecoding.sgml | 14 +++++++-
src/backend/replication/logical/logical.c | 12 +++----
src/backend/replication/logical/reorderbuffer.c | 11 +++---
src/backend/replication/pgoutput/pgoutput.c | 17 ++++-----
src/include/replication/output_plugin.h | 10 ++++--
src/include/replication/reorderbuffer.h | 2 ++
9 files changed, 132 insertions(+), 32 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Michael Paquier | 2026-11-23 22:59:41 | pgsql: Avoid DELAY_CHKPT_START in smgr_bulk_finish() |