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

Commit4a9c30a

Browse files
committed
Fix management of pendingOpsTable in auxiliary processes.
mdinit() was misusing IsBootstrapProcessingMode() to decide whether tocreate an fsync pending-operations table in the current process. This ledto creating a table not only in the startup and checkpointer processes asintended, but also in the bgwriter process, not to mention other auxiliaryprocesses such as walwriter and walreceiver. Creation of the table in thebgwriter is fatal, because it absorbs fsync requests that should have goneto the checkpointer; instead they just sit in bgwriter local memory and arenever acted on. So writes performed by the bgwriter were not being fsync'dwhich could result in data loss after an OS crash. I think there is nolive bug with respect to walwriter and walreceiver because those neverperform any writes of shared buffers; but the potential is there forfuture breakage in those processes too.To fix, make AuxiliaryProcessMain() export the current process'sAuxProcType as a global variable, and then make mdinit() test directly forthe types of aux process that should have a pendingOpsTable. Having donethat, we might as well also get rid of the random bool flags such asam_walreceiver that some of the aux processes had grown. (Note that wecould not have fixed the bug by examining those variables in mdinit(),because it's called from BaseInit() which is run by AuxiliaryProcessMain()before entering any of the process-type-specific code.)Back-patch to 9.2, where the problem was introduced by the split-up ofbgwriter and checkpointer processes. The bogus pendingOpsTable existsin walwriter and walreceiver processes in earlier branches, but absentany evidence that it causes actual problems there, I'll leave the olderbranches alone.
1 parent3855968 commit4a9c30a

File tree

11 files changed

+62
-57
lines changed

11 files changed

+62
-57
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8946,7 +8946,7 @@ get_sync_bit(int method)
89468946
* after its written. Also, walreceiver performs unaligned writes, which
89478947
* don't work with O_DIRECT, so it is required for correctness too.
89488948
*/
8949-
if (!XLogIsNeeded()&& !am_walreceiver)
8949+
if (!XLogIsNeeded()&& !AmWalReceiverProcess())
89508950
o_direct_flag=PG_O_DIRECT;
89518951

89528952
switch (method)

‎src/backend/bootstrap/bootstrap.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static void cleanup(void);
6363
* ----------------
6464
*/
6565

66+
AuxProcTypeMyAuxProcType=NotAnAuxProcess;/* declared in miscadmin.h */
67+
6668
Relationboot_reldesc;/* current relation descriptor */
6769

6870
Form_pg_attributeattrtypes[MAXATTR];/* points to attribute info */
@@ -187,7 +189,6 @@ AuxiliaryProcessMain(int argc, char *argv[])
187189
{
188190
char*progname=argv[0];
189191
intflag;
190-
AuxProcTypeauxType=CheckerProcess;
191192
char*userDoption=NULL;
192193

193194
/*
@@ -228,6 +229,9 @@ AuxiliaryProcessMain(int argc, char *argv[])
228229
argc--;
229230
}
230231

232+
/* If no -x argument, we are a CheckerProcess */
233+
MyAuxProcType=CheckerProcess;
234+
231235
while ((flag=getopt(argc,argv,"B:c:d:D:Fr:x:-:"))!=-1)
232236
{
233237
switch (flag)
@@ -258,7 +262,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
258262
strlcpy(OutputFileName,optarg,MAXPGPATH);
259263
break;
260264
case'x':
261-
auxType=atoi(optarg);
265+
MyAuxProcType=atoi(optarg);
262266
break;
263267
case'c':
264268
case'-':
@@ -308,7 +312,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
308312
{
309313
constchar*statmsg;
310314

311-
switch (auxType)
315+
switch (MyAuxProcType)
312316
{
313317
caseStartupProcess:
314318
statmsg="startup process";
@@ -374,15 +378,15 @@ AuxiliaryProcessMain(int argc, char *argv[])
374378
/*
375379
* Assign the ProcSignalSlot for an auxiliary process.Since it
376380
* doesn't have a BackendId, the slot is statically allocated based on
377-
* the auxiliary process type (auxType). Backends use slots indexed
378-
* in the range from 1 to MaxBackends (inclusive), so we use
381+
* the auxiliary process type (MyAuxProcType). Backends use slots
382+
*indexedin the range from 1 to MaxBackends (inclusive), so we use
379383
* MaxBackends + AuxProcType + 1 as the index of the slot for an
380384
* auxiliary process.
381385
*
382386
* This will need rethinking if we ever want more than one of a
383387
* particular auxiliary process type.
384388
*/
385-
ProcSignalInit(MaxBackends+auxType+1);
389+
ProcSignalInit(MaxBackends+MyAuxProcType+1);
386390

387391
/* finish setting up bufmgr.c */
388392
InitBufferPoolBackend();
@@ -396,7 +400,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
396400
*/
397401
SetProcessingMode(NormalProcessing);
398402

399-
switch (auxType)
403+
switch (MyAuxProcType)
400404
{
401405
caseCheckerProcess:
402406
/* don't set signals, they're useless here */
@@ -436,7 +440,7 @@ AuxiliaryProcessMain(int argc, char *argv[])
436440
proc_exit(1);/* should never return */
437441

438442
default:
439-
elog(PANIC,"unrecognized process type: %d",auxType);
443+
elog(PANIC,"unrecognized process type: %d",(int)MyAuxProcType);
440444
proc_exit(1);
441445
}
442446
}

‎src/backend/postmaster/bgwriter.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ intBgWriterDelay = 200;
7474
staticvolatilesig_atomic_tgot_SIGHUP= false;
7575
staticvolatilesig_atomic_tshutdown_requested= false;
7676

77-
/*
78-
* Private state
79-
*/
80-
staticboolam_bg_writer= false;
81-
8277
/* Signal handlers */
8378

8479
staticvoidbg_quickdie(SIGNAL_ARGS);
@@ -90,8 +85,8 @@ static void bgwriter_sigusr1_handler(SIGNAL_ARGS);
9085
/*
9186
* Main entry point for bgwriter process
9287
*
93-
* This is invoked fromBootstrapMain, which has already created the basic
94-
* execution environment, but not enabled signals yet.
88+
* This is invoked fromAuxiliaryProcessMain, which has already created the
89+
*basicexecution environment, but not enabled signals yet.
9590
*/
9691
void
9792
BackgroundWriterMain(void)
@@ -100,8 +95,6 @@ BackgroundWriterMain(void)
10095
MemoryContextbgwriter_context;
10196
boolprev_hibernate;
10297

103-
am_bg_writer= true;
104-
10598
/*
10699
* If possible, make this process a group leader, so that the postmaster
107100
* can signal any child processes too.(bgwriter probably never has any

‎src/backend/postmaster/checkpointer.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ static volatile sig_atomic_t shutdown_requested = false;
153153
/*
154154
* Private state
155155
*/
156-
staticboolam_checkpointer= false;
157-
158156
staticboolckpt_active= false;
159157

160158
/* these values are valid when ckpt_active is true: */
@@ -185,8 +183,8 @@ static void ReqShutdownHandler(SIGNAL_ARGS);
185183
/*
186184
* Main entry point for checkpointer process
187185
*
188-
* This is invoked fromBootstrapMain, which has already created the basic
189-
* execution environment, but not enabled signals yet.
186+
* This is invoked fromAuxiliaryProcessMain, which has already created the
187+
*basicexecution environment, but not enabled signals yet.
190188
*/
191189
void
192190
CheckpointerMain(void)
@@ -195,7 +193,6 @@ CheckpointerMain(void)
195193
MemoryContextcheckpointer_context;
196194

197195
CheckpointerShmem->checkpointer_pid=MyProcPid;
198-
am_checkpointer= true;
199196

200197
/*
201198
* If possible, make this process a group leader, so that the postmaster
@@ -685,7 +682,7 @@ CheckpointWriteDelay(int flags, double progress)
685682
staticintabsorb_counter=WRITES_PER_ABSORB;
686683

687684
/* Do nothing if checkpoint is being executed by non-checkpointer process */
688-
if (!am_checkpointer)
685+
if (!AmCheckpointerProcess())
689686
return;
690687

691688
/*
@@ -1129,7 +1126,7 @@ ForwardFsyncRequest(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
11291126
if (!IsUnderPostmaster)
11301127
return false;/* probably shouldn't even get here */
11311128

1132-
if (am_checkpointer)
1129+
if (AmCheckpointerProcess())
11331130
elog(ERROR,"ForwardFsyncRequest must not be called in checkpointer");
11341131

11351132
LWLockAcquire(CheckpointerCommLock,LW_EXCLUSIVE);
@@ -1306,7 +1303,7 @@ AbsorbFsyncRequests(void)
13061303
CheckpointerRequest*request;
13071304
intn;
13081305

1309-
if (!am_checkpointer)
1306+
if (!AmCheckpointerProcess())
13101307
return;
13111308

13121309
/*

‎src/backend/postmaster/walwriter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ static void walwriter_sigusr1_handler(SIGNAL_ARGS);
8989
/*
9090
* Main entry point for walwriter process
9191
*
92-
* This is invoked fromBootstrapMain, which has already created the basic
93-
* execution environment, but not enabled signals yet.
92+
* This is invoked fromAuxiliaryProcessMain, which has already created the
93+
*basicexecution environment, but not enabled signals yet.
9494
*/
9595
void
9696
WalWriterMain(void)

‎src/backend/replication/walreceiver.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@
5252
#include"utils/resowner.h"
5353
#include"utils/timestamp.h"
5454

55-
/* Global variable to indicate if this process is a walreceiver process */
56-
boolam_walreceiver;
5755

58-
/* GUCvariable */
56+
/* GUCvariables */
5957
intwal_receiver_status_interval;
6058
boolhot_standby_feedback;
6159

@@ -176,8 +174,6 @@ WalReceiverMain(void)
176174
/* use volatile pointer to prevent code rearrangement */
177175
volatileWalRcvData*walrcv=WalRcv;
178176

179-
am_walreceiver= true;
180-
181177
/*
182178
* WalRcv should be set up already (if we are a backend, we inherit this
183179
* by fork() or EXEC_BACKEND mechanism from the postmaster).

‎src/backend/storage/ipc/procsignal.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include<signal.h>
1818
#include<unistd.h>
1919

20-
#include"bootstrap/bootstrap.h"
2120
#include"commands/async.h"
2221
#include"miscadmin.h"
2322
#include"storage/latch.h"

‎src/backend/storage/smgr/md.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,10 @@ mdinit(void)
196196

197197
/*
198198
* Create pending-operations hashtable if we need it. Currently, we need
199-
* it if we are standalone (not under a postmaster) OR if we are a
200-
* bootstrap-mode subprocess of a postmaster (that is, a startup or
201-
* checkpointer process).
199+
* it if we are standalone (not under a postmaster) or if we are a startup
200+
* or checkpointer auxiliary process.
202201
*/
203-
if (!IsUnderPostmaster||IsBootstrapProcessingMode())
202+
if (!IsUnderPostmaster||AmStartupProcess()||AmCheckpointerProcess())
204203
{
205204
HASHCTLhash_ctl;
206205

‎src/include/bootstrap/bootstrap.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@
1616

1717
#include"nodes/execnodes.h"
1818

19-
typedefenum
20-
{
21-
CheckerProcess,
22-
BootstrapProcess,
23-
StartupProcess,
24-
BgWriterProcess,
25-
CheckpointerProcess,
26-
WalWriterProcess,
27-
WalReceiverProcess,
28-
29-
NUM_AUXPROCTYPES/* Must be last! */
30-
}AuxProcType;
3119

3220
/*
3321
* MAXATTR is the maximum number of attributes in a relation supported

‎src/include/miscadmin.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ extern bool superuser_arg(Oid roleid);/* given user is superuser */
328328
* initialization is complete.Some code behaves differently when executed
329329
* in this mode to enable system bootstrapping.
330330
*
331-
* If a POSTGRESbinaryis in normal mode, then all code may be executed
332-
* normally.
331+
* If a POSTGRESbackend processis in normal mode, then all code may be
332+
*executednormally.
333333
*/
334334

335335
typedefenumProcessingMode
@@ -341,9 +341,11 @@ typedef enum ProcessingMode
341341

342342
externProcessingModeMode;
343343

344-
#defineIsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing))
345-
#defineIsInitProcessingMode() ((bool)(Mode == InitProcessing))
346-
#defineIsNormalProcessingMode() ((bool)(Mode == NormalProcessing))
344+
#defineIsBootstrapProcessingMode()(Mode == BootstrapProcessing)
345+
#defineIsInitProcessingMode()(Mode == InitProcessing)
346+
#defineIsNormalProcessingMode()(Mode == NormalProcessing)
347+
348+
#defineGetProcessingMode() Mode
347349

348350
#defineSetProcessingMode(mode) \
349351
do { \
@@ -353,7 +355,35 @@ extern ProcessingMode Mode;
353355
Mode = (mode); \
354356
} while(0)
355357

356-
#defineGetProcessingMode() Mode
358+
359+
/*
360+
* Auxiliary-process type identifiers. These used to be in bootstrap.h
361+
* but it seems saner to have them here, with the ProcessingMode stuff.
362+
* The MyAuxProcType global is defined and set in bootstrap.c.
363+
*/
364+
365+
typedefenum
366+
{
367+
NotAnAuxProcess=-1,
368+
CheckerProcess=0,
369+
BootstrapProcess,
370+
StartupProcess,
371+
BgWriterProcess,
372+
CheckpointerProcess,
373+
WalWriterProcess,
374+
WalReceiverProcess,
375+
376+
NUM_AUXPROCTYPES/* Must be last! */
377+
}AuxProcType;
378+
379+
externAuxProcTypeMyAuxProcType;
380+
381+
#defineAmBootstrapProcess()(MyAuxProcType == BootstrapProcess)
382+
#defineAmStartupProcess()(MyAuxProcType == StartupProcess)
383+
#defineAmBackgroundWriterProcess()(MyAuxProcType == BgWriterProcess)
384+
#defineAmCheckpointerProcess()(MyAuxProcType == CheckpointerProcess)
385+
#defineAmWalWriterProcess()(MyAuxProcType == WalWriterProcess)
386+
#defineAmWalReceiverProcess()(MyAuxProcType == WalReceiverProcess)
357387

358388

359389
/*****************************************************************************

‎src/include/replication/walreceiver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include"storage/spin.h"
1818
#include"pgtime.h"
1919

20-
externboolam_walreceiver;
2120
externintwal_receiver_status_interval;
2221
externboolhot_standby_feedback;
2322

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp