Re: Avoid resetting subscription two_phase state to pending when already enabled

From: Zhijie Hou <houzhijie22(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: shveta malik <shveta(dot)malik(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, amit(dot)kapila16(at)gmail(dot)com, shveta malik <shvetamalik(at)gmail(dot)com>
Subject: Re: Avoid resetting subscription two_phase state to pending when already enabled
Date: 2026-11-02 02:51:25
Message-ID: 69baee13-4c0f-4c00-a268-2bff2b8246f9@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Mon, Nov 2, 2026 at 10:04 AM Peter Smith wrote:
> IMO, the nested checking of opts.twophase in the ternary makes the
> patch code unnecessarily hard to follow across combinations.
>
> My suggestion is to implement it using more verbose, but easier-to-read code:
>
> /* Change system catalog accordingly */
> if (sub->twophasestate == LOGICALREP_TWOPHASE_STATE_DISABLED)
> {
> if (opts.twophase)
> {
> /* enable two_phase */
> values[Anum_pg_subscription_subtwophasestate - 1] =
> CharGetDatum(LOGICALREP_TWOPHASE_STATE_PENDING);
> replaces[Anum_pg_subscription_subtwophasestate - 1] = true;
> }
> }
> else if (!opts.twophase)
> {
> /* disable two_phase */
> values[Anum_pg_subscription_subtwophasestate - 1] =
> CharGetDatum(LOGICALREP_TWOPHASE_STATE_DISABLED);
> replaces[Anum_pg_subscription_subtwophasestate - 1] = true;
> }
>
> ~

Thank for the suggestion, but I personally don't prefer the longer,
nested style, as I don't find it clearly easier to read. So I would keep
the current version for now and see what the committer thinks.

--
Best Regards,
Zhijie Hou

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2026-11-02 03:37:16 Re: Racing in ROLLBACK PREAPRED and checkpoint
Previous Message Fujii Masao 2026-11-02 02:41:56 Re: bug: query returns different result with and without memoization.