Skip to content

Commit 448b6a4

Browse files
committed
Tidyup WARNING ereports in subscriptioncmds.c
A couple of ereports were making use of StringInfos as temporary storage for the portions of the WARNING message. One was doing this to avoid having 2 separate ereports. This was all fairly unnecessary and resulted in more code rather than less code. Refactor out the additional StringInfos and make check_publications_origin_tables() use 2 ereports. In passing, adjust pubnames to become a stack-allocated StringInfoData to avoid having to palloc the temporary StringInfoData. This follows on from the efforts made in 6d0eba6. Author: Mats Kindahl <[email protected]> Reviewed-by: David Rowley <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Reviewed-by: Álvaro Herrera <[email protected]> Discussion: https://postgr.es/m/0b381b02-cab9-41f9-a900-ad6c8d26c1fc%40gmail.com
1 parent a2b0229 commit 448b6a4

File tree

1 file changed

+26
-33
lines changed

1 file changed

+26
-33
lines changed

src/backend/commands/subscriptioncmds.c

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,33 +2599,30 @@ check_publications_origin_tables(WalReceiverConn *wrconn, List *publications,
25992599
*/
26002600
if (publist)
26012601
{
2602-
StringInfo pubnames = makeStringInfo();
2603-
StringInfo err_msg = makeStringInfo();
2604-
StringInfo err_hint = makeStringInfo();
2602+
StringInfoData pubnames;
26052603

26062604
/* Prepare the list of publication(s) for warning message. */
2607-
GetPublicationsStr(publist, pubnames, false);
2605+
initStringInfo(&pubnames);
2606+
GetPublicationsStr(publist, &pubnames, false);
26082607

26092608
if (check_table_sync)
2610-
{
2611-
appendStringInfo(err_msg, _("subscription \"%s\" requested copy_data with origin = NONE but might copy data that had a different origin"),
2612-
subname);
2613-
appendStringInfoString(err_hint, _("Verify that initial data copied from the publisher tables did not come from other origins."));
2614-
}
2609+
ereport(WARNING,
2610+
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2611+
errmsg("subscription \"%s\" requested copy_data with origin = NONE but might copy data that had a different origin",
2612+
subname),
2613+
errdetail_plural("The subscription subscribes to a publication (%s) that contains tables that are written to by other subscriptions.",
2614+
"The subscription subscribes to publications (%s) that contain tables that are written to by other subscriptions.",
2615+
list_length(publist), pubnames.data),
2616+
errhint("Verify that initial data copied from the publisher tables did not come from other origins."));
26152617
else
2616-
{
2617-
appendStringInfo(err_msg, _("subscription \"%s\" enabled retain_dead_tuples but might not reliably detect conflicts for changes from different origins"),
2618-
subname);
2619-
appendStringInfoString(err_hint, _("Consider using origin = NONE or disabling retain_dead_tuples."));
2620-
}
2621-
2622-
ereport(WARNING,
2623-
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2624-
errmsg_internal("%s", err_msg->data),
2625-
errdetail_plural("The subscription subscribes to a publication (%s) that contains tables that are written to by other subscriptions.",
2626-
"The subscription subscribes to publications (%s) that contain tables that are written to by other subscriptions.",
2627-
list_length(publist), pubnames->data),
2628-
errhint_internal("%s", err_hint->data));
2618+
ereport(WARNING,
2619+
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2620+
errmsg("subscription \"%s\" enabled retain_dead_tuples but might not reliably detect conflicts for changes from different origins",
2621+
subname),
2622+
errdetail_plural("The subscription subscribes to a publication (%s) that contains tables that are written to by other subscriptions.",
2623+
"The subscription subscribes to publications (%s) that contain tables that are written to by other subscriptions.",
2624+
list_length(publist), pubnames.data),
2625+
errhint("Consider using origin = NONE or disabling retain_dead_tuples."));
26292626
}
26302627

26312628
ExecDropSingleTupleTableSlot(slot);
@@ -2716,24 +2713,20 @@ check_publications_origin_sequences(WalReceiverConn *wrconn, List *publications,
27162713
*/
27172714
if (publist)
27182715
{
2719-
StringInfo pubnames = makeStringInfo();
2720-
StringInfo err_msg = makeStringInfo();
2721-
StringInfo err_hint = makeStringInfo();
2716+
StringInfoData pubnames;
27222717

27232718
/* Prepare the list of publication(s) for warning message. */
2724-
GetPublicationsStr(publist, pubnames, false);
2725-
2726-
appendStringInfo(err_msg, _("subscription \"%s\" requested copy_data with origin = NONE but might copy data that had a different origin"),
2727-
subname);
2728-
appendStringInfoString(err_hint, _("Verify that initial data copied from the publisher sequences did not come from other origins."));
2719+
initStringInfo(&pubnames);
2720+
GetPublicationsStr(publist, &pubnames, false);
27292721

27302722
ereport(WARNING,
27312723
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2732-
errmsg_internal("%s", err_msg->data),
2724+
errmsg("subscription \"%s\" requested copy_data with origin = NONE but might copy data that had a different origin",
2725+
subname),
27332726
errdetail_plural("The subscription subscribes to a publication (%s) that contains sequences that are written to by other subscriptions.",
27342727
"The subscription subscribes to publications (%s) that contain sequences that are written to by other subscriptions.",
2735-
list_length(publist), pubnames->data),
2736-
errhint_internal("%s", err_hint->data));
2728+
list_length(publist), pubnames.data),
2729+
errhint("Verify that initial data copied from the publisher sequences did not come from other origins."));
27372730
}
27382731

27392732
ExecDropSingleTupleTableSlot(slot);

0 commit comments

Comments
 (0)