Restore smgrtruncate() prototype in back-branches.
authorThomas Munro <[email protected]>
Tue, 7 Jan 2025 18:50:30 +0000 (07:50 +1300)
committerThomas Munro <[email protected]>
Tue, 7 Jan 2025 21:48:57 +0000 (10:48 +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 <[email protected]>
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 5acf2cfbad2d282b001041cbc8b58c1a704870fe..ee2078b906f93ddb40ab067697f2be5edf0b9e0f 100644 (file)
@@ -429,7 +429,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->delayChkpt = false;
index 7550fc1accfbbd62dde781818e0cd89a95029dcc..8ef485d84ae917f7beb253a5fef8b3c81066ca02 100644 (file)
@@ -409,7 +409,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();
 
@@ -1070,7 +1070,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 fc0516c1eb013bd736affa439e6319bb2084bb1f..d33db9c4b383483a3b2a87e154752ad6657b7e6d 100644 (file)
@@ -544,6 +544,26 @@ smgrnblocks(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
@@ -555,8 +575,8 @@ smgrnblocks(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 147ec330f80baef79c0eb48c9e5fca5e044262f3..92020305e54307582a1a0ea8382eb30fc11acfdd 100644 (file)
@@ -102,8 +102,10 @@ extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
                          BlockNumber blocknum, BlockNumber nblocks);
 extern BlockNumber smgrnblocks(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);