| From: | Zhijie Hou <houzhijie22(at)gmail(dot)com> |
|---|---|
| To: | Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com> |
| Cc: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: Add a hook for handling logical decoding messages on subscribers. |
| Date: | 2026-10-31 12:35:15 |
| Message-ID: | b9b5bd27-6416-48b4-8f73-c5a60e2c97e2@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Sat, Oct 31, 2026 at 06:34 AM Masahiko Sawada wrote:
>
> It seems to me worth adding a check for tablesync workers since both
> the apply workers and the tablesync workers call
> walrcv_startstreaming() and it would prevent mistakes by future
> changes.
>
> I've attached the updated patch.
While reviewing how transactional logical messages interact with
subtransaction aborts, I noticed an issue with streamed transactions. In
non-streaming mode, it works as expected (i.e., the message is not
applied if the subtransaction is aborted). However, in streaming mode,
if a transactional message is emitted in a subtransaction that is later
aborted, the STREAM ABORT message does not discard or roll back that
logical message, so it still gets applied in both streaming=on and
streaming=parallel modes.
I think the reason is that ReorderBufferApplyMessage() passes the
top-level txn rather than change->txn to rb->stream_message(), so
logical decoding always sends the top-level XID instead of the
subtransaction XID when outputting a streamed message. Thus the apply
worker cannot associate the message with the subtransaction and cannot
roll it back properly.
Strictly speaking, this is an existing issue, but it becomes more
visible once subscribers can handle logical messages via this hook. So
it may be worth considering whether to fix it along with this patch or
separately.
Attached 0002 adds a test diff in 001_basic.pl to show the issue when
streaming a message in an aborted subtransaction. 0001 is a draft patch
showing that passing the subtransaction of the message when streaming
allows the message to be rolled back properly (we may not necessarily
fix it in this exact style, just sharing it to show the behavior change).
--
Best Regards,
Zhijie Hou
| Attachment | Content-Type | Size |
|---|---|---|
| nocfbot-0001-Fix-subtransaction-XID-in-streamed-logical-messag.patch | text/plain | 5.8 KB |
| nocfbot-0002-Top-up-for-v6-0001-Test-streamed-subtransaction-.patch | text/plain | 1.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Lakhin | 2026-10-31 13:00:00 | Re: greenfly lwlock corruption in REL_14_STABLE and REL_15_STABLE |
| Previous Message | Heikki Linnakangas | 2026-10-31 11:47:32 | Re: Avoid crashes on a concurrently dropped schema |