aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlog.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-09-13 02:12:17 -0700
committerAndres Freund <andres@anarazel.de>2017-09-14 14:14:34 -0700
commit8356753c212a5865469c9befc4cf1e637a9d8bbc (patch)
tree60fcf71cb5a90a687e5306263d9831e89e413ab4 /src/backend/access/transam/xlog.c
parent0a480502b092195a9b25a2f0f199a21d592a9c57 (diff)
downloadpostgresql-8356753c212a5865469c9befc4cf1e637a9d8bbc.tar.gz
postgresql-8356753c212a5865469c9befc4cf1e637a9d8bbc.zip
Perform only one ReadControlFile() during startup.
Previously we read the control file in multiple places. But soon the segment size will be configurable and stored in the control file, and that needs to be available earlier than it currently is needed. Instead of adding yet another place where it's read, refactor things so there's a single processing of the control file during startup (in EXEC_BACKEND that's every individual backend's startup). Author: Andres Freund Discussion: http://postgr.es/m/20170913092828.aozd3gvvmw67gmyc@alap3.anarazel.de
Diffstat (limited to 'src/backend/access/transam/xlog.c')
-rw-r--r--src/backend/access/transam/xlog.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a3e8ce092fa..b8f648927a2 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4800,6 +4800,22 @@ check_wal_buffers(int *newval, void **extra, GucSource source)
}
/*
+ * Read the control file, set respective GUCs.
+ *
+ * This is to be called during startup, unless in bootstrap mode, where no
+ * control file yet exists. As there's no shared memory yet (its sizing can
+ * depend on the contents of the control file!), first store data in local
+ * memory. XLOGShemInit() will then copy it to shared memory later.
+ */
+void
+LocalProcessControlFile(void)
+{
+ Assert(ControlFile == NULL);
+ ControlFile = palloc(sizeof(ControlFileData));
+ ReadControlFile();
+}
+
+/*
* Initialization of shared memory for XLOG
*/
Size
@@ -4850,6 +4866,7 @@ XLOGShmemInit(void)
foundXLog;
char *allocptr;
int i;
+ ControlFileData *localControlFile;
#ifdef WAL_DEBUG
@@ -4867,8 +4884,18 @@ XLOGShmemInit(void)
}
#endif
+ /*
+ * Already have read control file locally, unless in bootstrap mode. Move
+ * local version into shared memory.
+ */
+ localControlFile = ControlFile;
ControlFile = (ControlFileData *)
ShmemInitStruct("Control File", sizeof(ControlFileData), &foundCFile);
+ if (localControlFile)
+ {
+ memcpy(ControlFile, localControlFile, sizeof(ControlFileData));
+ pfree(localControlFile);
+ }
XLogCtl = (XLogCtlData *)
ShmemInitStruct("XLOG Ctl", XLOGShmemSize(), &foundXLog);
@@ -4933,14 +4960,6 @@ XLOGShmemInit(void)
SpinLockInit(&XLogCtl->info_lck);
SpinLockInit(&XLogCtl->ulsn_lck);
InitSharedLatch(&XLogCtl->recoveryWakeupLatch);
-
- /*
- * If we are not in bootstrap mode, pg_control should already exist. Read
- * and validate it immediately (see comments in ReadControlFile() for the
- * reasons why).
- */
- if (!IsBootstrapProcessingMode())
- ReadControlFile();
}
/*
@@ -5129,6 +5148,12 @@ BootStrapXLOG(void)
BootStrapMultiXact();
pfree(buffer);
+
+ /*
+ * Force control file to be read - in contrast to normal processing we'd
+ * otherwise never run the checks and GUC related initializations therein.
+ */
+ ReadControlFile();
}
static char *
@@ -6227,13 +6252,8 @@ StartupXLOG(void)
struct stat st;
/*
- * Read control file and check XLOG status looks valid.
- *
- * Note: in most control paths, *ControlFile is already valid and we need
- * not do ReadControlFile() here, but might as well do it to be sure.
+ * Verify XLOG status looks valid.
*/
- ReadControlFile();
-
if (ControlFile->state < DB_SHUTDOWNED ||
ControlFile->state > DB_IN_PRODUCTION ||
!XRecOffIsValid(ControlFile->checkPoint))