1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-25 01:02:05 +03:00

Add block_range_read_stream_cb(), to deduplicate code.

This replaces two functions for iterating over all blocks in a range.  A
pending patch will use this instead of adding a third.

Nazir Bilal Yavuz

Discussion: https://postgr.es/m/20240820184742.f2.nmisch@google.com
This commit is contained in:
Noah Misch
2024-09-03 10:46:20 -07:00
parent ba7625a7a5
commit c582b75851
5 changed files with 36 additions and 54 deletions

View File

@ -136,33 +136,6 @@ typedef struct SMgrSortArray
SMgrRelation srel;
} SMgrSortArray;
/*
* Helper struct for read stream object used in
* RelationCopyStorageUsingBuffer() function.
*/
struct copy_storage_using_buffer_read_stream_private
{
BlockNumber blocknum;
BlockNumber nblocks;
};
/*
* Callback function to get next block for read stream object used in
* RelationCopyStorageUsingBuffer() function.
*/
static BlockNumber
copy_storage_using_buffer_read_stream_next_block(ReadStream *stream,
void *callback_private_data,
void *per_buffer_data)
{
struct copy_storage_using_buffer_read_stream_private *p = callback_private_data;
if (p->blocknum < p->nblocks)
return p->blocknum++;
return InvalidBlockNumber;
}
/* GUC variables */
bool zero_damaged_pages = false;
int bgwriter_lru_maxpages = 100;
@ -4710,7 +4683,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
PGIOAlignedBlock buf;
BufferAccessStrategy bstrategy_src;
BufferAccessStrategy bstrategy_dst;
struct copy_storage_using_buffer_read_stream_private p;
BlockRangeReadStreamPrivate p;
ReadStream *src_stream;
SMgrRelation src_smgr;
@ -4742,15 +4715,15 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
bstrategy_dst = GetAccessStrategy(BAS_BULKWRITE);
/* Initialize streaming read */
p.blocknum = 0;
p.nblocks = nblocks;
p.current_blocknum = 0;
p.last_exclusive = nblocks;
src_smgr = smgropen(srclocator, INVALID_PROC_NUMBER);
src_stream = read_stream_begin_smgr_relation(READ_STREAM_FULL,
bstrategy_src,
src_smgr,
permanent ? RELPERSISTENCE_PERMANENT : RELPERSISTENCE_UNLOGGED,
forkNum,
copy_storage_using_buffer_read_stream_next_block,
block_range_read_stream_cb,
&p,
0);