Skip to content

Commit 4793740

Browse files
committed
XLOG (also known as WAL -:)) Bootstrap/Startup/Shutdown.
First step in cleaning up backend initialization code. Fix for FATAL: now FATAL is ERROR + exit.
1 parent 9dcd8c5 commit 4793740

File tree

20 files changed

+1176
-1033
lines changed

20 files changed

+1176
-1033
lines changed

src/backend/access/transam/xlog.c

Lines changed: 449 additions & 377 deletions
Large diffs are not rendered by default.

src/backend/bootstrap/bootstrap.c

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.68 1999/09/27 20:26:58 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.69 1999/10/06 21:58:02 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -39,6 +39,14 @@
3939
#define ALLOC(t, c) (t *)calloc((unsigned)(c), sizeof(t))
4040
#define FIRST_TYPE_OID 16 /* OID of the first type */
4141

42+
extern void BaseInit(void);
43+
extern void StartupXLOG(void);
44+
extern void ShutdownXLOG(void);
45+
extern void BootStrapXLOG(void);
46+
47+
extern char XLogDir[];
48+
extern char ControlFilePath[];
49+
4250
extern int Int_yyparse(void);
4351
static hashnode *AddStr(char *str, int strlength, int mderef);
4452
static Form_pg_attribute AllocateAttribute(void);
@@ -218,22 +226,13 @@ BootstrapMain(int argc, char *argv[])
218226
*/
219227
{
220228
int i;
221-
int portFd = -1;
222229
char *dbName;
223230
int flag;
224-
int override = 1; /* use BootstrapProcessing or
225-
* InitProcessing mode */
231+
bool xloginit = false;
226232

227233
extern int optind;
228234
extern char *optarg;
229235

230-
/* ----------------
231-
* initialize signal handlers
232-
* ----------------
233-
*/
234-
pqsignal(SIGINT, (sig_func) die);
235-
pqsignal(SIGHUP, (sig_func) die);
236-
pqsignal(SIGTERM, (sig_func) die);
237236

238237
/* --------------------
239238
* initialize globals
@@ -252,8 +251,9 @@ BootstrapMain(int argc, char *argv[])
252251
Noversion = false;
253252
dbName = NULL;
254253
DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
254+
IsUnderPostmaster = false;
255255

256-
while ((flag = getopt(argc, argv, "D:dCOQP:F")) != EOF)
256+
while ((flag = getopt(argc, argv, "D:dCQxpB:F")) != EOF)
257257
{
258258
switch (flag)
259259
{
@@ -270,14 +270,17 @@ BootstrapMain(int argc, char *argv[])
270270
case 'F':
271271
disableFsync = true;
272272
break;
273-
case 'O':
274-
override = true;
275-
break;
276273
case 'Q':
277274
Quiet = true;
278275
break;
279-
case 'P': /* specify port */
280-
portFd = atoi(optarg);
276+
case 'x':
277+
xloginit = true;
278+
break;
279+
case 'p':
280+
IsUnderPostmaster = true;
281+
break;
282+
case 'B':
283+
NBuffers = atoi(optarg);
281284
break;
282285
default:
283286
usage();
@@ -290,6 +293,8 @@ BootstrapMain(int argc, char *argv[])
290293
else if (argc - optind == 1)
291294
dbName = argv[optind];
292295

296+
SetProcessingMode(BootstrapProcessing);
297+
293298
if (!DataDir)
294299
{
295300
fprintf(stderr, "%s does not know where to find the database system "
@@ -311,24 +316,50 @@ BootstrapMain(int argc, char *argv[])
311316
}
312317
}
313318

314-
/* ----------------
315-
* initialize input fd
316-
* ----------------
319+
BaseInit();
320+
321+
if (!IsUnderPostmaster)
322+
{
323+
pqsignal(SIGINT, (sig_func) die);
324+
pqsignal(SIGHUP, (sig_func) die);
325+
pqsignal(SIGTERM, (sig_func) die);
326+
}
327+
328+
/*
329+
* Bootstrap under Postmaster means two things:
330+
* (xloginit) ? StartupXLOG : ShutdownXLOG
331+
*
332+
* If !under Postmaster and xloginit then BootStrapXLOG.
317333
*/
318-
if (IsUnderPostmaster && portFd < 0)
334+
if (IsUnderPostmaster || xloginit)
319335
{
320-
fputs("backend: failed, no -P option with -postmaster opt.\n", stderr);
321-
proc_exit(1);
336+
sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR);
337+
sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR);
322338
}
323339

324-
/* ----------------
325-
* backend initialization
326-
* ----------------
340+
if (IsUnderPostmaster && xloginit)
341+
{
342+
StartupXLOG();
343+
proc_exit(0);
344+
}
345+
346+
if (!IsUnderPostmaster && xloginit)
347+
{
348+
BootStrapXLOG();
349+
}
350+
351+
/*
352+
* backend initialization
327353
*/
328-
SetProcessingMode((override) ? BootstrapProcessing : InitProcessing);
329354
InitPostgres(dbName);
330355
LockDisable(true);
331356

357+
if (IsUnderPostmaster && !xloginit)
358+
{
359+
ShutdownXLOG();
360+
proc_exit(0);
361+
}
362+
332363
for (i = 0; i < MAXATTR; i++)
333364
{
334365
attrtypes[i] = (Form_pg_attribute) NULL;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy