Skip to content

Commit f154f02

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 9577dd5 commit f154f02

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

contrib/pg_visibility/pg_visibility.c

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

@@ -1069,7 +1069,7 @@ smgr_redo(XLogReaderState *record)
10691069
if (nforks > 0)
10701070
{
10711071
START_CRIT_SECTION();
1072-
smgrtruncate(reln, forks, nforks, old_blocks, blocks);
1072+
smgrtruncate2(reln, forks, nforks, old_blocks, blocks);
10731073
END_CRIT_SECTION();
10741074
}
10751075

src/backend/storage/smgr/smgr.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,26 @@ smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
586586
* smgrtruncate() -- Truncate the given forks of supplied relation to
587587
* each specified numbers of blocks
588588
*
589+
* Backward-compatible version of smgrtruncate2() for the benefit of external
590+
* callers. This version isn't used in PostgreSQL core code, and can't be
591+
* used in a critical section.
592+
*/
593+
void
594+
smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
595+
BlockNumber *nblocks)
596+
{
597+
BlockNumber old_nblocks[MAX_FORKNUM + 1];
598+
599+
for (int i = 0; i < nforks; ++i)
600+
old_nblocks[i] = smgrnblocks(reln, forknum[i]);
601+
602+
return smgrtruncate2(reln, forknum, nforks, old_nblocks, nblocks);
603+
}
604+
605+
/*
606+
* smgrtruncate2() -- Truncate the given forks of supplied relation to
607+
* each specified numbers of blocks
608+
*
589609
* The truncation is done immediately, so this can't be rolled back.
590610
*
591611
* The caller must hold AccessExclusiveLock on the relation, to ensure that
@@ -597,8 +617,8 @@ smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
597617
* to this relation should be called in between.
598618
*/
599619
void
600-
smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
601-
BlockNumber *old_nblocks, BlockNumber *nblocks)
620+
smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
621+
BlockNumber *old_nblocks, BlockNumber *nblocks)
602622
{
603623
int i;
604624

src/include/storage/smgr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
101101
extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
102102
extern BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum);
103103
extern void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
104-
BlockNumber *old_nblocks,
105104
BlockNumber *nblocks);
105+
extern void smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
106+
BlockNumber *old_nblocks,
107+
BlockNumber *nblocks);
106108
extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
107109
extern void AtEOXact_SMgr(void);
108110

0 commit comments

Comments
 (0)