Re: Enumize logical replication message actions - Mailing list pgsql-hackers

From Ashutosh Bapat
Subject Re: Enumize logical replication message actions
Date
Msg-id CAG-ACPU2CuvedOF6_6=tGXWaQT=4Mfb6Pn2_rSyNuEx1XxG_JA@mail.gmail.com
Whole thread Raw
In response to Re: Enumize logical replication message actions  (Amit Kapila <amit.kapila16@gmail.com>)
Responses Re: Enumize logical replication message actions  (Amit Kapila <amit.kapila16@gmail.com>)
List pgsql-hackers


On Fri, 30 Oct 2020 at 09:16, Amit Kapila <amit.kapila16@gmail.com> wrote

1.
+ LOGICAL_REP_MSG_STREAM_ABORT = 'A',
+} LogicalRepMsgType;

There is no need for a comma after the last message.

Done. Thanks for noticing it. 
 
2.
+/*
+ * Logical message types
+ *
+ * Used by logical replication wire protocol.
+ *
+ * Note: though this is an enum it should fit a single byte and should be a
+ * printable character.
+ */
+typedef enum
+{

I think we can expand the comments to probably say why we need these
to fit in a single byte or what problem it can cause if that rule is
disobeyed. This is to make the next person clear why we are imposing
such a rule.

Done. Please check.
 

3.
+typedef enum
+{
..
+} LogicalRepMsgType;

There are places in code where we use the enum name
(LogicalRepMsgType) both in the start and end. See TypeCat,
CoercionMethod, CoercionCodes, etc. I see places where we use the way
you have in the code. I would prefer the way we have used at places
like TypeCat as that makes it easier to read.

Not my favourite style since changing the type name requires changing enum name to keep those consistent. But anyway done.
 

4.
  switch (action)
  {
- /* BEGIN */
- case 'B':
+ case LOGICAL_REP_MSG_BEGIN:
  apply_handle_begin(s);
- break;
- /* COMMIT */
- case 'C':
+ return;

I think we can simply use 'return apply_handle_begin;' instead of
adding return in another line. Again, I think we changed this handling
in apply_dispatch() to improve the case where we can detect at the
compile time any missing enum but at this stage it is not clear to me
if that is true.
 
I don't see much value in writing it like "return apply_handle_begin()"; gives an impression that apply_handle_begin() and apply_dispatch() are returning something which they are not. I would prefer return on separate line unless there's something more than style improvement.

I have added rationale behind Enum in the commit message as you suggested in one of the later mails.

PFA patch addressing your comments.
--
Best Wishes,
Ashutosh
Attachment

pgsql-hackers by date:

Previous
From: Jürgen Purtz
Date:
Subject: Re: Additional Chapter for Tutorial
Next
From: Ashutosh Bapat
Date:
Subject: Re: Enumize logical replication message actions