Skip to content

Commit 6ab5835

Browse files
committed
Work around gcc 4.6.0 bug that breaks WAL replay.
ReadRecord's habit of using both direct references to tmpRecPtr and references to *RecPtr (which is pointing at tmpRecPtr) triggers an optimization bug in gcc 4.6.0, which apparently has forgotten about aliasing rules. Avoid the compiler bug, and make the code more readable to boot, by getting rid of the direct references. Improve the comments while at it. Back-patch to all supported versions, in case they get built with 4.6.0. Tom Lane, with some cosmetic suggestions from Alex Hunsaker
1 parent 376f93e commit 6ab5835

File tree

1 file changed

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

1 file changed

+11
-9
lines changed

src/backend/access/transam/xlog.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,12 +3041,12 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
30413041
goto got_record;
30423042
}
30433043
/* align old recptr to next page */
3044-
if (tmpRecPtr.xrecoff % XLOG_BLCKSZ != 0)
3045-
tmpRecPtr.xrecoff += (XLOG_BLCKSZ - tmpRecPtr.xrecoff % XLOG_BLCKSZ);
3046-
if (tmpRecPtr.xrecoff >= XLogFileSize)
3044+
if (RecPtr->xrecoff % XLOG_BLCKSZ != 0)
3045+
RecPtr->xrecoff += (XLOG_BLCKSZ - RecPtr->xrecoff % XLOG_BLCKSZ);
3046+
if (RecPtr->xrecoff >= XLogFileSize)
30473047
{
3048-
(tmpRecPtr.xlogid)++;
3049-
tmpRecPtr.xrecoff = 0;
3048+
(RecPtr->xlogid)++;
3049+
RecPtr->xrecoff = 0;
30503050
}
30513051
/* We will account for page header size below */
30523052
}
@@ -3132,11 +3132,13 @@ ReadRecord(XLogRecPtr *RecPtr, int emode)
31323132
if (targetRecOff == 0)
31333133
{
31343134
/*
3135-
* Can only get here in the continuing-from-prev-page case, because
3136-
* XRecOffIsValid eliminated the zero-page-offset case otherwise. Need
3137-
* to skip over the new page's header.
3135+
* At page start, so skip over page header. The Assert checks that
3136+
* we're not scribbling on caller's record pointer; it's OK because we
3137+
* can only get here in the continuing-from-prev-record case, since
3138+
* XRecOffIsValid rejected the zero-page-offset case otherwise.
31383139
*/
3139-
tmpRecPtr.xrecoff += pageHeaderSize;
3140+
Assert(RecPtr == &tmpRecPtr);
3141+
RecPtr->xrecoff += pageHeaderSize;
31403142
targetRecOff = pageHeaderSize;
31413143
}
31423144
else if (targetRecOff < pageHeaderSize)

0 commit comments

Comments
 (0)