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

Commit3b682df

Browse files
committed
Simplify the way changes to full_page_writes are logged.
It's harmless to do full page writes even when not strictly necessary, sowhen turning full_page_writes on, we can set the global flag first, and thencall XLogInsert. Likewise, when turning it off, we can write the WAL recordfirst, and then clear the flag. This way XLogInsert doesn't need any specialhandling of the XLOG_FPW_CHANGE record type. XLogInsert is complicatedenough already, so anything we can keep away from there is a good thing.Actually I don't think the atomicity of the shared memory flag matters,anyway, because we only write the XLOG_FPW_CHANGE at the end of recovery,when there are no concurrent WAL insertions going on. But might as well makeit safe, in case we allow changing full_page_writes on the fly in thefuture.
1 parent2127aac commit3b682df

File tree

1 file changed

+25
-35
lines changed
  • src/backend/access/transam

1 file changed

+25
-35
lines changed

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

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
731731
unsignedi;
732732
boolupdrqst;
733733
booldoPageWrites;
734-
boolisLogSwitch= false;
735-
boolfpwChange= false;
734+
boolisLogSwitch= (rmid==RM_XLOG_ID&&info==XLOG_SWITCH);
736735
uint8info_orig=info;
737736

738737
/* cross-check on whether we should be here or not */
@@ -746,30 +745,11 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
746745
TRACE_POSTGRESQL_XLOG_INSERT(rmid,info);
747746

748747
/*
749-
* Handle special cases/records.
748+
* In bootstrap mode, we don't actually log anything but XLOG resources;
749+
* return a phony record pointer.
750750
*/
751-
if (rmid==RM_XLOG_ID)
751+
if (IsBootstrapProcessingMode()&&rmid!=RM_XLOG_ID)
752752
{
753-
switch (info)
754-
{
755-
caseXLOG_SWITCH:
756-
isLogSwitch= true;
757-
break;
758-
759-
caseXLOG_FPW_CHANGE:
760-
fpwChange= true;
761-
break;
762-
763-
default:
764-
break;
765-
}
766-
}
767-
elseif (IsBootstrapProcessingMode())
768-
{
769-
/*
770-
* In bootstrap mode, we don't actually log anything but XLOG resources;
771-
* return a phony record pointer.
772-
*/
773753
RecPtr.xlogid=0;
774754
RecPtr.xrecoff=SizeOfXLogLongPHD;/* start of 1st chkpt record */
775755
returnRecPtr;
@@ -1232,15 +1212,6 @@ begin:;
12321212
WriteRqst=XLogCtl->xlblocks[curridx];
12331213
}
12341214

1235-
/*
1236-
* If the record is an XLOG_FPW_CHANGE, we update full_page_writes
1237-
* in shared memory before releasing WALInsertLock. This ensures that
1238-
* an XLOG_FPW_CHANGE record precedes any WAL record affected
1239-
* by this change of full_page_writes.
1240-
*/
1241-
if (fpwChange)
1242-
Insert->fullPageWrites=fullPageWrites;
1243-
12441215
LWLockRelease(WALInsertLock);
12451216

12461217
if (updrqst)
@@ -8517,6 +8488,22 @@ UpdateFullPageWrites(void)
85178488
if (fullPageWrites==Insert->fullPageWrites)
85188489
return;
85198490

8491+
START_CRIT_SECTION();
8492+
8493+
/*
8494+
* It's always safe to take full page images, even when not strictly
8495+
* required, but not the other round. So if we're setting full_page_writes
8496+
* to true, first set it true and then write the WAL record. If we're
8497+
* setting it to false, first write the WAL record and then set the
8498+
* global flag.
8499+
*/
8500+
if (fullPageWrites)
8501+
{
8502+
LWLockAcquire(WALInsertLock,LW_EXCLUSIVE);
8503+
Insert->fullPageWrites= true;
8504+
LWLockRelease(WALInsertLock);
8505+
}
8506+
85208507
/*
85218508
* Write an XLOG_FPW_CHANGE record. This allows us to keep
85228509
* track of full_page_writes during archive recovery, if required.
@@ -8532,12 +8519,15 @@ UpdateFullPageWrites(void)
85328519

85338520
XLogInsert(RM_XLOG_ID,XLOG_FPW_CHANGE,&rdata);
85348521
}
8535-
else
8522+
8523+
8524+
if (!fullPageWrites)
85368525
{
85378526
LWLockAcquire(WALInsertLock,LW_EXCLUSIVE);
8538-
Insert->fullPageWrites=fullPageWrites;
8527+
Insert->fullPageWrites=false;
85398528
LWLockRelease(WALInsertLock);
85408529
}
8530+
END_CRIT_SECTION();
85418531
}
85428532

85438533
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp