From 59cf52ec065445c0151f086b5627e48a08d97166 Mon Sep 17 00:00:00 2001 From: Dilip Kumar Date: Thu, 10 Feb 2022 15:55:33 +0530 Subject: [PATCH v14 3/6] Allow ReadBufferWithoutRelcache to support unlogged relpersistence At present, this function may only be used on permanent relations, because we only use it during XLOG replay. But now as part of the bigger patch set, we will be using this for reading the buffer from the database to which we are not connected. So now we need this for the unlogged relations as well. --- src/backend/access/transam/xlogutils.c | 6 +++--- src/backend/storage/buffer/bufmgr.c | 18 ++++++++++-------- src/include/storage/bufmgr.h | 3 ++- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 54d5f20..a05bdd0 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -484,7 +484,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, { /* page exists in file */ buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno, - mode, NULL); + mode, NULL, false); } else { @@ -509,7 +509,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, ReleaseBuffer(buffer); } buffer = ReadBufferWithoutRelcache(rnode, forknum, - P_NEW, mode, NULL); + P_NEW, mode, NULL, false); } while (BufferGetBlockNumber(buffer) < blkno); /* Handle the corner case that P_NEW returns non-consecutive pages */ @@ -519,7 +519,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, LockBuffer(buffer, BUFFER_LOCK_UNLOCK); ReleaseBuffer(buffer); buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno, - mode, NULL); + mode, NULL, false); } } diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index f5459c6..3e4926f 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -772,23 +772,25 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, * ReadBufferWithoutRelcache -- like ReadBufferExtended, but doesn't require * a relcache entry for the relation. * - * NB: At present, this function may only be used on permanent relations, which - * is OK, because we only use it during XLOG replay. If in the future we - * want to use it on temporary or unlogged relations, we could pass additional - * parameters. + * The caller should pass 'isunlogged' as true for the unlogged relation and + * false for the regular relation. + * + * NB: At present, this function may only be used on unlogged and regular + * relations, which is OK, because we only use it during XLOG replay and while + * copying the database. If in the future we want to use it on temporary + * relations, we could pass additional parameters. */ Buffer ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, - BufferAccessStrategy strategy) + BufferAccessStrategy strategy, bool isunlogged) { bool hit; SMgrRelation smgr = smgropen(rnode, InvalidBackendId); - Assert(InRecovery); - - return ReadBuffer_common(smgr, RELPERSISTENCE_PERMANENT, forkNum, blockNum, + return ReadBuffer_common(smgr, isunlogged ? RELPERSISTENCE_UNLOGGED : + RELPERSISTENCE_PERMANENT, forkNum, blockNum, mode, strategy, &hit); } diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h index dd01841..699d06b 100644 --- a/src/include/storage/bufmgr.h +++ b/src/include/storage/bufmgr.h @@ -184,7 +184,8 @@ extern Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BufferAccessStrategy strategy); extern Buffer ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum, - ReadBufferMode mode, BufferAccessStrategy strategy); + ReadBufferMode mode, BufferAccessStrategy strategy, + bool isunlogged); extern void ReleaseBuffer(Buffer buffer); extern void UnlockReleaseBuffer(Buffer buffer); extern void MarkBufferDirty(Buffer buffer); -- 1.8.3.1