aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlogutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-02-12 14:52:16 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2014-02-12 14:52:16 -0500
commit6f2aead1ffec6f056dc3c371c2ec6a12d7d5ccd3 (patch)
treeb760ef69b5c77ca6db773bb44bad44cc2014e7da /src/backend/access/transam/xlogutils.c
parent48870dd9f752db7f953dde54b3d16e82d529e0db (diff)
downloadpostgresql-6f2aead1ffec6f056dc3c371c2ec6a12d7d5ccd3.tar.gz
postgresql-6f2aead1ffec6f056dc3c371c2ec6a12d7d5ccd3.zip
In XLogReadBufferExtended, don't assume P_NEW yields consecutive pages.
In a database that's not yet reached consistency, it's possible that some segments of a relation are not full-size but are not the last ones either. Because of the way smgrnblocks() works, asking for a new page with P_NEW will fill in the last not-full-size segment --- and if that makes it full size, the apparent EOF of the relation will increase by more than one page, so that the next P_NEW request will yield a page past the next consecutive one. This breaks the relation-extension logic in XLogReadBufferExtended, possibly allowing a page update to be applied to some page far past where it was intended to go. This appears to be the explanation for reports of table bloat on replication slaves compared to their masters, and probably explains some corrupted-slave reports as well. Fix the loop to check the page number it actually got, rather than merely Assert()'ing that dead reckoning got it to the desired place. AFAICT, there are no other places that make assumptions about exactly which page they'll get from P_NEW. Problem identified by Greg Stark, though this is not the same as his proposed patch. It's been like this for a long time, so back-patch to all supported branches.
Diffstat (limited to 'src/backend/access/transam/xlogutils.c')
-rw-r--r--src/backend/access/transam/xlogutils.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index 4cd82dfeb79..f1918f6b078 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -338,15 +338,21 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
/* we do this in recovery only - no rel-extension lock needed */
Assert(InRecovery);
buffer = InvalidBuffer;
- while (blkno >= lastblock)
+ do
{
if (buffer != InvalidBuffer)
ReleaseBuffer(buffer);
buffer = ReadBufferWithoutRelcache(rnode, forknum,
P_NEW, mode, NULL);
- lastblock++;
}
- Assert(BufferGetBlockNumber(buffer) == blkno);
+ while (BufferGetBlockNumber(buffer) < blkno);
+ /* Handle the corner case that P_NEW returns non-consecutive pages */
+ if (BufferGetBlockNumber(buffer) != blkno)
+ {
+ ReleaseBuffer(buffer);
+ buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno,
+ mode, NULL);
+ }
}
if (mode == RBM_NORMAL)