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

Commit5c8eb92

Browse files
committed
When telling the bgwriter that we need a checkpoint because too much xlog
has been consumed, recheck against the latest value of RedoRecPtr beforereally sending the signal. This avoids useless checkpoint activity ifXLogWrite is executed when we have a very stale local copy of RedoRecPtr.The potential for useless checkpoint is very much worse in 8.3 because ofthe walwriter process (which never does XLogInsert), so while this behaviorwas intentional, it needs to be changed. Per report from Itagaki Takahiro.
1 parent6daef2b commit5c8eb92

File tree

1 file changed

+43
-23
lines changed
  • src/backend/access/transam

1 file changed

+43
-23
lines changed

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

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.285 2007/09/30 17:28:56 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.286 2007/10/12 19:39:59 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1331,6 +1331,40 @@ AdvanceXLInsertBuffer(bool new_segment)
13311331
returnupdate_needed;
13321332
}
13331333

1334+
/*
1335+
* Check whether we've consumed enough xlog space that a checkpoint is needed.
1336+
*
1337+
* Caller must have just finished filling the open log file (so that
1338+
* openLogId/openLogSeg are valid). We measure the distance from RedoRecPtr
1339+
* to the open log file and see if that exceeds CheckPointSegments.
1340+
*
1341+
* Note: it is caller's responsibility that RedoRecPtr is up-to-date.
1342+
*/
1343+
staticbool
1344+
XLogCheckpointNeeded(void)
1345+
{
1346+
/*
1347+
* A straight computation of segment number could overflow 32
1348+
* bits. Rather than assuming we have working 64-bit
1349+
* arithmetic, we compare the highest-order bits separately,
1350+
* and force a checkpoint immediately when they change.
1351+
*/
1352+
uint32old_segno,
1353+
new_segno;
1354+
uint32old_highbits,
1355+
new_highbits;
1356+
1357+
old_segno= (RedoRecPtr.xlogid %XLogSegSize)*XLogSegsPerFile+
1358+
(RedoRecPtr.xrecoff /XLogSegSize);
1359+
old_highbits=RedoRecPtr.xlogid /XLogSegSize;
1360+
new_segno= (openLogId %XLogSegSize)*XLogSegsPerFile+openLogSeg;
1361+
new_highbits=openLogId /XLogSegSize;
1362+
if (new_highbits!=old_highbits||
1363+
new_segno >=old_segno+ (uint32) (CheckPointSegments-1))
1364+
return true;
1365+
return false;
1366+
}
1367+
13341368
/*
13351369
* Write and/or fsync the log at least as far as WriteRqst indicates.
13361370
*
@@ -1522,30 +1556,16 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
15221556

15231557
/*
15241558
* Signal bgwriter to start a checkpoint if we've consumed too
1525-
* much xlog since the last one. (We look at local copy of
1526-
* RedoRecPtr which might be a little out of date, but should
1527-
* be close enough for this purpose.)
1528-
*
1529-
* A straight computation of segment number could overflow 32
1530-
* bits. Rather than assuming we have working 64-bit
1531-
* arithmetic, we compare the highest-order bits separately,
1532-
* and force a checkpoint immediately when they change.
1559+
* much xlog since the last one. For speed, we first check
1560+
* using the local copy of RedoRecPtr, which might be
1561+
* out of date; if it looks like a checkpoint is needed,
1562+
* forcibly update RedoRecPtr and recheck.
15331563
*/
1534-
if (IsUnderPostmaster)
1564+
if (IsUnderPostmaster&&
1565+
XLogCheckpointNeeded())
15351566
{
1536-
uint32old_segno,
1537-
new_segno;
1538-
uint32old_highbits,
1539-
new_highbits;
1540-
1541-
old_segno= (RedoRecPtr.xlogid %XLogSegSize)*XLogSegsPerFile+
1542-
(RedoRecPtr.xrecoff /XLogSegSize);
1543-
old_highbits=RedoRecPtr.xlogid /XLogSegSize;
1544-
new_segno= (openLogId %XLogSegSize)*XLogSegsPerFile+
1545-
openLogSeg;
1546-
new_highbits=openLogId /XLogSegSize;
1547-
if (new_highbits!=old_highbits||
1548-
new_segno >=old_segno+ (uint32) (CheckPointSegments-1))
1567+
(void)GetRedoRecPtr();
1568+
if (XLogCheckpointNeeded())
15491569
RequestCheckpoint(CHECKPOINT_CAUSE_XLOG);
15501570
}
15511571
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp