]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Restore smgrtruncate() prototype in back-branches.
authorThomas Munro <tmunro@postgresql.org>
Tue, 7 Jan 2025 18:50:30 +0000 (07:50 +1300)
committerThomas Munro <tmunro@postgresql.org>
Tue, 7 Jan 2025 21:47:43 +0000 (10:47 +1300)
It's possible that external code is calling smgrtruncate().  Any
external callers might like to consider the recent changes to
RelationTruncate(), but commit 38c579b0 should not have changed the
function prototype in the back-branches, per ABI stability policy.

Restore smgrtruncate()'s traditional argument list in the back-branches,
but make it a wrapper for a new function smgrtruncate2().  The three
callers in core can use smgrtruncate2() directly.  In master (18-to-be),
smgrtruncate2() is effectively renamed to smgrtruncate(), so this wart
is cleaned up.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CA%2BhUKG%2BThae6x6%2BjmQiuALQBT2Ae1ChjMh1%3DkMvJ8y_SBJZrvA%40mail.gmail.com

contrib/pg_visibility/pg_visibility.c
src/backend/catalog/storage.c
src/backend/storage/smgr/smgr.c
src/include/storage/smgr.h

index 62e3258111d578c4e5148d2080db33dbf047536a..1d699117c10b381ccbf877adeda2c3d04fea78bc 100644 (file)
@@ -428,7 +428,7 @@ pg_truncate_visibility_map(PG_FUNCTION_ARGS)
        }
 
        if (BlockNumberIsValid(block))
-               smgrtruncate(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
+               smgrtruncate2(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
 
        END_CRIT_SECTION();
        MyProc->delayChkptFlags &= ~(DELAY_CHKPT_START | DELAY_CHKPT_COMPLETE);
index fb234bc07e3d9fd7f5c3877f530ce8ad32dabcfc..5b0a40041c1c0cb6fd986d0330c85959c00faf02 100644 (file)
@@ -417,7 +417,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
         * longer exist after truncation is complete, and then truncate the
         * corresponding files on disk.
         */
-       smgrtruncate(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
+       smgrtruncate2(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
 
        END_CRIT_SECTION();
 
@@ -1076,7 +1076,7 @@ smgr_redo(XLogReaderState *record)
                if (nforks > 0)
                {
                        START_CRIT_SECTION();
-                       smgrtruncate(reln, forks, nforks, old_blocks, blocks);
+                       smgrtruncate2(reln, forks, nforks, old_blocks, blocks);
                        END_CRIT_SECTION();
                }
 
index e6a9a2dd7b0457b1d25c2abf572be182d3e7c577..657eabde93427bfae9f55b123a18d86f582cb713 100644 (file)
@@ -618,6 +618,26 @@ smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
  *     smgrtruncate() -- Truncate the given forks of supplied relation to
  *                                       each specified numbers of blocks
  *
+ * Backward-compatible version of smgrtruncate2() for the benefit of external
+ * callers.  This version isn't used in PostgreSQL core code, and can't be
+ * used in a critical section.
+ */
+void
+smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
+                        BlockNumber *nblocks)
+{
+       BlockNumber old_nblocks[MAX_FORKNUM + 1];
+
+       for (int i = 0; i < nforks; ++i)
+               old_nblocks[i] = smgrnblocks(reln, forknum[i]);
+
+       return smgrtruncate2(reln, forknum, nforks, old_nblocks, nblocks);
+}
+
+/*
+ * smgrtruncate2() -- Truncate the given forks of supplied relation to
+ *                                       each specified numbers of blocks
+ *
  * The truncation is done immediately, so this can't be rolled back.
  *
  * The caller must hold AccessExclusiveLock on the relation, to ensure that
@@ -629,8 +649,8 @@ smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
  * to this relation should be called in between.
  */
 void
-smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
-                        BlockNumber *old_nblocks, BlockNumber *nblocks)
+smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
+                         BlockNumber *old_nblocks, BlockNumber *nblocks)
 {
        int                     i;
 
index 0f1417043b36f56fcf2799701538e1e6fdd7675c..53a71c276e8a6beae0343239edbc6aa085840317 100644 (file)
@@ -103,8 +103,10 @@ extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
 extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
 extern BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum);
 extern void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
-                                                BlockNumber *old_nblocks,
                                                 BlockNumber *nblocks);
+extern void smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
+                                                 BlockNumber *old_nblocks,
+                                                 BlockNumber *nblocks);
 extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
 extern void AtEOXact_SMgr(void);
 extern bool ProcessBarrierSmgrRelease(void);