Upper limit arguments of pg_logical_slot_xxx_changes functions acceptinvalid values - Mailing list pgsql-hackers

From Masahiko Sawada
Subject Upper limit arguments of pg_logical_slot_xxx_changes functions acceptinvalid values
Date
Msg-id CAD21AoByngb7O=_zdDG_HjZDHtE1W6Ka0mRZJmQLkpzWoFoCkQ@mail.gmail.com
Whole thread Raw
Responses Re: Upper limit arguments of pg_logical_slot_xxx_changes functionsaccept invalid values  (Brian Faherty <anothergenericuser@gmail.com>)
Re: Upper limit arguments of pg_logical_slot_xxx_changes functionsaccept invalid values  (Michael Paquier <michael@paquier.xyz>)
Re: Upper limit arguments of pg_logical_slot_xxx_changes functionsaccept invalid values  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Hi,

While reading the replication slot codes, I found a wrong assignment
in pg_logical_slot_get_changes_guts() function as follows.

        if (PG_ARGISNULL(2))
               upto_nchanges = InvalidXLogRecPtr;
        else
                upto_nchanges = PG_GETARG_INT32(2);

Since the upto_nchanges is an integer value we should set 0 meaning
unlimited instead of InvalidXLogRecPtr. Since InvalidXLogRecPtr is
actually 0 this function works fine so far. Also I surprised that
these functions accept to set negative values to upto_nchanges.  The
upto_lsn argument is also the same; it also accepts an invalid lsn.
For safety maybe it's better to reject non-NULL invalid values.That
way, the behavior of these functions are consistent with what the
documentation says;

  If upto_lsn is non-NULL, decoding will include only those
transactions which commit prior to the specified LSN. If upto_nchanges
is non-NULL, decoding will stop when the number of rows produced by
decoding exceeds the specified value.

Attached patch fixes them. Feedback is very welcome.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachment

pgsql-hackers by date:

Previous
From: Nico Williams
Date:
Subject: Re: [HACKERS] [PATCH] WIP Add ALWAYS DEFERRED option for constraints
Next
From: "Tsunakawa, Takayuki"
Date:
Subject: RE: How can we submit code patches that implement our (pending)patents?