aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlogutils.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-04-06 17:45:42 -0700
committerAndres Freund <andres@anarazel.de>2023-04-06 17:56:17 -0700
commit26158b852d3adf6936008ce09c9ff2b947c8df40 (patch)
tree498e3e54b276023daca6f79543214b35b5542ba8 /src/backend/access/transam/xlogutils.c
parentae78cae3be627213528f2e08eb976d6906d754de (diff)
downloadpostgresql-26158b852d3adf6936008ce09c9ff2b947c8df40.tar.gz
postgresql-26158b852d3adf6936008ce09c9ff2b947c8df40.zip
Use ExtendBufferedRelTo() in XLogReadBufferExtended()
Instead of extending the relation block-by-block, use ExtendBufferedRelTo(), introduced in 31966b151e6. 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
Diffstat (limited to 'src/backend/access/transam/xlogutils.c')
-rw-r--r--src/backend/access/transam/xlogutils.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index 2c28956b1aa..e174a2a8919 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -524,28 +524,13 @@ XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum,
/* OK to extend the file */
/* we do this in recovery only - no rel-extension lock needed */
Assert(InRecovery);
- buffer = InvalidBuffer;
- do
- {
- if (buffer != InvalidBuffer)
- {
- if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK)
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
- ReleaseBuffer(buffer);
- }
- buffer = ReadBufferWithoutRelcache(rlocator, forknum,
- P_NEW, mode, NULL, true);
- }
- while (BufferGetBlockNumber(buffer) < blkno);
- /* Handle the corner case that P_NEW returns non-consecutive pages */
- if (BufferGetBlockNumber(buffer) != blkno)
- {
- if (mode == RBM_ZERO_AND_LOCK || mode == RBM_ZERO_AND_CLEANUP_LOCK)
- LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
- ReleaseBuffer(buffer);
- buffer = ReadBufferWithoutRelcache(rlocator, forknum, blkno,
- mode, NULL, true);
- }
+ buffer = ExtendBufferedRelTo(EB_SMGR(smgr, RELPERSISTENCE_PERMANENT),
+ forknum,
+ NULL,
+ EB_PERFORMING_RECOVERY |
+ EB_SKIP_EXTENSION_LOCK,
+ blkno + 1,
+ mode);
}
recent_buffer_fast_path: