Re: Event trigger code comment duplication

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Event trigger code comment duplication
Date: 2020-05-13 05:15:05
Message-ID: 20200513051505.GL88791@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, May 12, 2020 at 06:48:51PM -0700, David G. Johnston wrote:
> Whether its a style thing, or some requirement of the C-language, I found
> it odd that the four nearly identical checks were left inline in the
> functions instead of being pulled out into a function. I've attached a
> conceptual patch that does just this and more clearly presents on my
> thoughts on the topic. In particular I tried to cleanup the quadruple
> negative sentence (and worse for the whole paragraph) as part of the
> refactoring of the currentEventTriggerState comment.

You may want to check that your code compiles first :)

+bool
+EventTriggerValidContext(bool requireState)
+{
[...]
- if (!IsUnderPostmaster)
- return;
+ if (!EventTriggerValidContext(true))
+ return
EventTriggerValidContext() should be static, and the code as written
simply would not compile.

+ if (requireState) {
+ /*
+ * Only move forward if our state is set up. This is required
+ * to handle concurrency - if we proceed, without state already set up,
+ * and allow EventTriggerCommonSetup to run it may find triggers that
+ * didn't exist when the command started.
+ */
+ if (!currentEventTriggerState)
+ return false;
+ }
Comment format and the if block don't have a format consistent with
the project.

+ /*
+ * See EventTriggerDDLCommandStart for a discussion about why event
+ * triggers are disabled in single user mode.
+ */
+ if (!IsUnderPostmaster)
+ return false;
And here I am pretty sure that you don't want to remove the
explanation why event triggers are disabled in standalone mode.

Note the reason why we don't expect a state being set for
ddl_command_start is present in EventTriggerBeginCompleteQuery():
/*
* Currently, sql_drop, table_rewrite, ddl_command_end events are the only
* reason to have event trigger state at all; so if there are none, don't
* install one.
*/

Even with all that, I am not sure that we need to complicate further
what we have here. An empty currentEventTriggerState gets checks in
three places, and each one of them has a slight different of the
reason why we cannot process further, so I would prefer applying my
previous, simple patch if there are no objections to remove the
duplication about event triggers with standalone mode, keeping the
explanations local to each event trigger type, and call it a day.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2020-05-13 05:18:38 Re: PG 13 release notes, first draft
Previous Message Dilip Kumar 2020-05-13 04:59:09 Re: Problem with logical replication