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

Commit45d067d

Browse files
committed
Unify SIGHUP handling between normal and walsender backends.
Because walsender and normal backends share the same main loop it'sproblematic to have two different flag variables, set in signalhandlers, indicating a pending configuration reload. Only certainwalsender commands reach code paths checking for thevariable (START_[LOGICAL_]REPLICATION, CREATE_REPLICATION_SLOT... LOGICAL, notably not base backups).This is a bug present since the introduction of walsender, but hasgotten worse in releases since then which allow walsender to do more.A later patch, not slated for v10, will similarly unify SIGHUPhandling in other types of processes as well.Author: Petr Jelinek, Andres FreundReviewed-By: Michael PaquierDiscussion:https://postgr.es/m/20170423235941.qosiuoyqprq4nu7v@alap3.anarazel.deBackpatch: 9.2-, bug is present since 9.0
1 parentda30fa6 commit45d067d

File tree

4 files changed

+23
-33
lines changed

4 files changed

+23
-33
lines changed

‎src/backend/replication/walsender.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ static volatile sig_atomic_t walsender_ready_to_stop = false;
166166
staticvolatilesig_atomic_treplication_active= false;
167167

168168
/* Signal handlers */
169-
staticvoidWalSndSigHupHandler(SIGNAL_ARGS);
170169
staticvoidWalSndXLogSendHandler(SIGNAL_ARGS);
171170
staticvoidWalSndLastCycleHandler(SIGNAL_ARGS);
172171

@@ -979,9 +978,9 @@ WalSndLoop(void)
979978
exit(1);
980979

981980
/* Process any requests or signals received recently */
982-
if (got_SIGHUP)
981+
if (ConfigReloadPending)
983982
{
984-
got_SIGHUP= false;
983+
ConfigReloadPending= false;
985984
ProcessConfigFile(PGC_SIGHUP);
986985
SyncRepInitConfig();
987986
}
@@ -1712,19 +1711,6 @@ WalSndRqstFileReload(void)
17121711
}
17131712
}
17141713

1715-
/* SIGHUP: set flag to re-read config file at next convenient time */
1716-
staticvoid
1717-
WalSndSigHupHandler(SIGNAL_ARGS)
1718-
{
1719-
intsave_errno=errno;
1720-
1721-
got_SIGHUP= true;
1722-
if (MyWalSnd)
1723-
SetLatch(&MyWalSnd->latch);
1724-
1725-
errno=save_errno;
1726-
}
1727-
17281714
/* SIGUSR1: set flag to send WAL records */
17291715
staticvoid
17301716
WalSndXLogSendHandler(SIGNAL_ARGS)
@@ -1763,7 +1749,7 @@ void
17631749
WalSndSignals(void)
17641750
{
17651751
/* Set up signal handlers */
1766-
pqsignal(SIGHUP,WalSndSigHupHandler);/* set flag to read config
1752+
pqsignal(SIGHUP,PostgresSigHupHandler);/* set flag to read config
17671753
* file */
17681754
pqsignal(SIGINT,SIG_IGN);/* not used */
17691755
pqsignal(SIGTERM,die);/* request shutdown */

‎src/backend/tcop/postgres.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ char *stack_base_ptr = NULL;
130130
char*register_stack_base_ptr=NULL;
131131
#endif
132132

133-
/*
134-
* Flag to mark SIGHUP. Whenever the main loop comes around it
135-
* will reread the configuration file. (Better than doing the
136-
* reading in the signal handler, ey?)
137-
*/
138-
staticvolatilesig_atomic_tgot_SIGHUP= false;
139-
140133
/*
141134
* Flag to keep track of whether we have started a transaction.
142135
* For extended query protocol this has to be remembered across messages.
@@ -205,7 +198,6 @@ static bool IsTransactionExitStmt(Node *parsetree);
205198
staticboolIsTransactionExitStmtList(List*parseTrees);
206199
staticboolIsTransactionStmtList(List*parseTrees);
207200
staticvoiddrop_unnamed_stmt(void);
208-
staticvoidSigHupHandler(SIGNAL_ARGS);
209201
staticvoidlog_disconnections(intcode,Datumarg);
210202

211203

@@ -2685,13 +2677,19 @@ FloatExceptionHandler(SIGNAL_ARGS)
26852677
"invalid operation, such as division by zero.")));
26862678
}
26872679

2688-
/* SIGHUP: set flag to re-read config file at next convenient time */
2689-
staticvoid
2690-
SigHupHandler(SIGNAL_ARGS)
2680+
/*
2681+
* SIGHUP: set flag to re-read config file at next convenient time.
2682+
*
2683+
* Sets the ConfigReloadPending flag, which should be checked at convenient
2684+
* places inside main loops. (Better than doing the reading in the signal
2685+
* handler, ey?)
2686+
*/
2687+
void
2688+
PostgresSigHupHandler(SIGNAL_ARGS)
26912689
{
26922690
intsave_errno=errno;
26932691

2694-
got_SIGHUP= true;
2692+
ConfigReloadPending= true;
26952693
if (MyProc)
26962694
SetLatch(&MyProc->procLatch);
26972695

@@ -3683,8 +3681,8 @@ PostgresMain(int argc, char *argv[],
36833681
WalSndSignals();
36843682
else
36853683
{
3686-
pqsignal(SIGHUP,SigHupHandler);/* set flag to read config
3687-
* file */
3684+
pqsignal(SIGHUP,PostgresSigHupHandler);/* set flag to read config
3685+
* file */
36883686
pqsignal(SIGINT,StatementCancelHandler);/* cancel current query */
36893687
pqsignal(SIGTERM,die);/* cancel current query and exit */
36903688

@@ -4062,9 +4060,9 @@ PostgresMain(int argc, char *argv[],
40624060
* (5) check for any other interesting events that happened while we
40634061
* slept.
40644062
*/
4065-
if (got_SIGHUP)
4063+
if (ConfigReloadPending)
40664064
{
4067-
got_SIGHUP= false;
4065+
ConfigReloadPending= false;
40684066
ProcessConfigFile(PGC_SIGHUP);
40694067
}
40704068

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ volatile bool QueryCancelPending = false;
3030
volatileboolProcDiePending= false;
3131
volatileboolClientConnectionLost= false;
3232
volatileboolImmediateInterruptOK= false;
33+
volatilesig_atomic_tConfigReloadPending= false;
3334
volatileuint32InterruptHoldoffCount=0;
3435
volatileuint32QueryCancelHoldoffCount=0;
3536
volatileuint32CritSectionCount=0;

‎src/include/miscadmin.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#ifndefMISCADMIN_H
2424
#defineMISCADMIN_H
2525

26+
#include<signal.h>
27+
2628
#include"pgtime.h"/* for pg_time_t */
2729

2830

@@ -78,6 +80,7 @@
7880
externPGDLLIMPORTvolatileboolInterruptPending;
7981
externvolatileboolQueryCancelPending;
8082
externvolatileboolProcDiePending;
83+
externPGDLLIMPORTvolatilesig_atomic_tConfigReloadPending;
8184

8285
externvolatileboolClientConnectionLost;
8386

@@ -276,6 +279,8 @@ extern void restore_stack_base(pg_stack_base_t base);
276279
externvoidcheck_stack_depth(void);
277280
externboolstack_is_too_deep(void);
278281

282+
externvoidPostgresSigHupHandler(SIGNAL_ARGS);
283+
279284
/* in tcop/utility.c */
280285
externvoidPreventCommandIfReadOnly(constchar*cmdname);
281286
externvoidPreventCommandDuringRecovery(constchar*cmdname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp