From 30392aca58c4f9c103047eed104917f63e5d9236 Mon Sep 17 00:00:00 2001 From: Amul Sul Date: Mon, 20 Sep 2021 06:43:32 -0400 Subject: [PATCH v35 2/5] miscellaneous: remove dependency on global and local variable. Removes dependency on global variables and some local variable in StartupXLOG() function which may be available and/or deduced through the information available into shared memory. Changes enable us to move some of the code from StartupXLOG() into a separate function that can be executable by the other process which are connected to shared memory. --- src/backend/access/transam/xlog.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 4a6ddfb1872..c9d5bf9a72c 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7902,7 +7902,11 @@ StartupXLOG(void) UpdateFullPageWrites(); LocalXLogInsertAllowed = -1; - if (InRecovery) + /* + * Emit checkpoint or end-of-recovery record in XLOG, if the server wasn't + * shut down cleanly, which been through recovery. + */ + if (ControlFile->state != DB_SHUTDOWNED) { /* * Perform a checkpoint to update all our recovery activity to disk. @@ -7919,7 +7923,7 @@ StartupXLOG(void) * queries. */ if (ArchiveRecoveryIsRequested() && IsUnderPostmaster && - LocalPromoteIsTriggered) + PromoteIsTriggered()) { promoted = true; @@ -7945,6 +7949,8 @@ StartupXLOG(void) if (ArchiveRecoveryIsRequested()) { + XLogRecPtr EndOfLog; + /* * And finally, execute the recovery_end_command, if any. */ @@ -7962,6 +7968,7 @@ StartupXLOG(void) * pre-allocated files containing garbage. In any case, they are not * part of the new timeline's history so we don't need them. */ + (void) GetLastSegSwitchData(&EndOfLog); RemoveNonParentXlogFiles(EndOfLog, ThisTimeLineID); /* @@ -7998,6 +8005,7 @@ StartupXLOG(void) { char origfname[MAXFNAMELEN]; XLogSegNo endLogSegNo; + TimeLineID EndOfLogTLI = XLogCtl->replayEndTLI; XLByteToPrevSeg(EndOfLog, endLogSegNo, wal_segment_size); XLogFileName(origfname, EndOfLogTLI, endLogSegNo, wal_segment_size); -- 2.18.0