| From: | Zhijie Hou <houzhijie22(at)gmail(dot)com> |
|---|---|
| To: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Detect mismatched subscription and replication slot properties |
| Date: | 2026-11-19 06:32:37 |
| Message-ID: | e7e73c83-4e45-4c4a-a693-a4fadf289c07@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Wed, Nov18, 2026 at 10:15 PM Bertrand Drouvot wrote:
>
> On Mon, Nov 16, 2026 at 03:46:25PM +0530, Amit Kapila wrote:
> > On Tue, Nov 10, 2026 at 7:44 PM Bertrand Drouvot
> > > For failover, the value should match exactly.
> > >
> > > For two_phase, the expected value depends on subtwophasestate:
> > >
> > > • DISABLED: the slot must have two_phase = false.
> > > • PENDING, before the tables are ready: it must remain false.
> > > • PENDING, once the tables are ready: either value can be accepted before enabling
> > > it and recording the state as ENABLED. This also makes the
> > > transition safe if the worker previously exited between those two
> > > operations.
> > > • ENABLED: the slot must have two_phase = true.
> > >
> >
> > Instead of PENDING state checks, how about checking mismatch in
> > begin_prepared kind of functions whether the subscription has
> > reached ENABLED state? I am asking this because if the slot is
> > initially created with two_phase = true and the subscription is in
> > pending state then the apply worker will start receiving prepared
> > transactions and will lead to problems described under "TWO_PHASE
> > TRANSACTIONS" in worker.c.
>
> Thanks for looking at it!
>
> I think that could be too late. With parallel streaming, a parallel
> apply worker may already have executed the transaction's changes.
IIUC, it wouldn't be too late. Even if the changes are already being
executed, the transaction won't be prepared if we catch the mismatch in
apply_handle_prepare (and related functions). The user can still recover
by disabling two_phase on the slot, and the transaction will then be
replicated again as a normal transaction once COMMIT PREPARED is
executed on the publisher.
Also, catching this in the apply_handle_* functions still protects cases
where the publisher is on an older version that does not support the new
protocol option. It can also serve as a useful safeguard against
non-standard servers that might accidentally send unexpected prepared
transactions (similar checks were added in fe6a20c), and we already have
related checks that disallow prepare messages in the tablesync worker.
So adding a runtime check seems like an independent win to me.
Or do you have scenarios in mind that the runtime check cannot handle
that I might be missing (for cases when two_phase is disabled on sub but
enabled on slot) ?
I am attaching a draft patch that adds runtime check with a test to show
that reporting an ERROR at that point is recoverable, just for reference
and discussion.
--
Best Regards,
Zhijie Hou
| Attachment | Content-Type | Size |
|---|---|---|
| nocfbot-0001-Reject-two-phase-transactions-when-two_phase-is-n.patch | text/plain | 7.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ashutosh Bapat | 2026-11-19 06:56:49 | Re: [PATCH] Clarify CREATE INDEX IF NOT EXISTS output for invalid indexes |
| Previous Message | Chao Li | 2026-11-19 06:32:29 | Avoid rescanning prefixes in appendStringLiteralDQ() |