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

Commit7fedd79

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 parente1e7642 commit7fedd79

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
@@ -314,15 +314,21 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
314314
/* we do this in recovery only - no rel-extension lock needed */
315315
Assert(InRecovery);
316316
buffer=InvalidBuffer;
317-
while (blkno >=lastblock)
317+
do
318318
{
319319
if (buffer!=InvalidBuffer)
320320
ReleaseBuffer(buffer);
321321
buffer=ReadBufferWithoutRelcache(rnode, false,forknum,
322322
P_NEW,mode,NULL);
323-
lastblock++;
324323
}
325-
Assert(BufferGetBlockNumber(buffer)==blkno);
324+
while (BufferGetBlockNumber(buffer)<blkno);
325+
/* Handle the corner case that P_NEW returns non-consecutive pages */
326+
if (BufferGetBlockNumber(buffer)!=blkno)
327+
{
328+
ReleaseBuffer(buffer);
329+
buffer=ReadBufferWithoutRelcache(rnode, false,forknum,blkno,
330+
mode,NULL);
331+
}
326332
}
327333

328334
if (mode==RBM_NORMAL)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp