Skip to content

Commit 9c41ab4

Browse files
anarazelpull[bot]
authored andcommitted
Use ExtendBufferedRelTo() in XLogReadBufferExtended()
Instead of extending the relation block-by-block, use ExtendBufferedRelTo(), introduced in 31966b1. This is faster and simpler. This also somewhat reduces the danger that disconnected segments pose (which can be "discovered" once the previous segment reaches SEGSIZE), as ExtendBufferedRelTo() won't extend past the block it has been asked. However, the risk of the content of such a disconnected segment being invalid remains. Discussion: https://postgr.es/m/20221029025420.eplyow6k7tgu6he3@awork3.anarazel.de Discussion: https://postgr.es/m/20230223010147.32oir7sb66slqnjk@awork3.anarazel.de
1 parent d591cb8 commit 9c41ab4

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/backend/access/transam/xlogutils.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -524,28 +524,13 @@ XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum,
524524
/* OK to extend the file */
525525
/* we do this in recovery only - no rel-extension lock needed */
526526
Assert(InRecovery);
527-
buffer = InvalidBuffer;
528-
do
529-
{
530-
if (buffer != InvalidBuffer)
531-
{
532-
if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK)
533-
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
534-
ReleaseBuffer(buffer);
535-
}
536-
buffer = ReadBufferWithoutRelcache(rlocator, forknum,
537-
P_NEW, mode, NULL, true);
538-
}
539-
while (BufferGetBlockNumber(buffer) < blkno);
540-
/* Handle the corner case that P_NEW returns non-consecutive pages */
541-
if (BufferGetBlockNumber(buffer) != blkno)
542-
{
543-
if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK)
544-
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
545-
ReleaseBuffer(buffer);
546-
buffer = ReadBufferWithoutRelcache(rlocator, forknum, blkno,
547-
mode, NULL, true);
548-
}
527+
buffer = ExtendBufferedRelTo(EB_SMGR(smgr, RELPERSISTENCE_PERMANENT),
528+
forknum,
529+
NULL,
530+
EB_PERFORMING_RECOVERY |
531+
EB_SKIP_EXTENSION_LOCK,
532+
blkno + 1,
533+
mode);
549534
}
550535

551536
recent_buffer_fast_path:

0 commit comments

Comments
 (0)