Move block_range_read_stream_cb batchmode comment
Hi,
Currently, each usage of block_range_read_stream_cb is accompanied by
the same comment about the safety of using batchmode (there are 7
identical comments)
/*
* It is safe to use batchmode as block_range_read_stream_cb takes no
* locks.
*/
The idea is to write it once near block_range_read_stream_cb and drop
all duplicates. PFA the small patch that does this.
Best regards,
Arseniy Mukhin
Attachments:
v1-0001-Moves-the-comment-about-block_range_read_stream_c.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Moves-the-comment-about-block_range_read_stream_c.patchDownload
From bf29b68997fd414d97cd784fea462366c07e40c9 Mon Sep 17 00:00:00 2001
From: Arseniy Mukhin <arseniy.mukhin.dev@gmail.com>
Date: Sat, 30 Aug 2025 20:16:47 +0300
Subject: [PATCH v1] Moves the comment about block_range_read_stream_cb
Currently, each usage of block_range_read_stream_cb is accompanied by
the same comment about the safety of using batchmode. Commit moves the
comment closer to block_range_read_stream_cb, so no duplicate comments
are needed.
---
contrib/amcheck/verify_heapam.c | 4 ----
contrib/pg_prewarm/pg_prewarm.c | 4 ----
contrib/pg_visibility/pg_visibility.c | 4 ----
src/backend/access/gist/gistvacuum.c | 4 ----
src/backend/access/nbtree/nbtree.c | 4 ----
src/backend/access/spgist/spgvacuum.c | 4 ----
src/backend/storage/aio/read_stream.c | 3 ++-
src/backend/storage/buffer/bufmgr.c | 4 ----
8 files changed, 2 insertions(+), 29 deletions(-)
diff --git a/contrib/amcheck/verify_heapam.c b/contrib/amcheck/verify_heapam.c
index 4963e9245cb..bdda345a195 100644
--- a/contrib/amcheck/verify_heapam.c
+++ b/contrib/amcheck/verify_heapam.c
@@ -447,10 +447,6 @@ verify_heapam(PG_FUNCTION_ARGS)
if (skip_option == SKIP_PAGES_NONE)
{
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
stream_cb = block_range_read_stream_cb;
stream_flags = READ_STREAM_SEQUENTIAL |
READ_STREAM_FULL |
diff --git a/contrib/pg_prewarm/pg_prewarm.c b/contrib/pg_prewarm/pg_prewarm.c
index b968933ea8b..e2ee8711486 100644
--- a/contrib/pg_prewarm/pg_prewarm.c
+++ b/contrib/pg_prewarm/pg_prewarm.c
@@ -206,10 +206,6 @@ pg_prewarm(PG_FUNCTION_ARGS)
p.current_blocknum = first_block;
p.last_exclusive = last_block + 1;
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
stream = read_stream_begin_relation(READ_STREAM_MAINTENANCE |
READ_STREAM_FULL |
READ_STREAM_USE_BATCHING,
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index d79ef35006b..6d4ad5d243e 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -527,10 +527,6 @@ collect_visibility_data(Oid relid, bool include_pd)
p.current_blocknum = 0;
p.last_exclusive = nblocks;
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
stream = read_stream_begin_relation(READ_STREAM_FULL |
READ_STREAM_USE_BATCHING,
bstrategy,
diff --git a/src/backend/access/gist/gistvacuum.c b/src/backend/access/gist/gistvacuum.c
index dca236b6e57..ea2b47ce4da 100644
--- a/src/backend/access/gist/gistvacuum.c
+++ b/src/backend/access/gist/gistvacuum.c
@@ -211,10 +211,6 @@ gistvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
p.current_blocknum = GIST_ROOT_BLKNO;
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
stream = read_stream_begin_relation(READ_STREAM_MAINTENANCE |
READ_STREAM_FULL |
READ_STREAM_USE_BATCHING,
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index fdff960c130..ba56b8bf3ea 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -1260,10 +1260,6 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
p.current_blocknum = BTREE_METAPAGE + 1;
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
stream = read_stream_begin_relation(READ_STREAM_MAINTENANCE |
READ_STREAM_FULL |
READ_STREAM_USE_BATCHING,
diff --git a/src/backend/access/spgist/spgvacuum.c b/src/backend/access/spgist/spgvacuum.c
index 2678f7ab782..9169d860bed 100644
--- a/src/backend/access/spgist/spgvacuum.c
+++ b/src/backend/access/spgist/spgvacuum.c
@@ -823,10 +823,6 @@ spgvacuumscan(spgBulkDeleteState *bds)
needLock = !RELATION_IS_LOCAL(index);
p.current_blocknum = SPGIST_METAPAGE_BLKNO + 1;
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
stream = read_stream_begin_relation(READ_STREAM_MAINTENANCE |
READ_STREAM_FULL |
READ_STREAM_USE_BATCHING,
diff --git a/src/backend/storage/aio/read_stream.c b/src/backend/storage/aio/read_stream.c
index 031fde9f4cb..aac0d43d3b0 100644
--- a/src/backend/storage/aio/read_stream.c
+++ b/src/backend/storage/aio/read_stream.c
@@ -156,7 +156,8 @@ get_per_buffer_data(ReadStream *stream, int16 buffer_index)
/*
* General-use ReadStreamBlockNumberCB for block range scans. Loops over the
- * blocks [current_blocknum, last_exclusive).
+ * blocks [current_blocknum, last_exclusive). It is safe to use batchmode with
+ * block_range_read_stream_cb as it takes no locks.
*/
BlockNumber
block_range_read_stream_cb(ReadStream *stream,
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index fd7e21d96d3..808fe89d0f1 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -5168,10 +5168,6 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
p.last_exclusive = nblocks;
src_smgr = smgropen(srclocator, INVALID_PROC_NUMBER);
- /*
- * It is safe to use batchmode as block_range_read_stream_cb takes no
- * locks.
- */
src_stream = read_stream_begin_smgr_relation(READ_STREAM_FULL |
READ_STREAM_USE_BATCHING,
bstrategy_src,
--
2.43.0
Hi,
On 2025-08-30 20:33:09 +0300, Arseniy Mukhin wrote:
Currently, each usage of block_range_read_stream_cb is accompanied by
the same comment about the safety of using batchmode (there are 7
identical comments)
-1 - I think it's better to have the analysis at the point of using the flag
and callback, as otherwise it's too easy to change the callsites to a
different callback, without removing the flag.
Greetings,
Andres Freund
On Sat, Aug 30, 2025 at 9:14 PM Andres Freund <andres@anarazel.de> wrote:
Hi,
On 2025-08-30 20:33:09 +0300, Arseniy Mukhin wrote:
Currently, each usage of block_range_read_stream_cb is accompanied by
the same comment about the safety of using batchmode (there are 7
identical comments)-1 - I think it's better to have the analysis at the point of using the flag
and callback, as otherwise it's too easy to change the callsites to a
different callback, without removing the flag.
Got the idea, thank you for the explanation.
Best regards,
Arseniy Mukhin