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

Commitd7b8712

Browse files
nmischpull[bot]
authored andcommitted
Add block_range_read_stream_cb(), to deduplicate code.
This replaces two functions for iterating over all blocks in a range. Apending patch will use this instead of adding a third.Nazir Bilal YavuzDiscussion:https://postgr.es/m/20240820184742.f2.nmisch@google.com
1 parent79eada4 commitd7b8712

File tree

5 files changed

+36
-54
lines changed

5 files changed

+36
-54
lines changed

‎contrib/pg_prewarm/pg_prewarm.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,6 @@ typedef enum
3939

4040
staticPGIOAlignedBlockblockbuffer;
4141

42-
structpg_prewarm_read_stream_private
43-
{
44-
BlockNumberblocknum;
45-
int64last_block;
46-
};
47-
48-
staticBlockNumber
49-
pg_prewarm_read_stream_next_block(ReadStream*stream,
50-
void*callback_private_data,
51-
void*per_buffer_data)
52-
{
53-
structpg_prewarm_read_stream_private*p=callback_private_data;
54-
55-
if (p->blocknum <=p->last_block)
56-
returnp->blocknum++;
57-
58-
returnInvalidBlockNumber;
59-
}
60-
6142
/*
6243
* pg_prewarm(regclass, mode text, fork text,
6344
* first_block int8, last_block int8)
@@ -203,22 +184,22 @@ pg_prewarm(PG_FUNCTION_ARGS)
203184
}
204185
elseif (ptype==PREWARM_BUFFER)
205186
{
206-
structpg_prewarm_read_stream_privatep;
187+
BlockRangeReadStreamPrivatep;
207188
ReadStream*stream;
208189

209190
/*
210191
* In buffer mode, we actually pull the data into shared_buffers.
211192
*/
212193

213194
/* Set up the private state for our streaming buffer read callback. */
214-
p.blocknum=first_block;
215-
p.last_block=last_block;
195+
p.current_blocknum=first_block;
196+
p.last_exclusive=last_block+1;
216197

217198
stream=read_stream_begin_relation(READ_STREAM_FULL,
218199
NULL,
219200
rel,
220201
forkNumber,
221-
pg_prewarm_read_stream_next_block,
202+
block_range_read_stream_cb,
222203
&p,
223204
0);
224205

‎src/backend/storage/aio/read_stream.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ get_per_buffer_data(ReadStream *stream, int16 buffer_index)
163163
stream->per_buffer_data_size*buffer_index;
164164
}
165165

166+
/*
167+
* General-use ReadStreamBlockNumberCB for block range scans. Loops over the
168+
* blocks [current_blocknum, last_exclusive).
169+
*/
170+
BlockNumber
171+
block_range_read_stream_cb(ReadStream*stream,
172+
void*callback_private_data,
173+
void*per_buffer_data)
174+
{
175+
BlockRangeReadStreamPrivate*p=callback_private_data;
176+
177+
if (p->current_blocknum<p->last_exclusive)
178+
returnp->current_blocknum++;
179+
180+
returnInvalidBlockNumber;
181+
}
182+
166183
/*
167184
* Ask the callback which block it would like us to read next, with a one block
168185
* buffer in front to allow read_stream_unget_block() to work.

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,6 @@ typedef struct SMgrSortArray
136136
SMgrRelationsrel;
137137
}SMgrSortArray;
138138

139-
/*
140-
* Helper struct for read stream object used in
141-
* RelationCopyStorageUsingBuffer() function.
142-
*/
143-
structcopy_storage_using_buffer_read_stream_private
144-
{
145-
BlockNumberblocknum;
146-
BlockNumbernblocks;
147-
};
148-
149-
/*
150-
* Callback function to get next block for read stream object used in
151-
* RelationCopyStorageUsingBuffer() function.
152-
*/
153-
staticBlockNumber
154-
copy_storage_using_buffer_read_stream_next_block(ReadStream*stream,
155-
void*callback_private_data,
156-
void*per_buffer_data)
157-
{
158-
structcopy_storage_using_buffer_read_stream_private*p=callback_private_data;
159-
160-
if (p->blocknum<p->nblocks)
161-
returnp->blocknum++;
162-
163-
returnInvalidBlockNumber;
164-
}
165-
166139
/* GUC variables */
167140
boolzero_damaged_pages= false;
168141
intbgwriter_lru_maxpages=100;
@@ -4710,7 +4683,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
47104683
PGIOAlignedBlockbuf;
47114684
BufferAccessStrategybstrategy_src;
47124685
BufferAccessStrategybstrategy_dst;
4713-
structcopy_storage_using_buffer_read_stream_privatep;
4686+
BlockRangeReadStreamPrivatep;
47144687
ReadStream*src_stream;
47154688
SMgrRelationsrc_smgr;
47164689

@@ -4742,15 +4715,15 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
47424715
bstrategy_dst=GetAccessStrategy(BAS_BULKWRITE);
47434716

47444717
/* Initialize streaming read */
4745-
p.blocknum=0;
4746-
p.nblocks=nblocks;
4718+
p.current_blocknum=0;
4719+
p.last_exclusive=nblocks;
47474720
src_smgr=smgropen(srclocator,INVALID_PROC_NUMBER);
47484721
src_stream=read_stream_begin_smgr_relation(READ_STREAM_FULL,
47494722
bstrategy_src,
47504723
src_smgr,
47514724
permanent ?RELPERSISTENCE_PERMANENT :RELPERSISTENCE_UNLOGGED,
47524725
forkNum,
4753-
copy_storage_using_buffer_read_stream_next_block,
4726+
block_range_read_stream_cb,
47544727
&p,
47554728
0);
47564729

‎src/include/storage/read_stream.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,21 @@
4545
structReadStream;
4646
typedefstructReadStreamReadStream;
4747

48+
/* for block_range_read_stream_cb */
49+
typedefstructBlockRangeReadStreamPrivate
50+
{
51+
BlockNumbercurrent_blocknum;
52+
BlockNumberlast_exclusive;
53+
}BlockRangeReadStreamPrivate;
54+
4855
/* Callback that returns the next block number to read. */
4956
typedefBlockNumber (*ReadStreamBlockNumberCB) (ReadStream*stream,
5057
void*callback_private_data,
5158
void*per_buffer_data);
5259

60+
externBlockNumberblock_range_read_stream_cb(ReadStream*stream,
61+
void*callback_private_data,
62+
void*per_buffer_data);
5363
externReadStream*read_stream_begin_relation(intflags,
5464
BufferAccessStrategystrategy,
5565
Relationrel,

‎src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ BlockId
275275
BlockIdData
276276
BlockInfoRecord
277277
BlockNumber
278+
BlockRangeReadStreamPrivate
278279
BlockRefTable
279280
BlockRefTableBuffer
280281
BlockRefTableChunk

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp