Skip to content

Commit 811051c

Browse files
committed
Postpone some end-of-recovery operations related to allowing WAL.
CreateOverwriteContrecordRecord(), UpdateFullPageWrites(), PerformRecoveryXLogAction(), and CleanupAfterArchiveRecovery() are moved somewhat later in StartupXLOG(). This is preparatory work for a future patch that wants to allow recovery to end at one time and only later start to allow WAL writes. To do that, it's necessary to separate code that has to do with allowing WAL writes from other things that need to happen simply because recovery is ending, such as initializing shared memory data structures that depend on information that might not be accurate before redo is complete. This commit does not achieve that goal, but it is a step in that direction. For example, there are a few different bits of code that write things into WAL once we have finished recovery, and with this change, those bits of code are closer to each other than previously, with fewer unrelated bits of code interspersed. Robert Haas and Amul Sul Discussion: http://postgr.es/m/CAAJ_b97abMuq=470Wahun=aS1PHTSbStHtrjjPaD-C0YQ1AqVw@mail.gmail.com
1 parent 010e523 commit 811051c

File tree

1 file changed

+36
-28
lines changed
  • src/backend/access/transam

1 file changed

+36
-28
lines changed

src/backend/access/transam/xlog.c

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8018,34 +8018,6 @@ StartupXLOG(void)
80188018
XLogCtl->LogwrtRqst.Write = EndOfLog;
80198019
XLogCtl->LogwrtRqst.Flush = EndOfLog;
80208020

8021-
LocalSetXLogInsertAllowed();
8022-
8023-
/* If necessary, write overwrite-contrecord before doing anything else */
8024-
if (!XLogRecPtrIsInvalid(abortedRecPtr))
8025-
{
8026-
Assert(!XLogRecPtrIsInvalid(missingContrecPtr));
8027-
CreateOverwriteContrecordRecord(abortedRecPtr);
8028-
abortedRecPtr = InvalidXLogRecPtr;
8029-
missingContrecPtr = InvalidXLogRecPtr;
8030-
}
8031-
8032-
/*
8033-
* Update full_page_writes in shared memory and write an XLOG_FPW_CHANGE
8034-
* record before resource manager writes cleanup WAL records or checkpoint
8035-
* record is written.
8036-
*/
8037-
Insert->fullPageWrites = lastFullPageWrites;
8038-
UpdateFullPageWrites();
8039-
LocalXLogInsertAllowed = -1;
8040-
8041-
/* Emit checkpoint or end-of-recovery record in XLOG, if required. */
8042-
if (InRecovery)
8043-
promoted = PerformRecoveryXLogAction();
8044-
8045-
/* If this is archive recovery, perform post-recovery cleanup actions. */
8046-
if (ArchiveRecoveryRequested)
8047-
CleanupAfterArchiveRecovery(EndOfLogTLI, EndOfLog);
8048-
80498021
/*
80508022
* Preallocate additional log files, if wanted.
80518023
*/
@@ -8090,6 +8062,42 @@ StartupXLOG(void)
80908062
}
80918063
XLogReaderFree(xlogreader);
80928064

8065+
LocalSetXLogInsertAllowed();
8066+
8067+
/* If necessary, write overwrite-contrecord before doing anything else */
8068+
if (!XLogRecPtrIsInvalid(abortedRecPtr))
8069+
{
8070+
Assert(!XLogRecPtrIsInvalid(missingContrecPtr));
8071+
CreateOverwriteContrecordRecord(abortedRecPtr);
8072+
abortedRecPtr = InvalidXLogRecPtr;
8073+
missingContrecPtr = InvalidXLogRecPtr;
8074+
}
8075+
8076+
/*
8077+
* Update full_page_writes in shared memory and write an XLOG_FPW_CHANGE
8078+
* record before resource manager writes cleanup WAL records or checkpoint
8079+
* record is written.
8080+
*/
8081+
Insert->fullPageWrites = lastFullPageWrites;
8082+
UpdateFullPageWrites();
8083+
LocalXLogInsertAllowed = -1;
8084+
8085+
/*
8086+
* Emit checkpoint or end-of-recovery record in XLOG, if required.
8087+
*
8088+
* XLogCtl->lastReplayedEndRecPtr will be a valid LSN if and only if we
8089+
* entered recovery. Even if we ultimately replayed no WAL records, it will
8090+
* have been initialized based on where replay was due to start. We don't
8091+
* need a lock to access this, since this can't change any more by the time
8092+
* we reach this code.
8093+
*/
8094+
if (!XLogRecPtrIsInvalid(XLogCtl->lastReplayedEndRecPtr))
8095+
promoted = PerformRecoveryXLogAction();
8096+
8097+
/* If this is archive recovery, perform post-recovery cleanup actions. */
8098+
if (ArchiveRecoveryRequested)
8099+
CleanupAfterArchiveRecovery(EndOfLogTLI, EndOfLog);
8100+
80938101
/*
80948102
* If any of the critical GUCs have changed, log them before we allow
80958103
* backends to write WAL.

0 commit comments

Comments
 (0)