Refactor StringInfo usage in subscriptioncmds.c

Started by Mats Kindahlabout 1 year ago7 messageshackers
Jump to latest
#1Mats Kindahl
mats.kindahl@gmail.com

Hi all,

As discussed in [1]/messages/by-id/CAApHDvrZnM28wa2VY58cvtY0y9XbMhKJH4m=ga3c1wfsx=MF4Q@mail.gmail.com the functions check_publications_origin_tables() and
check_publications_origin_sequences() are building error messages using
dynamically allocated StringInfo instances only to avoid duplicating a
call of ereport().

Attached is a proposal that instead of building error message and hints
dynamically, it will use ereport() directly and as a result does not
have to allocate the error message strings and error message hints
dynamically and these can be removed.

This also means that a previous use of gettext() (in the form of the "_"
macro) is not needed any more and we can use errmsg() and errhint()
rather than errmsg_internal() and errhint_internal() with ereport().

It also replaces the usage a dynamically allocated StringInfo of
pubnames containing the publication names with a stack allocated
StringInfoData, along the same line as in [2]/messages/by-id/CAApHDvrZnM28wa2VY58cvtY0y9XbMhKJH4m=ga3c1wfsx=MF4Q@mail.gmail.com.

[1]: /messages/by-id/CAApHDvrZnM28wa2VY58cvtY0y9XbMhKJH4m=ga3c1wfsx=MF4Q@mail.gmail.com
/messages/by-id/CAApHDvrZnM28wa2VY58cvtY0y9XbMhKJH4m=ga3c1wfsx=MF4Q@mail.gmail.com

[2]: /messages/by-id/CAApHDvrZnM28wa2VY58cvtY0y9XbMhKJH4m=ga3c1wfsx=MF4Q@mail.gmail.com
/messages/by-id/CAApHDvrZnM28wa2VY58cvtY0y9XbMhKJH4m=ga3c1wfsx=MF4Q@mail.gmail.com

Attachments:

0001-Refactor-StringInfo-usage-in-subscriptioncmds.c.v1.patchtext/x-patch; charset=UTF-8; name=0001-Refactor-StringInfo-usage-in-subscriptioncmds.c.v1.patchDownload+28-34
#2David Rowley
dgrowleyml@gmail.com
In reply to: Mats Kindahl (#1)
Re: Refactor StringInfo usage in subscriptioncmds.c

On Fri, 7 Nov 2025 at 00:38, Mats Kindahl <mats.kindahl@gmail.com> wrote:

As discussed in [1] the functions check_publications_origin_tables() and
check_publications_origin_sequences() are building error messages using
dynamically allocated StringInfo instances only to avoid duplicating a
call of ereport().

Looks better and more traditional to me, plus git diff --stat reports:

1 file changed, 28 insertions(+), 33 deletions(-)

It has my vote. I've included Vignesh and Amit to see if they're also
ok with it.

David

#3Amit Kapila
amit.kapila16@gmail.com
In reply to: David Rowley (#2)
Re: Refactor StringInfo usage in subscriptioncmds.c

On Thu, Nov 6, 2025 at 5:24 PM David Rowley <dgrowleyml@gmail.com> wrote:

On Fri, 7 Nov 2025 at 00:38, Mats Kindahl <mats.kindahl@gmail.com> wrote:

As discussed in [1] the functions check_publications_origin_tables() and
check_publications_origin_sequences() are building error messages using
dynamically allocated StringInfo instances only to avoid duplicating a
call of ereport().

Looks better and more traditional to me, plus git diff --stat reports:

1 file changed, 28 insertions(+), 33 deletions(-)

It has my vote. I've included Vignesh and Amit to see if they're also
ok with it.

LGTM as well. We can avoid doing pfree(pubnames.data) as it is not
allocated in any long term context but I am fine if we want to do it
as there are places where we do such retail pfree as well.

--
With Regards,
Amit Kapila.

#4Mats Kindahl
mats.kindahl@gmail.com
In reply to: Amit Kapila (#3)
Re: Refactor StringInfo usage in subscriptioncmds.c

On 11/6/25 13:09, Amit Kapila wrote:

On Thu, Nov 6, 2025 at 5:24 PM David Rowley <dgrowleyml@gmail.com> wrote:

On Fri, 7 Nov 2025 at 00:38, Mats Kindahl <mats.kindahl@gmail.com> wrote:

As discussed in [1] the functions check_publications_origin_tables() and
check_publications_origin_sequences() are building error messages using
dynamically allocated StringInfo instances only to avoid duplicating a
call of ereport().

Looks better and more traditional to me, plus git diff --stat reports:

1 file changed, 28 insertions(+), 33 deletions(-)

It has my vote. I've included Vignesh and Amit to see if they're also
ok with it.

LGTM as well. We can avoid doing pfree(pubnames.data) as it is not
allocated in any long term context but I am fine if we want to do it
as there are places where we do such retail pfree as well.

I have no strong opinion either way, but since it is not needed and it
is not a frequent call it seemed prudent to free it after.

Best wishes,
Mats Kindahl

#5Alvaro Herrera
alvherre@kurilemu.de
In reply to: Mats Kindahl (#1)
Re: Refactor StringInfo usage in subscriptioncmds.c

On 2025-Nov-06, Mats Kindahl wrote:

Attached is a proposal that instead of building error message and hints
dynamically, it will use ereport() directly and as a result does not have to
allocate the error message strings and error message hints dynamically and
these can be removed.

LGTM, thanks.

I agree with Amit that there doesn't seem to be a need to free
pubnames.data. We're already leaking publist, for instance. This is
okay since we only call these functions during DDL, which in general is
not sensitive to leaks.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"Small aircraft do not crash frequently ... usually only once!"
(ponder, http://thedailywtf.com/)

#6Mats Kindahl
mats.kindahl@gmail.com
In reply to: Alvaro Herrera (#5)
Re: Refactor StringInfo usage in subscriptioncmds.c

On 11/6/25 13:40, Álvaro Herrera wrote:

On 2025-Nov-06, Mats Kindahl wrote:

Attached is a proposal that instead of building error message and hints
dynamically, it will use ereport() directly and as a result does not have to
allocate the error message strings and error message hints dynamically and
these can be removed.

LGTM, thanks.

I agree with Amit that there doesn't seem to be a need to free
pubnames.data. We're already leaking publist, for instance. This is
okay since we only call these functions during DDL, which in general is
not sensitive to leaks.

Seems reasonable. Here is an updated version that removes the pfree() calls.

Best wishes,
Mats Kindahl

Attachments:

0001-Refactor-StringInfo-usage-in-subscriptioncmds.c.v2.patchtext/x-patch; charset=UTF-8; name=0001-Refactor-StringInfo-usage-in-subscriptioncmds.c.v2.patchDownload+25-34
#7David Rowley
dgrowleyml@gmail.com
In reply to: Mats Kindahl (#6)
Re: Refactor StringInfo usage in subscriptioncmds.c

On Fri, 7 Nov 2025 at 01:47, Mats Kindahl <mats.kindahl@gmail.com> wrote:

I agree with Amit that there doesn't seem to be a need to free
pubnames.data. We're already leaking publist, for instance. This is
okay since we only call these functions during DDL, which in general is
not sensitive to leaks.

Seems reasonable. Here is an updated version that removes the pfree() calls.

Sounds like all are in favour. Pushed.

David