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

Commit6e1dd27

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 parentc6c3334 commit6e1dd27

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
@@ -182,7 +182,6 @@ static bool streamingDoneReceiving;
182182
staticboolWalSndCaughtUp= false;
183183

184184
/* Flags set by signal handlers for later service in main loop */
185-
staticvolatilesig_atomic_tgot_SIGHUP= false;
186185
staticvolatilesig_atomic_tgot_SIGUSR2= false;
187186
staticvolatilesig_atomic_tgot_STOPPING= false;
188187

@@ -218,7 +217,6 @@ static struct
218217
}LagTracker;
219218

220219
/* Signal handlers */
221-
staticvoidWalSndSigHupHandler(SIGNAL_ARGS);
222220
staticvoidWalSndLastCycleHandler(SIGNAL_ARGS);
223221

224222
/* Prototypes for private functions */
@@ -1201,9 +1199,9 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid,
12011199
CHECK_FOR_INTERRUPTS();
12021200

12031201
/* Process any requests or signals received recently */
1204-
if (got_SIGHUP)
1202+
if (ConfigReloadPending)
12051203
{
1206-
got_SIGHUP= false;
1204+
ConfigReloadPending= false;
12071205
ProcessConfigFile(PGC_SIGHUP);
12081206
SyncRepInitConfig();
12091207
}
@@ -1309,9 +1307,9 @@ WalSndWaitForWal(XLogRecPtr loc)
13091307
CHECK_FOR_INTERRUPTS();
13101308

13111309
/* Process any requests or signals received recently */
1312-
if (got_SIGHUP)
1310+
if (ConfigReloadPending)
13131311
{
1314-
got_SIGHUP= false;
1312+
ConfigReloadPending= false;
13151313
ProcessConfigFile(PGC_SIGHUP);
13161314
SyncRepInitConfig();
13171315
}
@@ -2101,9 +2099,9 @@ WalSndLoop(WalSndSendDataCallback send_data)
21012099
CHECK_FOR_INTERRUPTS();
21022100

21032101
/* Process any requests or signals received recently */
2104-
if (got_SIGHUP)
2102+
if (ConfigReloadPending)
21052103
{
2106-
got_SIGHUP= false;
2104+
ConfigReloadPending= false;
21072105
ProcessConfigFile(PGC_SIGHUP);
21082106
SyncRepInitConfig();
21092107
}
@@ -2908,19 +2906,6 @@ HandleWalSndInitStopping(void)
29082906
got_STOPPING= true;
29092907
}
29102908

2911-
/* SIGHUP: set flag to re-read config file at next convenient time */
2912-
staticvoid
2913-
WalSndSigHupHandler(SIGNAL_ARGS)
2914-
{
2915-
intsave_errno=errno;
2916-
2917-
got_SIGHUP= true;
2918-
2919-
SetLatch(MyLatch);
2920-
2921-
errno=save_errno;
2922-
}
2923-
29242909
/*
29252910
* SIGUSR2: set flag to do a last cycle and shut down afterwards. The WAL
29262911
* sender should already have been switched to WALSNDSTATE_STOPPING at
@@ -2942,7 +2927,7 @@ void
29422927
WalSndSignals(void)
29432928
{
29442929
/* Set up signal handlers */
2945-
pqsignal(SIGHUP,WalSndSigHupHandler);/* set flag to read config
2930+
pqsignal(SIGHUP,PostgresSigHupHandler);/* set flag to read config
29462931
* file */
29472932
pqsignal(SIGINT,SIG_IGN);/* not used */
29482933
pqsignal(SIGTERM,die);/* request shutdown */

‎src/backend/tcop/postgres.c

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

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

193185

@@ -2684,13 +2676,19 @@ FloatExceptionHandler(SIGNAL_ARGS)
26842676
"invalid operation, such as division by zero.")));
26852677
}
26862678

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

2693-
got_SIGHUP= true;
2691+
ConfigReloadPending= true;
26942692
SetLatch(MyLatch);
26952693

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

@@ -4046,9 +4044,9 @@ PostgresMain(int argc, char *argv[],
40464044
* (6) check for any other interesting events that happened while we
40474045
* slept.
40484046
*/
4049-
if (got_SIGHUP)
4047+
if (ConfigReloadPending)
40504048
{
4051-
got_SIGHUP= false;
4049+
ConfigReloadPending= false;
40524050
ProcessConfigFile(PGC_SIGHUP);
40534051
}
40544052

‎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

@@ -273,6 +276,8 @@ extern void restore_stack_base(pg_stack_base_t base);
273276
externvoidcheck_stack_depth(void);
274277
externboolstack_is_too_deep(void);
275278

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp