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

Commitec9e05b

Browse files
committed
Fix crash restart bug introduced in8356753.
The bug was caused by not re-reading the control file during crashrecovery restarts, which lead to an attempt to pfree() shared memorycontents. The fix is to re-read the control file, which seems goodanyway.It's unclear as of this moment, whether we want to keep therefactoring introduced in the commit referenced above, or come up withan alternative approach. But fixing the bug in the mean time seemslike a good idea regardless.A followup commit will introduce regression test coverage for crashrestarts.Reported-By: Tom LaneDiscussion:https://postgr.es/m/14134.1505572349@sss.pgh.pa.us
1 parenteb5c404 commitec9e05b

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4802,15 +4802,19 @@ check_wal_buffers(int *newval, void **extra, GucSource source)
48024802
/*
48034803
* Read the control file, set respective GUCs.
48044804
*
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.
4805+
* This is to be called during startup, including a crash recovery cycle,
4806+
* unless in bootstrap mode, where no control file yet exists. As there's no
4807+
* usable shared memory yet (its sizing can depend on the contents of the
4808+
* control file!), first store the contents in local memory. XLOGShemInit()
4809+
* will then copy it to shared memory later.
4810+
*
4811+
* reset just controls whether previous contents are to be expected (in the
4812+
* reset case, there's a dangling pointer into old shared memory), or not.
48094813
*/
48104814
void
4811-
LocalProcessControlFile(void)
4815+
LocalProcessControlFile(boolreset)
48124816
{
4813-
Assert(ControlFile==NULL);
4817+
Assert(reset||ControlFile==NULL);
48144818
ControlFile=palloc(sizeof(ControlFileData));
48154819
ReadControlFile();
48164820
}
@@ -4884,20 +4888,13 @@ XLOGShmemInit(void)
48844888
}
48854889
#endif
48864890

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

49024899
if (foundCFile||foundXLog)
49034900
{
@@ -4908,10 +4905,23 @@ XLOGShmemInit(void)
49084905
WALInsertLocks=XLogCtl->Insert.WALInsertLocks;
49094906
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,
49104907
"wal_insert");
4908+
4909+
if (localControlFile)
4910+
pfree(localControlFile);
49114911
return;
49124912
}
49134913
memset(XLogCtl,0,sizeof(XLogCtlData));
49144914

4915+
/*
4916+
* Already have read control file locally, unless in bootstrap mode. Move
4917+
* contents into shared memory.
4918+
*/
4919+
if (localControlFile)
4920+
{
4921+
memcpy(ControlFile,localControlFile,sizeof(ControlFileData));
4922+
pfree(localControlFile);
4923+
}
4924+
49154925
/*
49164926
* Since XLogCtlData contains XLogRecPtr fields, its sizeof should be a
49174927
* multiple of the alignment for same, so no extra alignment padding is

‎src/backend/postmaster/postmaster.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ PostmasterMain(int argc, char *argv[])
951951
CreateDataDirLockFile(true);
952952

953953
/* read control file (error checking and contains config) */
954-
LocalProcessControlFile();
954+
LocalProcessControlFile(false);
955955

956956
/*
957957
* Initialize SSL library, if specified.
@@ -3829,6 +3829,10 @@ PostmasterStateMachine(void)
38293829
ResetBackgroundWorkerCrashTimes();
38303830

38313831
shmem_exit(1);
3832+
3833+
/* re-read control file into local memory */
3834+
LocalProcessControlFile(true);
3835+
38323836
reset_shared(PostPortNumber);
38333837

38343838
StartupPID=StartupDataBase();
@@ -4808,8 +4812,11 @@ SubPostmasterMain(int argc, char *argv[])
48084812
/* Read in remaining GUC variables */
48094813
read_nondefault_variables();
48104814

4811-
/* (re-)read control file (contains config) */
4812-
LocalProcessControlFile();
4815+
/*
4816+
* (re-)read control file, as it contains config. The postmaster will
4817+
* already have read this, but this process doesn't know about that.
4818+
*/
4819+
LocalProcessControlFile(false);
48134820

48144821
/*
48154822
* Reload any libraries that were preloaded by the postmaster. Since we

‎src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3718,7 +3718,7 @@ PostgresMain(int argc, char *argv[],
37183718
CreateDataDirLockFile(false);
37193719

37203720
/* read control file (error checking and contains config ) */
3721-
LocalProcessControlFile();
3721+
LocalProcessControlFile(false);
37223722

37233723
/* Initialize MaxBackends (if under postmaster, was done already) */
37243724
InitializeMaxBackends();

‎src/include/access/xlog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
261261
externSizeXLOGShmemSize(void);
262262
externvoidXLOGShmemInit(void);
263263
externvoidBootStrapXLOG(void);
264-
externvoidLocalProcessControlFile(void);
264+
externvoidLocalProcessControlFile(boolreset);
265265
externvoidStartupXLOG(void);
266266
externvoidShutdownXLOG(intcode,Datumarg);
267267
externvoidInitXLOGAccess(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp