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

From Ashutosh Bapat
Subject Re: Enumize logical replication message actions
Date
Msg-id CAG-ACPWO_kxUPVj0XP3WD+XvoT-bQdif3_RgcesRpK2xy-Va0A@mail.gmail.com
Whole thread Raw
In response to Re: Enumize logical replication message actions  (Kyotaro Horiguchi <horikyota.ntt@gmail.com>)
Responses Re: Enumize logical replication message actions
Re: Enumize logical replication message actions
List pgsql-hackers


On Thu, 22 Oct 2020 at 14:46, Kyotaro Horiguchi <horikyota.ntt@gmail.com> wrote:


We shouldn't have the default: in the switch() block in
apply_dispatch(). That prevents compilers from checking
completeness. The content of the default: should be moved out to after
the switch() block.

apply_dispatch()
{
    switch (action)
        {
           ....
            case LOGICAL_REP_MSG_STREAM_COMMIT(s);
                   apply_handle_stream_commit(s);
                   return;
    }

    ereport(ERROR, ...);
}   

> 0002 adds wrappers on top of pq_sendbyte() and pq_getmsgbyte() to send and
> receive a logical replication message type respectively. These wrappers add
> more protection to make sure that the enum definitions fit one byte. This
> also removes the default case from apply_dispatch() so that we can detect
> any LogicalRepMsgType not handled by that function.

pg_send_logicalrep_msg_type() looks somewhat too-much.  If we need
something like that we shouldn't do this refactoring, I think.

Enum is an integer, and we want to send byte. The function asserts that the enum fits a byte. If there's a way to declare byte long enums I would use that. But I didn't find a way to do that.


pg_get_logicalrep_msg_type() seems doing the same check (that the
value is compared aganst every keyword value) with
apply_dispatch(). Why do we need that function separately from
apply_dispatch()?


The second patch removes the default case you quoted above. I think that's important to detect any unhandled case at compile time rather than at run time. But we need some way to detect whether the values we get from wire are legit. pg_get_logicalrep_msg_type() does that. Further that function can be used at places other than apply_dispatch() if required without each of those places having their own validation.

--
Best Wishes,
Ashutosh

pgsql-hackers by date:

Previous
From: Ashutosh Bapat
Date:
Subject: Re: Improper use about DatumGetInt32
Next
From: Amit Kapila
Date:
Subject: Re: Resetting spilled txn statistics in pg_stat_replication