Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8356753

Browse files
committed
Perform only one ReadControlFile() during startup.
Previously we read the control file in multiple places. But soon thesegment size will be configurable and stored in the control file, andthat needs to be available earlier than it currently is needed.Instead of adding yet another place where it's read, refactor thingsso there's a single processing of the control file during startup (inEXEC_BACKEND that's every individual backend's startup).Author: Andres FreundDiscussion:http://postgr.es/m/20170913092828.aozd3gvvmw67gmyc@alap3.anarazel.de
1 parent0a48050 commit8356753

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,6 +4799,22 @@ check_wal_buffers(int *newval, void **extra, GucSource source)
47994799
return true;
48004800
}
48014801

4802+
/*
4803+
* Read the control file, set respective GUCs.
4804+
*
4805+
* This is to be called during startup, unless in bootstrap mode, where no
4806+
* control file yet exists. As there's no shared memory yet (its sizing can
4807+
* depend on the contents of the control file!), first store data in local
4808+
* memory. XLOGShemInit() will then copy it to shared memory later.
4809+
*/
4810+
void
4811+
LocalProcessControlFile(void)
4812+
{
4813+
Assert(ControlFile==NULL);
4814+
ControlFile=palloc(sizeof(ControlFileData));
4815+
ReadControlFile();
4816+
}
4817+
48024818
/*
48034819
* Initialization of shared memory for XLOG
48044820
*/
@@ -4850,6 +4866,7 @@ XLOGShmemInit(void)
48504866
foundXLog;
48514867
char*allocptr;
48524868
inti;
4869+
ControlFileData*localControlFile;
48534870

48544871
#ifdefWAL_DEBUG
48554872

@@ -4867,8 +4884,18 @@ XLOGShmemInit(void)
48674884
}
48684885
#endif
48694886

4887+
/*
4888+
* Already have read control file locally, unless in bootstrap mode. Move
4889+
* local version into shared memory.
4890+
*/
4891+
localControlFile=ControlFile;
48704892
ControlFile= (ControlFileData*)
48714893
ShmemInitStruct("Control File",sizeof(ControlFileData),&foundCFile);
4894+
if (localControlFile)
4895+
{
4896+
memcpy(ControlFile,localControlFile,sizeof(ControlFileData));
4897+
pfree(localControlFile);
4898+
}
48724899
XLogCtl= (XLogCtlData*)
48734900
ShmemInitStruct("XLOG Ctl",XLOGShmemSize(),&foundXLog);
48744901

@@ -4933,14 +4960,6 @@ XLOGShmemInit(void)
49334960
SpinLockInit(&XLogCtl->info_lck);
49344961
SpinLockInit(&XLogCtl->ulsn_lck);
49354962
InitSharedLatch(&XLogCtl->recoveryWakeupLatch);
4936-
4937-
/*
4938-
* If we are not in bootstrap mode, pg_control should already exist. Read
4939-
* and validate it immediately (see comments in ReadControlFile() for the
4940-
* reasons why).
4941-
*/
4942-
if (!IsBootstrapProcessingMode())
4943-
ReadControlFile();
49444963
}
49454964

49464965
/*
@@ -5129,6 +5148,12 @@ BootStrapXLOG(void)
51295148
BootStrapMultiXact();
51305149

51315150
pfree(buffer);
5151+
5152+
/*
5153+
* Force control file to be read - in contrast to normal processing we'd
5154+
* otherwise never run the checks and GUC related initializations therein.
5155+
*/
5156+
ReadControlFile();
51325157
}
51335158

51345159
staticchar*
@@ -6227,13 +6252,8 @@ StartupXLOG(void)
62276252
structstatst;
62286253

62296254
/*
6230-
* Read control file and check XLOG status looks valid.
6231-
*
6232-
* Note: in most control paths, *ControlFile is already valid and we need
6233-
* not do ReadControlFile() here, but might as well do it to be sure.
6255+
* Verify XLOG status looks valid.
62346256
*/
6235-
ReadControlFile();
6236-
62376257
if (ControlFile->state<DB_SHUTDOWNED||
62386258
ControlFile->state>DB_IN_PRODUCTION||
62396259
!XRecOffIsValid(ControlFile->checkPoint))

‎src/backend/postmaster/postmaster.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,9 @@ PostmasterMain(int argc, char *argv[])
950950
*/
951951
CreateDataDirLockFile(true);
952952

953+
/* read control file (error checking and contains config) */
954+
LocalProcessControlFile();
955+
953956
/*
954957
* Initialize SSL library, if specified.
955958
*/
@@ -4805,6 +4808,9 @@ SubPostmasterMain(int argc, char *argv[])
48054808
/* Read in remaining GUC variables */
48064809
read_nondefault_variables();
48074810

4811+
/* (re-)read control file (contains config) */
4812+
LocalProcessControlFile();
4813+
48084814
/*
48094815
* Reload any libraries that were preloaded by the postmaster. Since we
48104816
* exec'd this process, those libraries didn't come along with us; but we

‎src/backend/tcop/postgres.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,6 +3717,9 @@ PostgresMain(int argc, char *argv[],
37173717
*/
37183718
CreateDataDirLockFile(false);
37193719

3720+
/* read control file (error checking and contains config ) */
3721+
LocalProcessControlFile();
3722+
37203723
/* Initialize MaxBackends (if under postmaster, was done already) */
37213724
InitializeMaxBackends();
37223725
}

‎src/include/access/xlog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
261261
externSizeXLOGShmemSize(void);
262262
externvoidXLOGShmemInit(void);
263263
externvoidBootStrapXLOG(void);
264+
externvoidLocalProcessControlFile(void);
264265
externvoidStartupXLOG(void);
265266
externvoidShutdownXLOG(intcode,Datumarg);
266267
externvoidInitXLOGAccess(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp