Skip to content

Commit ff5a354

Browse files
committed
Fix is-it-time-for-a-checkpoint logic so that checkpoint_segments can
usefully be larger than 255. Per gripe from Simon Riggs.
1 parent 24658a2 commit ff5a354

File tree

1 file changed

+26
-9
lines changed
  • src/backend/access/transam

1 file changed

+26
-9
lines changed

src/backend/access/transam/xlog.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, 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.178 2004/11/17 16:26:59 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.179 2004/12/17 00:10:36 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1201,21 +1201,38 @@ XLogWrite(XLogwrtRqst WriteRqst)
12011201
UpdateControlFile();
12021202

12031203
/*
1204-
* Signal postmaster to start a checkpoint if it's been
1204+
* Signal bgwriter to start a checkpoint if it's been
12051205
* too long since the last one. (We look at local copy of
12061206
* RedoRecPtr which might be a little out of date, but
12071207
* should be close enough for this purpose.)
1208+
*
1209+
* A straight computation of segment number could overflow
1210+
* 32 bits. Rather than assuming we have working 64-bit
1211+
* arithmetic, we compare the highest-order bits separately,
1212+
* and force a checkpoint immediately when they change.
12081213
*/
1209-
if (IsUnderPostmaster &&
1210-
(openLogId != RedoRecPtr.xlogid ||
1211-
openLogSeg >= (RedoRecPtr.xrecoff / XLogSegSize) +
1212-
(uint32) CheckPointSegments))
1214+
if (IsUnderPostmaster)
12131215
{
1216+
uint32 old_segno,
1217+
new_segno;
1218+
uint32 old_highbits,
1219+
new_highbits;
1220+
1221+
old_segno = (RedoRecPtr.xlogid % XLogSegSize) * XLogSegsPerFile +
1222+
(RedoRecPtr.xrecoff / XLogSegSize);
1223+
old_highbits = RedoRecPtr.xlogid / XLogSegSize;
1224+
new_segno = (openLogId % XLogSegSize) * XLogSegsPerFile +
1225+
openLogSeg;
1226+
new_highbits = openLogId / XLogSegSize;
1227+
if (new_highbits != old_highbits ||
1228+
new_segno >= old_segno + (uint32) CheckPointSegments)
1229+
{
12141230
#ifdef WAL_DEBUG
1215-
if (XLOG_DEBUG)
1216-
elog(LOG, "time for a checkpoint, signaling bgwriter");
1231+
if (XLOG_DEBUG)
1232+
elog(LOG, "time for a checkpoint, signaling bgwriter");
12171233
#endif
1218-
RequestCheckpoint(false);
1234+
RequestCheckpoint(false);
1235+
}
12191236
}
12201237
}
12211238
LWLockRelease(ControlFileLock);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy