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

Commit5aa4a9d

Browse files
committed
process startup: Separate out BootstrapModeMain from AuxiliaryProcessMain.
There practically was no shared code between the two, once all the ifs areremoved. And it was quite confusing that aux processes weren't actuallystarted by the call to AuxiliaryProcessMain() in main().There's more to do, AuxiliaryProcessMain() should move out of bootstrap.c, andBootstrapModeMain() shouldn't use/be part of AuxProcType.Author: Andres Freund <andres@anarazel.de>Reviewed-By: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Reviewed-By: Robert Haas <robertmhaas@gmail.com>Discussion:https://postgr.es/m/20210802164124.ufo5buo4apl6yuvs@alap3.anarazel.de
1 parent50017f7 commit5aa4a9d

File tree

4 files changed

+187
-186
lines changed

4 files changed

+187
-186
lines changed

‎src/backend/bootstrap/bootstrap.c‎

Lines changed: 159 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ uint32bootstrap_data_checksum_version = 0;/* No checksum */
5555

5656

5757
staticvoidCheckerModeMain(void);
58-
staticvoidBootstrapModeMain(void);
5958
staticvoidbootstrap_signals(void);
6059
staticvoidShutdownAuxiliaryProcess(intcode,Datumarg);
6160
staticForm_pg_attributeAllocateAttribute(void);
@@ -194,124 +193,11 @@ static IndexList *ILHead = NULL;
194193
* This code is here just because of historical reasons.
195194
*/
196195
void
197-
AuxiliaryProcessMain(intargc,char*argv[])
196+
AuxiliaryProcessMain(AuxProcTypeauxtype)
198197
{
199-
char*progname=argv[0];
200-
intflag;
201-
char*userDoption=NULL;
202-
203-
/*
204-
* Initialize process environment (already done if under postmaster, but
205-
* not if standalone).
206-
*/
207-
if (!IsUnderPostmaster)
208-
InitStandaloneProcess(argv[0]);
209-
210-
/*
211-
* process command arguments
212-
*/
213-
214-
/* Set defaults, to be overridden by explicit options below */
215-
if (!IsUnderPostmaster)
216-
InitializeGUCOptions();
217-
218-
/* Ignore the initial --boot argument, if present */
219-
if (argc>1&&strcmp(argv[1],"--boot")==0)
220-
{
221-
argv++;
222-
argc--;
223-
}
224-
225-
/* If no -x argument, we are a CheckerProcess */
226-
MyAuxProcType=CheckerProcess;
227-
228-
while ((flag=getopt(argc,argv,"B:c:d:D:Fkr:x:X:-:"))!=-1)
229-
{
230-
switch (flag)
231-
{
232-
case'B':
233-
SetConfigOption("shared_buffers",optarg,PGC_POSTMASTER,PGC_S_ARGV);
234-
break;
235-
case'D':
236-
userDoption=pstrdup(optarg);
237-
break;
238-
case'd':
239-
{
240-
/* Turn on debugging for the bootstrap process. */
241-
char*debugstr;
242-
243-
debugstr=psprintf("debug%s",optarg);
244-
SetConfigOption("log_min_messages",debugstr,
245-
PGC_POSTMASTER,PGC_S_ARGV);
246-
SetConfigOption("client_min_messages",debugstr,
247-
PGC_POSTMASTER,PGC_S_ARGV);
248-
pfree(debugstr);
249-
}
250-
break;
251-
case'F':
252-
SetConfigOption("fsync","false",PGC_POSTMASTER,PGC_S_ARGV);
253-
break;
254-
case'k':
255-
bootstrap_data_checksum_version=PG_DATA_CHECKSUM_VERSION;
256-
break;
257-
case'r':
258-
strlcpy(OutputFileName,optarg,MAXPGPATH);
259-
break;
260-
case'x':
261-
MyAuxProcType=atoi(optarg);
262-
break;
263-
case'X':
264-
{
265-
intWalSegSz=strtoul(optarg,NULL,0);
266-
267-
if (!IsValidWalSegSize(WalSegSz))
268-
ereport(ERROR,
269-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
270-
errmsg("-X requires a power of two value between 1 MB and 1 GB")));
271-
SetConfigOption("wal_segment_size",optarg,PGC_INTERNAL,
272-
PGC_S_OVERRIDE);
273-
}
274-
break;
275-
case'c':
276-
case'-':
277-
{
278-
char*name,
279-
*value;
280-
281-
ParseLongOption(optarg,&name,&value);
282-
if (!value)
283-
{
284-
if (flag=='-')
285-
ereport(ERROR,
286-
(errcode(ERRCODE_SYNTAX_ERROR),
287-
errmsg("--%s requires a value",
288-
optarg)));
289-
else
290-
ereport(ERROR,
291-
(errcode(ERRCODE_SYNTAX_ERROR),
292-
errmsg("-c %s requires a value",
293-
optarg)));
294-
}
295-
296-
SetConfigOption(name,value,PGC_POSTMASTER,PGC_S_ARGV);
297-
free(name);
298-
if (value)
299-
free(value);
300-
break;
301-
}
302-
default:
303-
write_stderr("Try \"%s --help\" for more information.\n",
304-
progname);
305-
proc_exit(1);
306-
break;
307-
}
308-
}
198+
Assert(IsUnderPostmaster);
309199

310-
if (argc!=optind)
311-
{
312-
write_stderr("%s: invalid command-line arguments\n",progname);
313-
proc_exit(1);
314-
}
200+
MyAuxProcType=auxtype;
315201

316202
switch (MyAuxProcType)
317203
{
@@ -334,47 +220,22 @@ AuxiliaryProcessMain(int argc, char *argv[])
334220
MyBackendType=B_WAL_RECEIVER;
335221
break;
336222
default:
223+
elog(ERROR,"something has gone wrong");
337224
MyBackendType=B_INVALID;
338225
}
339-
if (IsUnderPostmaster)
340-
init_ps_display(NULL);
341-
342-
/* Acquire configuration parameters, unless inherited from postmaster */
343-
if (!IsUnderPostmaster)
344-
{
345-
if (!SelectConfigFiles(userDoption,progname))
346-
proc_exit(1);
347-
}
348226

349-
/*
350-
* Validate we have been given a reasonable-looking DataDir and change
351-
* into it (if under postmaster, should be done already).
352-
*/
353-
if (!IsUnderPostmaster)
354-
{
355-
checkDataDir();
356-
ChangeToDataDir();
357-
}
358-
359-
/* If standalone, create lockfile for data directory */
360-
if (!IsUnderPostmaster)
361-
CreateDataDirLockFile(false);
227+
init_ps_display(NULL);
362228

363229
SetProcessingMode(BootstrapProcessing);
364230
IgnoreSystemIndexes= true;
365231

366-
/* Initialize MaxBackends (if under postmaster, was done already) */
367-
if (!IsUnderPostmaster)
368-
InitializeMaxBackends();
369-
370232
BaseInit();
371233

372234
/*
373-
*When we arean auxiliary process, we aren't going to do the full
374-
*InitPostgrespushups, but there are a couple of things that need to get
375-
*lit up evenin an auxiliary process.
235+
*Asan auxiliary process, we aren't going to do the full InitPostgres
236+
* pushups, but there are a couple of things that need to get lit up even
237+
* in an auxiliary process.
376238
*/
377-
if (IsUnderPostmaster)
378239
{
379240
/*
380241
* Create a PGPROC so we can use LWLocks. In the EXEC_BACKEND case,
@@ -423,22 +284,9 @@ AuxiliaryProcessMain(int argc, char *argv[])
423284
switch (MyAuxProcType)
424285
{
425286
caseCheckerProcess:
426-
/* don't set signals, they're useless here */
427-
CheckerModeMain();
428-
proc_exit(1);/* should never return */
429-
430287
caseBootstrapProcess:
431-
432-
/*
433-
* There was a brief instant during which mode was Normal; this is
434-
* okay. We need to be in bootstrap mode during BootStrapXLOG for
435-
* the sake of multixact initialization.
436-
*/
437-
SetProcessingMode(BootstrapProcessing);
438-
bootstrap_signals();
439-
BootStrapXLOG();
440-
BootstrapModeMain();
441-
proc_exit(1);/* should never return */
288+
pg_unreachable();
289+
break;
442290

443291
caseStartupProcess:
444292
StartupProcessMain();
@@ -490,13 +338,159 @@ CheckerModeMain(void)
490338
* The bootstrap backend doesn't speak SQL, but instead expects
491339
* commands in a special bootstrap language.
492340
*/
493-
staticvoid
494-
BootstrapModeMain(void)
341+
void
342+
BootstrapModeMain(intargc,char*argv[])
495343
{
496344
inti;
345+
char*progname=argv[0];
346+
intflag;
347+
char*userDoption=NULL;
497348

498349
Assert(!IsUnderPostmaster);
499-
Assert(IsBootstrapProcessingMode());
350+
351+
InitStandaloneProcess(argv[0]);
352+
353+
/* Set defaults, to be overridden by explicit options below */
354+
InitializeGUCOptions();
355+
356+
/* an initial --boot should be present */
357+
Assert(argc==1
358+
||strcmp(argv[1],"--boot")!=0);
359+
argv++;
360+
argc--;
361+
362+
/* If no -x argument, we are a CheckerProcess */
363+
MyAuxProcType=CheckerProcess;
364+
365+
while ((flag=getopt(argc,argv,"B:c:d:D:Fkr:x:X:-:"))!=-1)
366+
{
367+
switch (flag)
368+
{
369+
case'B':
370+
SetConfigOption("shared_buffers",optarg,PGC_POSTMASTER,PGC_S_ARGV);
371+
break;
372+
case'D':
373+
userDoption=pstrdup(optarg);
374+
break;
375+
case'd':
376+
{
377+
/* Turn on debugging for the bootstrap process. */
378+
char*debugstr;
379+
380+
debugstr=psprintf("debug%s",optarg);
381+
SetConfigOption("log_min_messages",debugstr,
382+
PGC_POSTMASTER,PGC_S_ARGV);
383+
SetConfigOption("client_min_messages",debugstr,
384+
PGC_POSTMASTER,PGC_S_ARGV);
385+
pfree(debugstr);
386+
}
387+
break;
388+
case'F':
389+
SetConfigOption("fsync","false",PGC_POSTMASTER,PGC_S_ARGV);
390+
break;
391+
case'k':
392+
bootstrap_data_checksum_version=PG_DATA_CHECKSUM_VERSION;
393+
break;
394+
case'r':
395+
strlcpy(OutputFileName,optarg,MAXPGPATH);
396+
break;
397+
case'x':
398+
MyAuxProcType=atoi(optarg);
399+
if (MyAuxProcType!=CheckerProcess&&
400+
MyAuxProcType!=BootstrapProcess)
401+
{
402+
ereport(ERROR,
403+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
404+
errmsg("-x %s is invalid",optarg)));
405+
}
406+
break;
407+
case'X':
408+
{
409+
intWalSegSz=strtoul(optarg,NULL,0);
410+
411+
if (!IsValidWalSegSize(WalSegSz))
412+
ereport(ERROR,
413+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
414+
errmsg("-X requires a power of two value between 1 MB and 1 GB")));
415+
SetConfigOption("wal_segment_size",optarg,PGC_INTERNAL,
416+
PGC_S_OVERRIDE);
417+
}
418+
break;
419+
case'c':
420+
case'-':
421+
{
422+
char*name,
423+
*value;
424+
425+
ParseLongOption(optarg,&name,&value);
426+
if (!value)
427+
{
428+
if (flag=='-')
429+
ereport(ERROR,
430+
(errcode(ERRCODE_SYNTAX_ERROR),
431+
errmsg("--%s requires a value",
432+
optarg)));
433+
else
434+
ereport(ERROR,
435+
(errcode(ERRCODE_SYNTAX_ERROR),
436+
errmsg("-c %s requires a value",
437+
optarg)));
438+
}
439+
440+
SetConfigOption(name,value,PGC_POSTMASTER,PGC_S_ARGV);
441+
free(name);
442+
if (value)
443+
free(value);
444+
break;
445+
}
446+
default:
447+
write_stderr("Try \"%s --help\" for more information.\n",
448+
progname);
449+
proc_exit(1);
450+
break;
451+
}
452+
}
453+
454+
if (argc!=optind)
455+
{
456+
write_stderr("%s: invalid command-line arguments\n",progname);
457+
proc_exit(1);
458+
}
459+
460+
/* Acquire configuration parameters */
461+
if (!SelectConfigFiles(userDoption,progname))
462+
proc_exit(1);
463+
464+
/*
465+
* Validate we have been given a reasonable-looking DataDir and change
466+
* into it
467+
*/
468+
checkDataDir();
469+
ChangeToDataDir();
470+
471+
CreateDataDirLockFile(false);
472+
473+
SetProcessingMode(BootstrapProcessing);
474+
IgnoreSystemIndexes= true;
475+
476+
InitializeMaxBackends();
477+
478+
BaseInit();
479+
480+
/*
481+
* XXX: It might make sense to move this into its own function at some
482+
* point. Right now it seems like it'd cause more code duplication than
483+
* it's worth.
484+
*/
485+
if (MyAuxProcType==CheckerProcess)
486+
{
487+
SetProcessingMode(NormalProcessing);
488+
CheckerModeMain();
489+
abort();
490+
}
491+
492+
bootstrap_signals();
493+
BootStrapXLOG();
500494

501495
/*
502496
* To ensure that src/common/link-canary.c is linked into the backend, we

‎src/backend/main/main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ main(int argc, char *argv[])
198198
#endif
199199

200200
if (argc>1&&strcmp(argv[1],"--boot")==0)
201-
AuxiliaryProcessMain(argc,argv);/* does not return */
201+
BootstrapModeMain(argc,argv);/* does not return */
202202
elseif (argc>1&&strcmp(argv[1],"--describe-config")==0)
203203
GucInfoMain();/* does not return */
204204
elseif (argc>1&&strcmp(argv[1],"--single")==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp