Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf106f53

Browse files
committed
Make invalid primary_slot_name follow standard GUC error reporting.
Previously, if primary_slot_name was set to an invalid slot name andthe configuration file was reloaded, both the postmaster and all otherbackend processes reported a WARNING. With many processes running,this could produce a flood of duplicate messages. The problem was thatthe GUC check hook for primary_slot_name reported errors at WARNINGlevel via ereport().This commit changes the check hook to use GUC_check_errdetail() andGUC_check_errhint() for error reporting. As with other GUC parameters,this causes non-postmaster processes to log the message at DEBUG3,so by default, only the postmaster's message appears in the log file.Backpatch to all supported versions.Author: Fujii Masao <masao.fujii@gmail.com>Reviewed-by: Chao Li <lic@highgo.com>Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>Discussion:https://postgr.es/m/CAHGQGwFud-cvthCTfusBfKHBS6Jj6kdAPTdLWKvP2qjUX6L_wA@mail.gmail.comBackpatch-through: 13
1 parenta7ab6ce commitf106f53

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

‎src/backend/replication/slot.c‎

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,31 +163,62 @@ ReplicationSlotsShmemInit(void)
163163
/*
164164
* Check whether the passed slot name is valid and report errors at elevel.
165165
*
166+
* See comments for ReplicationSlotValidateNameInternal().
167+
*/
168+
bool
169+
ReplicationSlotValidateName(constchar*name,intelevel)
170+
{
171+
interr_code;
172+
char*err_msg=NULL;
173+
char*err_hint=NULL;
174+
175+
if (!ReplicationSlotValidateNameInternal(name,&err_code,&err_msg,
176+
&err_hint))
177+
{
178+
ereport(elevel,
179+
errcode(err_code),
180+
errmsg_internal("%s",err_msg),
181+
(err_hint!=NULL) ?errhint("%s",err_hint) :0);
182+
183+
pfree(err_msg);
184+
if (err_hint!=NULL)
185+
pfree(err_hint);
186+
return false;
187+
}
188+
189+
return true;
190+
}
191+
192+
/*
193+
* Check whether the passed slot name is valid.
194+
*
166195
* Slot names may consist out of [a-z0-9_]{1,NAMEDATALEN-1} which should allow
167196
* the name to be used as a directory name on every supported OS.
168197
*
169-
* Returns whether the directory name is valid or not if elevel < ERROR.
198+
* Returns true if the slot name is valid. Otherwise, returns false and stores
199+
* the error code, error message, and optional hint in err_code, err_msg, and
200+
* err_hint, respectively. The caller is responsible for freeing err_msg and
201+
* err_hint, which are palloc'd.
170202
*/
171203
bool
172-
ReplicationSlotValidateName(constchar*name,intelevel)
204+
ReplicationSlotValidateNameInternal(constchar*name,int*err_code,
205+
char**err_msg,char**err_hint)
173206
{
174207
constchar*cp;
175208

176209
if (strlen(name)==0)
177210
{
178-
ereport(elevel,
179-
(errcode(ERRCODE_INVALID_NAME),
180-
errmsg("replication slot name \"%s\" is too short",
181-
name)));
211+
*err_code=ERRCODE_INVALID_NAME;
212+
*err_msg=psprintf(_("replication slot name \"%s\" is too short"),name);
213+
*err_hint=NULL;
182214
return false;
183215
}
184216

185217
if (strlen(name) >=NAMEDATALEN)
186218
{
187-
ereport(elevel,
188-
(errcode(ERRCODE_NAME_TOO_LONG),
189-
errmsg("replication slot name \"%s\" is too long",
190-
name)));
219+
*err_code=ERRCODE_NAME_TOO_LONG;
220+
*err_msg=psprintf(_("replication slot name \"%s\" is too long"),name);
221+
*err_hint=NULL;
191222
return false;
192223
}
193224

@@ -197,11 +228,9 @@ ReplicationSlotValidateName(const char *name, int elevel)
197228
|| (*cp >='0'&&*cp <='9')
198229
|| (*cp=='_')))
199230
{
200-
ereport(elevel,
201-
(errcode(ERRCODE_INVALID_NAME),
202-
errmsg("replication slot name \"%s\" contains invalid character",
203-
name),
204-
errhint("Replication slot names may only contain lower case letters, numbers, and the underscore character.")));
231+
*err_code=ERRCODE_INVALID_NAME;
232+
*err_msg=psprintf(_("replication slot name \"%s\" contains invalid character"),name);
233+
*err_hint=psprintf(_("Replication slot names may only contain lower case letters, numbers, and the underscore character."));
205234
return false;
206235
}
207236
}

‎src/backend/utils/misc/guc.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12587,9 +12587,20 @@ assign_recovery_target_lsn(const char *newval, void *extra)
1258712587
staticbool
1258812588
check_primary_slot_name(char**newval,void**extra,GucSourcesource)
1258912589
{
12590+
interr_code;
12591+
char*err_msg=NULL;
12592+
char*err_hint=NULL;
12593+
1259012594
if (*newval&&strcmp(*newval,"")!=0&&
12591-
!ReplicationSlotValidateName(*newval,WARNING))
12595+
!ReplicationSlotValidateNameInternal(*newval,&err_code,&err_msg,
12596+
&err_hint))
12597+
{
12598+
GUC_check_errcode(err_code);
12599+
GUC_check_errdetail("%s",err_msg);
12600+
if (err_hint!=NULL)
12601+
GUC_check_errhint("%s",err_hint);
1259212602
return false;
12603+
}
1259312604

1259412605
return true;
1259512606
}

‎src/include/replication/slot.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ extern void ReplicationSlotMarkDirty(void);
208208

209209
/* misc stuff */
210210
externboolReplicationSlotValidateName(constchar*name,intelevel);
211+
externboolReplicationSlotValidateNameInternal(constchar*name,
212+
int*err_code,char**err_msg,char**err_hint);
211213
externvoidReplicationSlotReserveWal(void);
212214
externvoidReplicationSlotsComputeRequiredXmin(boolalready_locked);
213215
externvoidReplicationSlotsComputeRequiredLSN(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp