1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Get rid of the former rather baroque mechanism for propagating the values

of ThisStartUpID and RedoRecPtr into new backends.  It's a lot easier just
to make them all grab the values out of shared memory during startup.
This helps to decouple the postmaster from checkpoint execution, which I
need since I'm intending to let the bgwriter do it instead, and it also
fixes a bug in the Win32 port: ThisStartUpID wasn't getting propagated at
all AFAICS.  (Doesn't give me a lot of faith in the amount of testing that
port has gotten.)
This commit is contained in:
Tom Lane
2004-05-27 17:12:57 +00:00
parent bb44a7c525
commit 16974ee910
6 changed files with 38 additions and 59 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.142 2004/05/21 16:08:46 tgl Exp $
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.143 2004/05/27 17:12:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -166,9 +166,10 @@ XLogRecPtr ProcLastRecEnd = {0, 0};
* XLogCtl->Insert.RedoRecPtr, whenever we can safely do so (ie, when we
* hold the Insert lock). See XLogInsert for details. We are also allowed
* to update from XLogCtl->Insert.RedoRecPtr if we hold the info_lck;
* see GetRedoRecPtr.
* see GetRedoRecPtr. A freshly spawned backend obtains the value during
* InitXLOGAccess.
*/
NON_EXEC_STATIC XLogRecPtr RedoRecPtr;
static XLogRecPtr RedoRecPtr;
/*----------
* Shared-memory data structures for XLOG control
@ -280,10 +281,6 @@ typedef struct XLogCtlData
uint32 XLogCacheBlck; /* highest allocated xlog buffer index */
StartUpID ThisStartUpID;
/* This value is not protected by *any* lock... */
/* see SetSavedRedoRecPtr/GetSavedRedoRecPtr */
XLogRecPtr SavedRedoRecPtr;
slock_t info_lck; /* locks shared LogwrtRqst/LogwrtResult */
} XLogCtlData;
@ -2893,8 +2890,7 @@ StartupXLOG(void)
else
ThisStartUpID = checkPoint.ThisStartUpID;
RedoRecPtr = XLogCtl->Insert.RedoRecPtr =
XLogCtl->SavedRedoRecPtr = checkPoint.redo;
RedoRecPtr = XLogCtl->Insert.RedoRecPtr = checkPoint.redo;
if (XLByteLT(RecPtr, checkPoint.redo))
ereport(PANIC,
@ -3251,35 +3247,22 @@ ReadCheckpointRecord(XLogRecPtr RecPtr,
}
/*
* Postmaster uses this to initialize ThisStartUpID & RedoRecPtr from
* XLogCtlData located in shmem after successful startup.
* This must be called during startup of a backend process, except that
* it need not be called in a standalone backend (which does StartupXLOG
* instead). We need to initialize the local copies of ThisStartUpID and
* RedoRecPtr.
*
* Note: before Postgres 7.5, we went to some effort to keep the postmaster
* process's copies of ThisStartUpID and RedoRecPtr valid too. This was
* unnecessary however, since the postmaster itself never touches XLOG anyway.
*/
void
SetThisStartUpID(void)
InitXLOGAccess(void)
{
/* ThisStartUpID doesn't change so we need no lock to copy it */
ThisStartUpID = XLogCtl->ThisStartUpID;
RedoRecPtr = XLogCtl->SavedRedoRecPtr;
}
/*
* CheckPoint process called by postmaster saves copy of new RedoRecPtr
* in shmem (using SetSavedRedoRecPtr). When checkpointer completes,
* postmaster calls GetSavedRedoRecPtr to update its own copy of RedoRecPtr,
* so that subsequently-spawned backends will start out with a reasonably
* up-to-date local RedoRecPtr. Since these operations are not protected by
* any lock and copying an XLogRecPtr isn't atomic, it's unsafe to use either
* of these routines at other times!
*/
void
SetSavedRedoRecPtr(void)
{
XLogCtl->SavedRedoRecPtr = RedoRecPtr;
}
void
GetSavedRedoRecPtr(void)
{
RedoRecPtr = XLogCtl->SavedRedoRecPtr;
/* Use GetRedoRecPtr to copy the RedoRecPtr safely */
(void) GetRedoRecPtr();
}
/*