1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-16 15:02:33 +03:00

XLOG (also known as WAL -:)) Bootstrap/Startup/Shutdown.

First step in cleaning up backend initialization code.
Fix for FATAL: now FATAL is ERROR + exit.
This commit is contained in:
Vadim B. Mikheev
1999-10-06 21:58:18 +00:00
parent 9dcd8c528f
commit 4793740367
20 changed files with 1158 additions and 1015 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.48 1999/09/11 19:06:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.49 1999/10/06 21:58:09 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -37,6 +37,7 @@
extern int errno;
extern int sys_nerr;
extern CommandDest whereToSendOutput;
#ifdef USE_SYSLOG
/*
@@ -107,6 +108,19 @@ elog(int lev, const char *fmt, ...)
if (lev <= DEBUG && Debugfile < 0)
return; /* ignore debug msgs if noplace to send */
if (lev == ERROR || lev == FATAL)
{
if (IsInitProcessingMode())
{
extern TransactionState CurrentTransactionState;
if (CurrentTransactionState->state != TRANS_DEFAULT &&
CurrentTransactionState->state != TRANS_DISABLED)
abort();
lev = FATAL;
}
}
/* choose message prefix and indent level */
switch (lev)
{
@@ -304,7 +318,7 @@ elog(int lev, const char *fmt, ...)
#ifndef PG_STANDALONE
if (lev > DEBUG && IsUnderPostmaster)
if (lev > DEBUG && whereToSendOutput == Remote)
{
/* Send IPC message to the front-end program */
char msgtype;
@@ -336,7 +350,7 @@ elog(int lev, const char *fmt, ...)
pq_flush();
}
if (lev > DEBUG && ! IsUnderPostmaster)
if (lev > DEBUG && whereToSendOutput != Remote)
{
/* We are running as an interactive backend, so just send
* the message to stderr.
@@ -355,36 +369,29 @@ elog(int lev, const char *fmt, ...)
/*
* Perform error recovery action as specified by lev.
*/
if (lev == ERROR)
if (lev == ERROR || lev == FATAL)
{
if (InError)
{
/* error reported during error recovery; don't loop forever */
elog(REALLYFATAL, "elog: error during error recovery, giving up!");
}
InError = true;
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
if (lev == FATAL)
{
if (IsInitProcessingMode())
ExitPostgres(0);
ExitAfterAbort = true;
}
/* exit to main loop */
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
siglongjmp(Warn_restart, 1);
}
if (lev == FATAL)
{
/*
* Assume that if we have detected the failure we can exit with a
* normal exit status. This will prevent the postmaster from
* cleaning up when it's not needed.
*/
fflush(stdout);
fflush(stderr);
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
ProcReleaseLocks(); /* get rid of real locks we hold */
proc_exit(0);
}
if (lev > FATAL)
{
/*
* Serious crash time. Postmaster will observe nonzero
* Serious crash time. Postmaster will observe nonzero
* process exit status and kill the other backends too.
*/
fflush(stdout);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.34 1999/07/17 20:18:08 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.35 1999/10/06 21:58:10 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -133,20 +133,7 @@ StatusPostmasterExit(int status)
* processing mode support stuff (used to be in pmod.c)
* ----------------------------------------------------------------
*/
static ProcessingMode Mode = NoProcessing;
#ifdef NOT_USED
/*
* IsNoProcessingMode
* True iff processing mode is NoProcessing.
*/
bool
IsNoProcessingMode()
{
return (bool) (Mode == NoProcessing);
}
#endif
static ProcessingMode Mode = InitProcessing;
/*
* IsBootstrapProcessingMode
@@ -186,13 +173,13 @@ IsNormalProcessingMode()
* BadArg if called with invalid mode.
*
* Note:
* Mode is NoProcessing before the first time this is called.
* Mode is InitProcessing before the first time this is called.
*/
void
SetProcessingMode(ProcessingMode mode)
{
AssertArg(mode == NoProcessing || mode == BootstrapProcessing ||
mode == InitProcessing || mode == NormalProcessing);
AssertArg(mode == BootstrapProcessing || mode == InitProcessing ||
mode == NormalProcessing);
Mode = mode;
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.50 1999/09/28 11:41:09 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.51 1999/10/06 21:58:10 vadim Exp $
*
* NOTES
* InitPostgres() is the function called from PostgresMain
@@ -53,12 +53,13 @@
#include "mb/pg_wchar.h"
#endif
void BaseInit(void);
static void VerifySystemDatabase(void);
static void VerifyMyDatabase(void);
static void ReverifyMyDatabase(char *name);
static void InitCommunication(void);
static void InitMyDatabaseInfo(char *name);
static void InitStdio(void);
static void InitUserid(void);
@@ -385,37 +386,6 @@ InitCommunication()
{
if (MyBackendTag == -1)
elog(FATAL, "InitCommunication: missing POSTID");
/*
* Enable this if you are trying to force the backend to run as if
* it is running under the postmaster.
*
* This goto forces Postgres to attach to shared memory instead of
* using malloc'ed memory (which is the normal behavior if run
* directly).
*
* To enable emulation, run the following shell commands (in addition
* to enabling this goto)
*
* % setenv POSTID 1 % setenv POSTPORT 4321 % setenv IPC_KEY 4321000
* % postmaster & % kill -9 %1
*
* Upon doing this, Postmaster will have allocated the shared memory
* resources that Postgres will attach to if you enable
* EMULATE_UNDER_POSTMASTER.
*
* This comment may well age with time - it is current as of 8
* January 1990
*
* Greg
*/
#ifdef EMULATE_UNDER_POSTMASTER
goto forcesharedmemory;
#endif
}
else if (IsUnderPostmaster)
{
@@ -439,12 +409,6 @@ InitCommunication()
* initialize shared memory and semaphores appropriately.
* ----------------
*/
#ifdef EMULATE_UNDER_POSTMASTER
forcesharedmemory:
#endif
if (!IsUnderPostmaster) /* postmaster already did this */
{
PostgresIpcKey = key;
@@ -452,21 +416,6 @@ forcesharedmemory:
}
}
/* --------------------------------
* InitStdio
*
* this routine consists of a bunch of code fragments
* that used to be randomly scattered through cinit().
* they all seem to do stuff associated with io.
* --------------------------------
*/
static void
InitStdio()
{
DebugFileOpen();
}
/* --------------------------------
* InitPostgres
* Initialize POSTGRES.
@@ -477,8 +426,6 @@ InitStdio()
*/
extern int NBuffers;
bool PostgresIsInitialized = false;
int lockingOff = 0; /* backend -L switch */
/*
@@ -488,37 +435,11 @@ InitPostgres(char *name) /* database name */
{
bool bootstrap; /* true if BootstrapProcessing */
/* ----------------
* see if we're running in BootstrapProcessing mode
* ----------------
/*
* See if we're running in BootstrapProcessing mode
*/
bootstrap = IsBootstrapProcessingMode();
/* ----------------
* turn on the exception handler. Note: we cannot use elog, Assert,
* AssertState, etc. until after exception handling is on.
* ----------------
*/
EnableExceptionHandling(true);
/* ----------------
* A stupid check to make sure we don't call this more than once.
* But things like ReinitPostgres() get around this by just diddling
* the PostgresIsInitialized flag.
* ----------------
*/
AssertState(!PostgresIsInitialized);
/* ----------------
* Memory system initialization.
* (we may call palloc after EnableMemoryContext())
*
* Note EnableMemoryContext() must happen before EnablePortalManager().
* ----------------
*/
EnableMemoryContext(true); /* initializes the "top context" */
EnablePortalManager(true); /* memory for portal/transaction stuff */
/* ----------------
* initialize the backend local portal stack used by
* internal PQ function calls. see src/lib/libpq/be-dumpdata.c
@@ -528,14 +449,6 @@ InitPostgres(char *name) /* database name */
*/
be_portalinit();
/* ----------------
* attach to shared memory and semaphores, and initialize our
* input/output/debugging file descriptors.
* ----------------
*/
InitCommunication();
InitStdio();
/*
* initialize the local buffer manager
*/
@@ -574,13 +487,9 @@ InitPostgres(char *name) /* database name */
* Will try that, but may not work... - thomas 1997-11-01
*/
/* Does not touch files (?) - thomas 1997-11-01 */
smgrinit();
/* ----------------
* initialize the transaction system and the relation descriptor cache.
* Note we have to make certain the lock manager is off while we do this.
* ----------------
/*
* Initialize the transaction system and the relation descriptor cache.
* Note we have to make certain the lock manager is off while we do this.
*/
AmiTransactionOverride(IsBootstrapProcessingMode());
LockDisable(true);
@@ -598,20 +507,18 @@ InitPostgres(char *name) /* database name */
LockDisable(false);
/* ----------------
/*
* Set up my per-backend PROC struct in shared memory.
* ----------------
*/
InitProcess(PostgresIpcKey);
/* ----------------
* Initialize my entry in the shared-invalidation manager's
* array of per-backend data. (Formerly this came before
* InitProcess, but now it must happen after, because it uses
* MyProc.) Once I have done this, I am visible to other backends!
/*
* Initialize my entry in the shared-invalidation manager's
* array of per-backend data. (Formerly this came before
* InitProcess, but now it must happen after, because it uses
* MyProc.) Once I have done this, I am visible to other backends!
*
* Sets up MyBackendId, a unique backend identifier.
* ----------------
* Sets up MyBackendId, a unique backend identifier.
*/
InitSharedInvalidationState();
@@ -622,16 +529,14 @@ InitPostgres(char *name) /* database name */
MyBackendId);
}
/* ----------------
* initialize the access methods.
* Does not touch files (?) - thomas 1997-11-01
* ----------------
/*
* Initialize the access methods.
* Does not touch files (?) - thomas 1997-11-01
*/
initam();
/* ----------------
* initialize all the system catalog caches.
* ----------------
/*
* Initialize all the system catalog caches.
*/
zerocaches();
@@ -641,34 +546,19 @@ InitPostgres(char *name) /* database name */
*/
InitCatalogCache();
/* ----------------
* set ourselves to the proper user id and figure out our postgres
* user id. If we ever add security so that we check for valid
* postgres users, we might do it here.
* ----------------
/*
* Set ourselves to the proper user id and figure out our postgres
* user id. If we ever add security so that we check for valid
* postgres users, we might do it here.
*/
InitUserid();
/* ----------------
* initialize local data in cache invalidation stuff
* ----------------
/*
* Initialize local data in cache invalidation stuff
*/
if (!bootstrap)
InitLocalInvalidateData();
/* ----------------
* ok, all done, now let's make sure we don't do it again.
* ----------------
*/
PostgresIsInitialized = true;
/* ----------------
* Done with "InitPostgres", now change to NormalProcessing unless
* we're in BootstrapProcessing mode.
* ----------------
*/
if (!bootstrap)
SetProcessingMode(NormalProcessing);
if (lockingOff)
LockDisable(true);
@@ -680,3 +570,30 @@ InitPostgres(char *name) /* database name */
if (!bootstrap)
ReverifyMyDatabase(name);
}
void
BaseInit(void)
{
/*
* Turn on the exception handler. Note: we cannot use elog, Assert,
* AssertState, etc. until after exception handling is on.
*/
EnableExceptionHandling(true);
/*
* Memory system initialization - we may call palloc after
* EnableMemoryContext()). Note that EnableMemoryContext()
* must happen before EnablePortalManager().
*/
EnableMemoryContext(true); /* initializes the "top context" */
EnablePortalManager(true); /* memory for portal/transaction stuff */
/*
* Attach to shared memory and semaphores, and initialize our
* input/output/debugging file descriptors.
*/
InitCommunication();
DebugFileOpen();
smgrinit();
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.31 1999/07/15 22:40:15 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/time/tqual.c,v 1.32 1999/10/06 21:58:11 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,8 +18,6 @@
#include "utils/tqual.h"
extern bool PostgresIsInitialized;
SnapshotData SnapshotDirtyData;
Snapshot SnapshotDirty = &SnapshotDirtyData;
@@ -194,17 +192,6 @@ HeapTupleSatisfiesNow(HeapTupleHeader tuple)
if (AMI_OVERRIDE)
return true;
/*
* If the transaction system isn't yet initialized, then we assume
* that transactions committed. We only look at system catalogs
* during startup, so this is less awful than it seems, but it's still
* pretty awful.
*/
if (!PostgresIsInitialized)
return ((bool) (TransactionIdIsValid(tuple->t_xmin) &&
!TransactionIdIsValid(tuple->t_xmax)));
if (!(tuple->t_infomask & HEAP_XMIN_COMMITTED))
{
if (tuple->t_infomask & HEAP_XMIN_INVALID)