Re: parse_subscription_options - suggested improvements

From: "Bossart, Nathan" <bossartn(at)amazon(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: parse_subscription_options - suggested improvements
Date: 2021-12-03 00:02:34
Message-ID: 6D83EAFA-E47C-436B-BF77-DA21F05F35FC@amazon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 8/8/21, 11:54 PM, "Peter Smith" <smithpb2250(at)gmail(dot)com> wrote:
> v11 -> v12
>
> * A rebase was needed due to some recent pgindent changes on HEAD.

The patch looks correct to me. I have a couple of small comments.

+ /* Start out with cleared opts. */
+ memset(opts, 0, sizeof(SubOpts));

Should we stop initializing opts in the callers?

- if (opts->enabled &&
- IsSet(supported_opts, SUBOPT_ENABLED) &&
- !IsSet(opts->specified_opts, SUBOPT_ENABLED))
+ if (opts->enabled)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
/*- translator: both %s are strings of the form "option = value" */
errmsg("subscription with %s must also set %s",
"slot_name = NONE", "enabled = false")));

IMO the way these 'if' statements are written isn't super readable.
Right now, it's written like this:

if (opt && IsSet(someopt))
ereport(ERROR, ...);

if (otheropt && IsSet(someotheropt))
ereport(ERROR, ...);

if (opt)
ereport(ERROR, ...);

if (otheropt)
ereport(ERROR, ...);

I think it would be easier to understand if it was written more like
this:

if (opt)
{
if (IsSet(someopt))
ereport(ERROR, ...);
else
ereport(ERROR, ...);
}

if (otheropt)
{
if (IsSet(someotheropt))
ereport(ERROR, ...);
else
ereport(ERROR, ...);
}

Of course, this does result in a small behavior change because the
order of the checks is different, but I'm not sure that's a big deal.
Ultimately, it would probably be nice to report all the errors instead
of just the first one that is hit, but again, I don't know if that's
worth the effort.

I attached a new version of the patch with my suggestions. However, I
think v12 is committable.

Nathan

Attachment Content-Type Size
v13-0001-Simplify-recent-parse_subscription_option-change.patch application/octet-stream 8.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bossart, Nathan 2021-12-03 00:45:56 Re: should we document an example to set multiple libraries in shared_preload_libraries?
Previous Message Peter Smith 2021-12-02 23:55:19 Re: row filtering for logical replication