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

Commitb8bd32a

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 parent862204a commitb8bd32a

File tree

4 files changed

+27
-38
lines changed

4 files changed

+27
-38
lines changed

‎src/backend/replication/walsender.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static bool streamingDoneReceiving;
176176
staticboolWalSndCaughtUp= false;
177177

178178
/* Flags set by signal handlers for later service in main loop */
179-
staticvolatilesig_atomic_tgot_SIGHUP= false;
180179
staticvolatilesig_atomic_tgot_SIGUSR2= false;
181180
staticvolatilesig_atomic_tgot_STOPPING= false;
182181

@@ -192,7 +191,6 @@ static LogicalDecodingContext *logical_decoding_ctx = NULL;
192191
staticXLogRecPtrlogical_startptr=InvalidXLogRecPtr;
193192

194193
/* Signal handlers */
195-
staticvoidWalSndSigHupHandler(SIGNAL_ARGS);
196194
staticvoidWalSndLastCycleHandler(SIGNAL_ARGS);
197195

198196
/* Prototypes for private functions */
@@ -1119,9 +1117,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
11191117
CHECK_FOR_INTERRUPTS();
11201118

11211119
/* Process any requests or signals received recently */
1122-
if (got_SIGHUP)
1120+
if (ConfigReloadPending)
11231121
{
1124-
got_SIGHUP= false;
1122+
ConfigReloadPending= false;
11251123
ProcessConfigFile(PGC_SIGHUP);
11261124
SyncRepInitConfig();
11271125
}
@@ -1202,9 +1200,9 @@ WalSndWaitForWal(XLogRecPtr loc)
12021200
CHECK_FOR_INTERRUPTS();
12031201

12041202
/* Process any requests or signals received recently */
1205-
if (got_SIGHUP)
1203+
if (ConfigReloadPending)
12061204
{
1207-
got_SIGHUP= false;
1205+
ConfigReloadPending= false;
12081206
ProcessConfigFile(PGC_SIGHUP);
12091207
SyncRepInitConfig();
12101208
}
@@ -1857,9 +1855,9 @@ WalSndLoop(WalSndSendDataCallback send_data)
18571855
CHECK_FOR_INTERRUPTS();
18581856

18591857
/* Process any requests or signals received recently */
1860-
if (got_SIGHUP)
1858+
if (ConfigReloadPending)
18611859
{
1862-
got_SIGHUP= false;
1860+
ConfigReloadPending= false;
18631861
ProcessConfigFile(PGC_SIGHUP);
18641862
SyncRepInitConfig();
18651863
}
@@ -2628,19 +2626,6 @@ HandleWalSndInitStopping(void)
26282626
got_STOPPING= true;
26292627
}
26302628

2631-
/* SIGHUP: set flag to re-read config file at next convenient time */
2632-
staticvoid
2633-
WalSndSigHupHandler(SIGNAL_ARGS)
2634-
{
2635-
intsave_errno=errno;
2636-
2637-
got_SIGHUP= true;
2638-
2639-
SetLatch(MyLatch);
2640-
2641-
errno=save_errno;
2642-
}
2643-
26442629
/*
26452630
* SIGUSR2: set flag to do a last cycle and shut down afterwards. The WAL
26462631
* sender should already have been switched to WALSNDSTATE_STOPPING at
@@ -2662,7 +2647,7 @@ void
26622647
WalSndSignals(void)
26632648
{
26642649
/* Set up signal handlers */
2665-
pqsignal(SIGHUP,WalSndSigHupHandler);/* set flag to read config
2650+
pqsignal(SIGHUP,PostgresSigHupHandler);/* set flag to read config
26662651
* file */
26672652
pqsignal(SIGINT,SIG_IGN);/* not used */
26682653
pqsignal(SIGTERM,die);/* request shutdown */

‎src/backend/tcop/postgres.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ char *stack_base_ptr = NULL;
121121
char*register_stack_base_ptr=NULL;
122122
#endif
123123

124-
/*
125-
* Flag to mark SIGHUP. Whenever the main loop comes around it
126-
* will reread the configuration file. (Better than doing the
127-
* reading in the signal handler, ey?)
128-
*/
129-
staticvolatilesig_atomic_tgot_SIGHUP= false;
130-
131124
/*
132125
* Flag to keep track of whether we have started a transaction.
133126
* For extended query protocol this has to be remembered across messages.
@@ -186,7 +179,6 @@ static bool IsTransactionExitStmt(Node *parsetree);
186179
staticboolIsTransactionExitStmtList(List*parseTrees);
187180
staticboolIsTransactionStmtList(List*parseTrees);
188181
staticvoiddrop_unnamed_stmt(void);
189-
staticvoidSigHupHandler(SIGNAL_ARGS);
190182
staticvoidlog_disconnections(intcode,Datumarg);
191183

192184

@@ -2689,13 +2681,19 @@ FloatExceptionHandler(SIGNAL_ARGS)
26892681
"invalid operation, such as division by zero.")));
26902682
}
26912683

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

2698-
got_SIGHUP= true;
2696+
ConfigReloadPending= true;
26992697
SetLatch(MyLatch);
27002698

27012699
errno=save_errno;
@@ -3633,8 +3631,8 @@ PostgresMain(int argc, char *argv[],
36333631
WalSndSignals();
36343632
else
36353633
{
3636-
pqsignal(SIGHUP,SigHupHandler);/* set flag to read config
3637-
* file */
3634+
pqsignal(SIGHUP,PostgresSigHupHandler);/* set flag to read config
3635+
* file */
36383636
pqsignal(SIGINT,StatementCancelHandler);/* cancel current query */
36393637
pqsignal(SIGTERM,die);/* cancel current query and exit */
36403638

@@ -4045,9 +4043,9 @@ PostgresMain(int argc, char *argv[],
40454043
* (6) check for any other interesting events that happened while we
40464044
* slept.
40474045
*/
4048-
if (got_SIGHUP)
4046+
if (ConfigReloadPending)
40494047
{
4050-
got_SIGHUP= false;
4048+
ConfigReloadPending= false;
40514049
ProcessConfigFile(PGC_SIGHUP);
40524050
}
40534051

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ volatile bool QueryCancelPending = false;
3131
volatileboolProcDiePending= false;
3232
volatileboolClientConnectionLost= false;
3333
volatileboolIdleInTransactionSessionTimeoutPending= false;
34+
volatilesig_atomic_tConfigReloadPending= false;
3435
volatileuint32InterruptHoldoffCount=0;
3536
volatileuint32QueryCancelHoldoffCount=0;
3637
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

@@ -81,6 +83,7 @@ extern PGDLLIMPORT volatile bool InterruptPending;
8183
externPGDLLIMPORTvolatileboolQueryCancelPending;
8284
externPGDLLIMPORTvolatileboolProcDiePending;
8385
externPGDLLIMPORTvolatileboolIdleInTransactionSessionTimeoutPending;
86+
externPGDLLIMPORTvolatilesig_atomic_tConfigReloadPending;
8487

8588
externvolatileboolClientConnectionLost;
8689

@@ -272,6 +275,8 @@ extern void restore_stack_base(pg_stack_base_t base);
272275
externvoidcheck_stack_depth(void);
273276
externboolstack_is_too_deep(void);
274277

278+
externvoidPostgresSigHupHandler(SIGNAL_ARGS);
279+
275280
/* in tcop/utility.c */
276281
externvoidPreventCommandIfReadOnly(constchar*cmdname);
277282
externvoidPreventCommandIfParallelMode(constchar*cmdname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp