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
fix_logical_slot_changes_funcs.patch
Description: Binary data