summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/pg_visibility/pg_visibility.c2
-rw-r--r--src/backend/catalog/storage.c4
-rw-r--r--src/backend/storage/smgr/smgr.c24
-rw-r--r--src/include/storage/smgr.h4
4 files changed, 28 insertions, 6 deletions
diff --git a/contrib/pg_visibility/pg_visibility.c b/contrib/pg_visibility/pg_visibility.c
index 5acf2cfbad2..ee2078b906f 100644
--- a/contrib/pg_visibility/pg_visibility.c
+++ b/contrib/pg_visibility/pg_visibility.c
@@ -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;
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index 7550fc1accf..8ef485d84ae 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -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();
}
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c
index fc0516c1eb0..d33db9c4b38 100644
--- a/src/backend/storage/smgr/smgr.c
+++ b/src/backend/storage/smgr/smgr.c
@@ -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;
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index 147ec330f80..92020305e54 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -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);