|
7 | 7 | * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 |
| - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.178 2004/11/1716:26:59 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.179 2004/12/1700:10:36 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -1201,21 +1201,38 @@ XLogWrite(XLogwrtRqst WriteRqst)
|
1201 | 1201 | UpdateControlFile();
|
1202 | 1202 |
|
1203 | 1203 | /*
|
1204 |
| - * Signalpostmaster to start a checkpoint if it's been |
| 1204 | + * Signalbgwriter to start a checkpoint if it's been |
1205 | 1205 | * too long since the last one. (We look at local copy of
|
1206 | 1206 | * RedoRecPtr which might be a little out of date, but
|
1207 | 1207 | * 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. |
1208 | 1213 | */
|
1209 |
| -if (IsUnderPostmaster&& |
1210 |
| -(openLogId!=RedoRecPtr.xlogid|| |
1211 |
| -openLogSeg >= (RedoRecPtr.xrecoff /XLogSegSize)+ |
1212 |
| - (uint32)CheckPointSegments)) |
| 1214 | +if (IsUnderPostmaster) |
1213 | 1215 | {
|
| 1216 | +uint32old_segno, |
| 1217 | +new_segno; |
| 1218 | +uint32old_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 | +{ |
1214 | 1230 | #ifdefWAL_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"); |
1217 | 1233 | #endif
|
1218 |
| -RequestCheckpoint(false); |
| 1234 | +RequestCheckpoint(false); |
| 1235 | +} |
1219 | 1236 | }
|
1220 | 1237 | }
|
1221 | 1238 | LWLockRelease(ControlFileLock);
|
|