Re: Gripes about walsender command processing

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Gripes about walsender command processing
Date: 2020-09-16 22:14:22
Message-ID: 20200916221422.GA24095@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2020-Sep-16, Tom Lane wrote:

> This looks moderately reasonable to me. However, with the process
> title reporting I want to add, we're going to end up with a switch
> that looks like
>
> case T_IdentifySystemCmd:
> + set_ps_display("IDENTIFY_SYSTEM");
> IdentifySystem();
> + EndReplicationCommand("IDENTIFY_SYSTEM");
> break;
>
> case T_BaseBackupCmd:
> + set_ps_display("BASE_BACKUP");
> PreventInTransactionBlock(true, "BASE_BACKUP");
> SendBaseBackup((BaseBackupCmd *) cmd_node);
> + EndReplicationCommand("BASE_BACKUP");
> break;
>
> which is starting to look a bit repetitive and copy-pasteo-prone.

Agreed.

> I don't see an easy way to improve on it though. The only obvious
> alternative would be to put another switch before the main one that
> just fills a "const char *cmdtag" variable, but that seems ugly.

The alternative of doing the assignment in each case of the same switch
does not look too terrible:

case T_IdentifySystemCmd:
+ cmdtag = "IDENTIFY_SYSTEM";
+ set_ps_display(cmdtag);
IdentifySystem();
+ EndReplicationCommand(cmdtag);
break;

case T_BaseBackupCmd:
+ cmdtag = "BASE_BACKUP";
+ set_ps_display(cmdtag);
PreventInTransactionBlock(true, cmdtag);
SendBaseBackup((BaseBackupCmd *) cmd_node);
+ EndReplicationCommand(cmdtag);
break;

--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2020-09-16 22:20:00 Re: DROP relation IF EXISTS Docs and Tests - Bug Fix
Previous Message Peter Geoghegan 2020-09-16 21:58:00 Re: PG 13 release notes, first draft