Skip to content

Commit a1d17a8

Browse files
committed
Restore smgrtruncate() prototype in back-branches.
It's possible that external code is calling smgrtruncate(). Any external callers might like to consider the recent changes to RelationTruncate(), but commit 38c579b 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
1 parent 20a344b commit a1d17a8

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

contrib/pg_visibility/pg_visibility.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pg_truncate_visibility_map(PG_FUNCTION_ARGS)
429429
}
430430

431431
if (BlockNumberIsValid(block))
432-
smgrtruncate(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
432+
smgrtruncate2(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
433433

434434
END_CRIT_SECTION();
435435
MyProc->delayChkpt = false;

src/backend/catalog/storage.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
409409
* longer exist after truncation is complete, and then truncate the
410410
* corresponding files on disk.
411411
*/
412-
smgrtruncate(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
412+
smgrtruncate2(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
413413

414414
END_CRIT_SECTION();
415415

@@ -1070,7 +1070,7 @@ smgr_redo(XLogReaderState *record)
10701070
if (nforks > 0)
10711071
{
10721072
START_CRIT_SECTION();
1073-
smgrtruncate(reln, forks, nforks, old_blocks, blocks);
1073+
smgrtruncate2(reln, forks, nforks, old_blocks, blocks);
10741074
END_CRIT_SECTION();
10751075
}
10761076

src/backend/storage/smgr/smgr.c

+22-2
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,26 @@ smgrnblocks(SMgrRelation reln, ForkNumber forknum)
544544
* smgrtruncate() -- Truncate the given forks of supplied relation to
545545
* each specified numbers of blocks
546546
*
547+
* Backward-compatible version of smgrtruncate2() for the benefit of external
548+
* callers. This version isn't used in PostgreSQL core code, and can't be
549+
* used in a critical section.
550+
*/
551+
void
552+
smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
553+
BlockNumber *nblocks)
554+
{
555+
BlockNumber old_nblocks[MAX_FORKNUM + 1];
556+
557+
for (int i = 0; i < nforks; ++i)
558+
old_nblocks[i] = smgrnblocks(reln, forknum[i]);
559+
560+
return smgrtruncate2(reln, forknum, nforks, old_nblocks, nblocks);
561+
}
562+
563+
/*
564+
* smgrtruncate2() -- Truncate the given forks of supplied relation to
565+
* each specified numbers of blocks
566+
*
547567
* The truncation is done immediately, so this can't be rolled back.
548568
*
549569
* The caller must hold AccessExclusiveLock on the relation, to ensure that
@@ -555,8 +575,8 @@ smgrnblocks(SMgrRelation reln, ForkNumber forknum)
555575
* to this relation should be called in between.
556576
*/
557577
void
558-
smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
559-
BlockNumber *old_nblocks, BlockNumber *nblocks)
578+
smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
579+
BlockNumber *old_nblocks, BlockNumber *nblocks)
560580
{
561581
int i;
562582

src/include/storage/smgr.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
102102
BlockNumber blocknum, BlockNumber nblocks);
103103
extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
104104
extern void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
105-
BlockNumber *old_nblocks,
106105
BlockNumber *nblocks);
106+
extern void smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
107+
BlockNumber *old_nblocks,
108+
BlockNumber *nblocks);
107109
extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
108110
extern void AtEOXact_SMgr(void);
109111

0 commit comments

Comments
 (0)