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

Commit6f2aead

Browse files
committed
In XLogReadBufferExtended, don't assume P_NEW yields consecutive pages.
In a database that's not yet reached consistency, it's possible that somesegments 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_NEWwill fill in the last not-full-size segment --- and if that makes it fullsize, 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 consecutiveone. This breaks the relation-extension logic in XLogReadBufferExtended,possibly allowing a page update to be applied to some page far past whereit was intended to go. This appears to be the explanation for reports oftable bloat on replication slaves compared to their masters, and probablyexplains some corrupted-slave reports as well.Fix the loop to check the page number it actually got, rather than merelyAssert()'ing that dead reckoning got it to the desired place. AFAICT,there are no other places that make assumptions about exactly which pagethey'll get from P_NEW.Problem identified by Greg Stark, though this is not the same as hisproposed patch.It's been like this for a long time, so back-patch to all supportedbranches.
1 parent48870dd commit6f2aead

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,21 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
338338
/* we do this in recovery only - no rel-extension lock needed */
339339
Assert(InRecovery);
340340
buffer=InvalidBuffer;
341-
while (blkno >=lastblock)
341+
do
342342
{
343343
if (buffer!=InvalidBuffer)
344344
ReleaseBuffer(buffer);
345345
buffer=ReadBufferWithoutRelcache(rnode,forknum,
346346
P_NEW,mode,NULL);
347-
lastblock++;
348347
}
349-
Assert(BufferGetBlockNumber(buffer)==blkno);
348+
while (BufferGetBlockNumber(buffer)<blkno);
349+
/* Handle the corner case that P_NEW returns non-consecutive pages */
350+
if (BufferGetBlockNumber(buffer)!=blkno)
351+
{
352+
ReleaseBuffer(buffer);
353+
buffer=ReadBufferWithoutRelcache(rnode,forknum,blkno,
354+
mode,NULL);
355+
}
350356
}
351357

352358
if (mode==RBM_NORMAL)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp