Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16974ee

Browse files
committed
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.)
1 parent bb44a7c commit 16974ee

File tree

6 files changed

+38
-59
lines changed

6 files changed

+38
-59
lines changed

src/backend/access/heap/heapam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.167 2004/05/20 15:07:30 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.168 2004/05/27 17:12:37 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1902,7 +1902,7 @@ heap_mark4update(Relation relation, HeapTuple tuple, Buffer *buffer,
19021902
* XLOG stuff: no logging is required as long as we have no
19031903
* savepoints. For savepoints private log could be used...
19041904
*/
1905-
((PageHeader) BufferGetPage(*buffer))->pd_sui = ThisStartUpID;
1905+
PageSetSUI(BufferGetPage(*buffer), ThisStartUpID);
19061906

19071907
/* store transaction information of xact marking the tuple */
19081908
tuple->t_data->t_infomask &= ~(HEAP_XMAX_COMMITTED |

src/backend/access/transam/xlog.c

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.142 2004/05/21 16:08:46 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.143 2004/05/27 17:12:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -166,9 +166,10 @@ XLogRecPtr ProcLastRecEnd = {0, 0};
166166
* XLogCtl->Insert.RedoRecPtr, whenever we can safely do so (ie, when we
167167
* hold the Insert lock). See XLogInsert for details. We are also allowed
168168
* to update from XLogCtl->Insert.RedoRecPtr if we hold the info_lck;
169-
* see GetRedoRecPtr.
169+
* see GetRedoRecPtr. A freshly spawned backend obtains the value during
170+
* InitXLOGAccess.
170171
*/
171-
NON_EXEC_STATIC XLogRecPtr RedoRecPtr;
172+
static XLogRecPtr RedoRecPtr;
172173

173174
/*----------
174175
* Shared-memory data structures for XLOG control
@@ -280,10 +281,6 @@ typedef struct XLogCtlData
280281
uint32 XLogCacheBlck; /* highest allocated xlog buffer index */
281282
StartUpID ThisStartUpID;
282283

283-
/* This value is not protected by *any* lock... */
284-
/* see SetSavedRedoRecPtr/GetSavedRedoRecPtr */
285-
XLogRecPtr SavedRedoRecPtr;
286-
287284
slock_t info_lck; /* locks shared LogwrtRqst/LogwrtResult */
288285
} XLogCtlData;
289286

@@ -2893,8 +2890,7 @@ StartupXLOG(void)
28932890
else
28942891
ThisStartUpID = checkPoint.ThisStartUpID;
28952892

2896-
RedoRecPtr = XLogCtl->Insert.RedoRecPtr =
2897-
XLogCtl->SavedRedoRecPtr = checkPoint.redo;
2893+
RedoRecPtr = XLogCtl->Insert.RedoRecPtr = checkPoint.redo;
28982894

28992895
if (XLByteLT(RecPtr, checkPoint.redo))
29002896
ereport(PANIC,
@@ -3251,35 +3247,22 @@ ReadCheckpointRecord(XLogRecPtr RecPtr,
32513247
}
32523248

32533249
/*
3254-
* Postmaster uses this to initialize ThisStartUpID & RedoRecPtr from
3255-
* XLogCtlData located in shmem after successful startup.
3250+
* This must be called during startup of a backend process, except that
3251+
* it need not be called in a standalone backend (which does StartupXLOG
3252+
* instead). We need to initialize the local copies of ThisStartUpID and
3253+
* RedoRecPtr.
3254+
*
3255+
* Note: before Postgres 7.5, we went to some effort to keep the postmaster
3256+
* process's copies of ThisStartUpID and RedoRecPtr valid too. This was
3257+
* unnecessary however, since the postmaster itself never touches XLOG anyway.
32563258
*/
32573259
void
3258-
SetThisStartUpID(void)
3260+
InitXLOGAccess(void)
32593261
{
3262+
/* ThisStartUpID doesn't change so we need no lock to copy it */
32603263
ThisStartUpID = XLogCtl->ThisStartUpID;
3261-
RedoRecPtr = XLogCtl->SavedRedoRecPtr;
3262-
}
3263-
3264-
/*
3265-
* CheckPoint process called by postmaster saves copy of new RedoRecPtr
3266-
* in shmem (using SetSavedRedoRecPtr). When checkpointer completes,
3267-
* postmaster calls GetSavedRedoRecPtr to update its own copy of RedoRecPtr,
3268-
* so that subsequently-spawned backends will start out with a reasonably
3269-
* up-to-date local RedoRecPtr. Since these operations are not protected by
3270-
* any lock and copying an XLogRecPtr isn't atomic, it's unsafe to use either
3271-
* of these routines at other times!
3272-
*/
3273-
void
3274-
SetSavedRedoRecPtr(void)
3275-
{
3276-
XLogCtl->SavedRedoRecPtr = RedoRecPtr;
3277-
}
3278-
3279-
void
3280-
GetSavedRedoRecPtr(void)
3281-
{
3282-
RedoRecPtr = XLogCtl->SavedRedoRecPtr;
3264+
/* Use GetRedoRecPtr to copy the RedoRecPtr safely */
3265+
(void) GetRedoRecPtr();
32833266
}
32843267

32853268
/*

src/backend/bootstrap/bootstrap.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.179 2004/05/21 05:07:56 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.180 2004/05/27 17:12:49 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -489,12 +489,12 @@ BootstrapMain(int argc, char *argv[])
489489
break;
490490

491491
case BS_XLOG_CHECKPOINT:
492+
InitXLOGAccess();
492493
CreateCheckPoint(false, false);
493-
SetSavedRedoRecPtr(); /* pass redo ptr back to
494-
* postmaster */
495494
proc_exit(0); /* done */
496495

497496
case BS_XLOG_BGWRITER:
497+
InitXLOGAccess();
498498
BufferBackgroundWriter();
499499
proc_exit(0); /* done */
500500

@@ -504,6 +504,7 @@ BootstrapMain(int argc, char *argv[])
504504
proc_exit(0); /* done */
505505

506506
case BS_XLOG_SHUTDOWN:
507+
InitXLOGAccess();
507508
ShutdownXLOG(0, 0);
508509
DumpFreeSpaceMap(0, 0);
509510
proc_exit(0); /* done */

src/backend/postmaster/postmaster.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.396 2004/05/27 15:07:41 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.397 2004/05/27 17:12:52 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -1909,8 +1909,8 @@ reaper(SIGNAL_ARGS)
19091909
* trouble...
19101910
*/
19111911
win32_RemoveChild(pid);
1912-
#endif
1913-
#endif
1912+
#endif /* WIN32 */
1913+
#endif /* HAVE_WAITPID */
19141914

19151915
/*
19161916
* Check if this child was the statistics collector. If so, try to
@@ -1953,14 +1953,9 @@ reaper(SIGNAL_ARGS)
19531953
StartupPID = 0;
19541954

19551955
/*
1956-
* Startup succeeded - remember its ID and RedoRecPtr.
1957-
*
1958-
* NB: this MUST happen before we fork a checkpoint or shutdown
1959-
* subprocess, else they will have wrong local ThisStartUpId.
1956+
* Startup succeeded - we are done with system startup or recovery.
19601957
*/
1961-
SetThisStartUpID();
1962-
1963-
FatalError = false; /* done with recovery */
1958+
FatalError = false;
19641959

19651960
/*
19661961
* Arrange for first checkpoint to occur after standard delay.
@@ -2073,8 +2068,6 @@ CleanupProc(int pid,
20732068
if (!FatalError)
20742069
{
20752070
checkpointed = time(NULL);
2076-
/* Update RedoRecPtr for future child backends */
2077-
GetSavedRedoRecPtr();
20782071
}
20792072
}
20802073
else if (pid == BgWriterPID)
@@ -3287,7 +3280,6 @@ postmaster_error(const char *fmt,...)
32873280
* functions
32883281
*/
32893282
#include "storage/spin.h"
3290-
extern XLogRecPtr RedoRecPtr;
32913283
extern XLogwrtResult LogwrtResult;
32923284
extern slock_t *ShmemLock;
32933285
extern slock_t *ShmemIndexLock;
@@ -3351,7 +3343,6 @@ write_backend_variables(Port *port)
33513343
}
33523344
write_var(MyCancelKey, fp);
33533345

3354-
write_var(RedoRecPtr, fp);
33553346
write_var(LogwrtResult, fp);
33563347

33573348
write_var(UsedShmemSegID, fp);
@@ -3416,7 +3407,6 @@ read_backend_variables(unsigned long id, Port *port)
34163407
}
34173408
read_var(MyCancelKey, fp);
34183409

3419-
read_var(RedoRecPtr, fp);
34203410
read_var(LogwrtResult, fp);
34213411

34223412
read_var(UsedShmemSegID, fp);

src/backend/utils/init/postinit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.131 2003/12/12 18:45:09 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.132 2004/05/27 17:12:54 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -325,6 +325,13 @@ InitPostgres(const char *dbname, const char *username)
325325
*/
326326
AmiTransactionOverride(bootstrap);
327327

328+
/*
329+
* Initialize local process's access to XLOG. In bootstrap case
330+
* we may skip this since StartupXLOG() was run instead.
331+
*/
332+
if (!bootstrap)
333+
InitXLOGAccess();
334+
328335
/*
329336
* Initialize the relation descriptor cache. This must create at
330337
* least the minimum set of "nailed-in" cache entries. No catalog

src/include/access/xlog.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.49 2004/02/11 22:55:25 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.50 2004/05/27 17:12:57 tgl Exp $
1010
*/
1111
#ifndef XLOG_H
1212
#define XLOG_H
@@ -230,11 +230,9 @@ extern void XLOGPathInit(void);
230230
extern void BootStrapXLOG(void);
231231
extern void StartupXLOG(void);
232232
extern void ShutdownXLOG(int code, Datum arg);
233+
extern void InitXLOGAccess(void);
233234
extern void CreateCheckPoint(bool shutdown, bool force);
234-
extern void SetThisStartUpID(void);
235235
extern void XLogPutNextOid(Oid nextOid);
236-
extern void SetSavedRedoRecPtr(void);
237-
extern void GetSavedRedoRecPtr(void);
238236
extern XLogRecPtr GetRedoRecPtr(void);
239237

240238
/* in storage/ipc/sinval.c, but don't want to declare in sinval.h because

0 commit comments

Comments
 (0)