Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 66aaabe

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 e43537c commit 66aaabe

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
@@ -421,7 +421,7 @@ pg_truncate_visibility_map(PG_FUNCTION_ARGS)
421421
}
422422

423423
if (BlockNumberIsValid(block))
424-
smgrtruncate(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
424+
smgrtruncate2(RelationGetSmgr(rel), &fork, 1, &old_block, &block);
425425

426426
END_CRIT_SECTION();
427427
MyProc->delayChkptFlags &= ~(DELAY_CHKPT_START | DELAY_CHKPT_COMPLETE);

src/backend/catalog/storage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
418418
* longer exist after truncation is complete, and then truncate the
419419
* corresponding files on disk.
420420
*/
421-
smgrtruncate(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
421+
smgrtruncate2(RelationGetSmgr(rel), forks, nforks, old_blocks, blocks);
422422

423423
END_CRIT_SECTION();
424424

@@ -1059,7 +1059,7 @@ smgr_redo(XLogReaderState *record)
10591059
if (nforks > 0)
10601060
{
10611061
START_CRIT_SECTION();
1062-
smgrtruncate(reln, forks, nforks, old_blocks, blocks);
1062+
smgrtruncate2(reln, forks, nforks, old_blocks, blocks);
10631063
END_CRIT_SECTION();
10641064
}
10651065

src/backend/storage/smgr/smgr.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,26 @@ smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
693693
* smgrtruncate() -- Truncate the given forks of supplied relation to
694694
* each specified numbers of blocks
695695
*
696+
* Backward-compatible version of smgrtruncate2() for the benefit of external
697+
* callers. This version isn't used in PostgreSQL core code, and can't be
698+
* used in a critical section.
699+
*/
700+
void
701+
smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
702+
BlockNumber *nblocks)
703+
{
704+
BlockNumber old_nblocks[MAX_FORKNUM + 1];
705+
706+
for (int i = 0; i < nforks; ++i)
707+
old_nblocks[i] = smgrnblocks(reln, forknum[i]);
708+
709+
return smgrtruncate2(reln, forknum, nforks, old_nblocks, nblocks);
710+
}
711+
712+
/*
713+
* smgrtruncate2() -- Truncate the given forks of supplied relation to
714+
* each specified numbers of blocks
715+
*
696716
* The truncation is done immediately, so this can't be rolled back.
697717
*
698718
* The caller must hold AccessExclusiveLock on the relation, to ensure that
@@ -704,8 +724,8 @@ smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
704724
* to this relation should be called in between.
705725
*/
706726
void
707-
smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
708-
BlockNumber *old_nblocks, BlockNumber *nblocks)
727+
smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
728+
BlockNumber *old_nblocks, BlockNumber *nblocks)
709729
{
710730
int i;
711731

src/include/storage/smgr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
104104
extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
105105
extern BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum);
106106
extern void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
107-
BlockNumber *old_nblocks,
108107
BlockNumber *nblocks);
108+
extern void smgrtruncate2(SMgrRelation reln, ForkNumber *forknum, int nforks,
109+
BlockNumber *old_nblocks,
110+
BlockNumber *nblocks);
109111
extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
110112
extern void smgrregistersync(SMgrRelation reln, ForkNumber forknum);
111113
extern void AtEOXact_SMgr(void);

0 commit comments

Comments
 (0)