v4-0005-Refactor-smgr-API-mdcreate-needs-the-old-relfilel.patch
text/x-patch
Filename: v4-0005-Refactor-smgr-API-mdcreate-needs-the-old-relfilel.patch
Type: text/x-patch
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v4-0005
Subject: Refactor smgr API: mdcreate needs the old relfilelocator
| File | + | − |
|---|---|---|
| src/backend/access/heap/heapam_handler.c | 6 | 4 |
| src/backend/access/transam/xlogutils.c | 1 | 1 |
| src/backend/catalog/heap.c | 1 | 1 |
| src/backend/catalog/index.c | 1 | 1 |
| src/backend/catalog/storage.c | 4 | 4 |
| src/backend/commands/sequence.c | 1 | 1 |
| src/backend/commands/tablecmds.c | 2 | 2 |
| src/backend/storage/buffer/bufmgr.c | 4 | 3 |
| src/backend/storage/smgr/md.c | 1 | 1 |
| src/backend/storage/smgr/smgr.c | 2 | 2 |
| src/backend/utils/cache/relcache.c | 1 | 1 |
| src/include/catalog/storage.h | 2 | 1 |
| src/include/storage/md.h | 1 | 1 |
| src/include/storage/smgr.h | 2 | 2 |
From 96523c547e90de64b116acf470c07307541795b1 Mon Sep 17 00:00:00 2001
From: Zsolt Parragi <zsolt.parragi@cancellar.hu>
Date: Sat, 12 Oct 2024 22:01:28 +0100
Subject: [PATCH v4 5/6] Refactor smgr API: mdcreate needs the old
relfilelocator
With this change, mdcreate receives the old relfilelocator along
with the new for operations that create a new file for an existing
relation.
This is required for tde_heap in pg_tde.
---
src/backend/access/heap/heapam_handler.c | 10 ++++++----
src/backend/access/transam/xlogutils.c | 2 +-
src/backend/catalog/heap.c | 2 +-
src/backend/catalog/index.c | 2 +-
src/backend/catalog/storage.c | 8 ++++----
src/backend/commands/sequence.c | 2 +-
src/backend/commands/tablecmds.c | 4 ++--
src/backend/storage/buffer/bufmgr.c | 7 ++++---
src/backend/storage/smgr/md.c | 2 +-
src/backend/storage/smgr/smgr.c | 4 ++--
src/backend/utils/cache/relcache.c | 2 +-
src/include/catalog/storage.h | 3 ++-
src/include/storage/md.h | 2 +-
src/include/storage/smgr.h | 4 ++--
14 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index e78682c3cef..96463d1bb14 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -584,6 +584,8 @@ heapam_relation_set_new_filelocator(Relation rel,
{
SMgrRelation srel;
+ RelFileLocator oldlocator = rel->rd_locator;
+
/*
* Initialize to the minimum XID that could put tuples in the table. We
* know that no xacts older than RecentXmin are still running, so that
@@ -601,7 +603,7 @@ heapam_relation_set_new_filelocator(Relation rel,
*/
*minmulti = GetOldestMultiXactId();
- srel = RelationCreateStorage(*newrlocator, persistence, true);
+ srel = RelationCreateStorage(oldlocator, *newrlocator, persistence, true);
/*
* If required, set up an init fork for an unlogged table so that it can
@@ -611,7 +613,7 @@ heapam_relation_set_new_filelocator(Relation rel,
{
Assert(rel->rd_rel->relkind == RELKIND_RELATION ||
rel->rd_rel->relkind == RELKIND_TOASTVALUE);
- smgrcreate(srel, INIT_FORKNUM, false);
+ smgrcreate(oldlocator, srel, INIT_FORKNUM, false);
log_smgrcreate(newrlocator, INIT_FORKNUM);
}
@@ -644,7 +646,7 @@ heapam_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
* NOTE: any conflict in relfilenumber value will be caught in
* RelationCreateStorage().
*/
- dstrel = RelationCreateStorage(*newrlocator, rel->rd_rel->relpersistence, true);
+ dstrel = RelationCreateStorage(rel->rd_locator, *newrlocator, rel->rd_rel->relpersistence, true);
/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
@@ -656,7 +658,7 @@ heapam_relation_copy_data(Relation rel, const RelFileLocator *newrlocator)
{
if (smgrexists(RelationGetSmgr(rel), forkNum))
{
- smgrcreate(dstrel, forkNum, false);
+ smgrcreate(rel->rd_locator, dstrel, forkNum, false);
/*
* WAL log creation if the relation is persistent, or this is the
diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c
index c389b27f77d..2179d2f73fa 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -487,7 +487,7 @@ XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum,
* filesystem loses an inode during a crash. Better to write the data
* until we are actually told to delete the file.)
*/
- smgrcreate(smgr, forknum, true);
+ smgrcreate(rlocator, smgr, forknum, true);
lastblock = smgrnblocks(smgr, forknum);
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index bd3554c0bfd..251d22f50b2 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -386,7 +386,7 @@ heap_create(const char *relname,
relpersistence,
relfrozenxid, relminmxid);
else if (RELKIND_HAS_STORAGE(rel->rd_rel->relkind))
- RelationCreateStorage(rel->rd_locator, relpersistence, true);
+ RelationCreateStorage(rel->rd_locator, rel->rd_locator, relpersistence, true);
else
Assert(false);
}
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 022b9b99b13..cc99d45f2ff 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -3089,7 +3089,7 @@ index_build(Relation heapRelation,
if (indexRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
!smgrexists(RelationGetSmgr(indexRelation), INIT_FORKNUM))
{
- smgrcreate(RelationGetSmgr(indexRelation), INIT_FORKNUM, false);
+ smgrcreate(indexRelation->rd_locator, RelationGetSmgr(indexRelation), INIT_FORKNUM, false);
log_smgrcreate(&indexRelation->rd_locator, INIT_FORKNUM);
indexRelation->rd_indam->ambuildempty(indexRelation);
}
diff --git a/src/backend/catalog/storage.c b/src/backend/catalog/storage.c
index 624ed41bbf3..59fa01decc5 100644
--- a/src/backend/catalog/storage.c
+++ b/src/backend/catalog/storage.c
@@ -118,7 +118,7 @@ AddPendingSync(const RelFileLocator *rlocator)
* pass register_delete = false.
*/
SMgrRelation
-RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
+RelationCreateStorage(RelFileLocator oldlocator, RelFileLocator rlocator, char relpersistence,
bool register_delete)
{
SMgrRelation srel;
@@ -147,7 +147,7 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
}
srel = smgropen(rlocator, procNumber);
- smgrcreate(srel, MAIN_FORKNUM, false);
+ smgrcreate(oldlocator, srel, MAIN_FORKNUM, false);
if (needs_wal)
log_smgrcreate(&srel->smgr_rlocator.locator, MAIN_FORKNUM);
@@ -976,7 +976,7 @@ smgr_redo(XLogReaderState *record)
SMgrRelation reln;
reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
- smgrcreate(reln, xlrec->forkNum, true);
+ smgrcreate(xlrec->rlocator, reln, xlrec->forkNum, true);
}
else if (info == XLOG_SMGR_TRUNCATE)
{
@@ -997,7 +997,7 @@ smgr_redo(XLogReaderState *record)
* XLogReadBufferForRedo, we prefer to recreate the rel and replay the
* log as best we can until the drop is seen.
*/
- smgrcreate(reln, MAIN_FORKNUM, true);
+ smgrcreate(xlrec->rlocator, reln, MAIN_FORKNUM, true);
/*
* Before we perform the truncation, update minimum recovery point to
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 4b7c5113aab..d8c560a11b2 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -344,7 +344,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
SMgrRelation srel;
srel = smgropen(rel->rd_locator, INVALID_PROC_NUMBER);
- smgrcreate(srel, INIT_FORKNUM, false);
+ smgrcreate(rel->rd_locator, srel, INIT_FORKNUM, false);
log_smgrcreate(&rel->rd_locator, INIT_FORKNUM);
fill_seq_fork_with_data(rel, tuple, INIT_FORKNUM);
FlushRelationBuffers(rel);
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 59156a1c1f6..7d0d9d3efa9 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16313,7 +16313,7 @@ index_copy_data(Relation rel, RelFileLocator newrlocator)
* NOTE: any conflict in relfilenumber value will be caught in
* RelationCreateStorage().
*/
- dstrel = RelationCreateStorage(newrlocator, rel->rd_rel->relpersistence, true);
+ dstrel = RelationCreateStorage(rel->rd_locator, newrlocator, rel->rd_rel->relpersistence, true);
/* copy main fork */
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
@@ -16325,7 +16325,7 @@ index_copy_data(Relation rel, RelFileLocator newrlocator)
{
if (smgrexists(RelationGetSmgr(rel), forkNum))
{
- smgrcreate(dstrel, forkNum, false);
+ smgrcreate(rel->rd_locator, dstrel, forkNum, false);
/*
* WAL log creation if the relation is persistent, or this is the
diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c
index 7915ed624c1..ecacb5fb50a 100644
--- a/src/backend/storage/buffer/bufmgr.c
+++ b/src/backend/storage/buffer/bufmgr.c
@@ -943,7 +943,7 @@ ExtendBufferedRelTo(BufferManagerRelation bmr,
/* recheck, fork might have been created concurrently */
if (!smgrexists(bmr.smgr, fork))
- smgrcreate(bmr.smgr, fork, flags & EB_PERFORMING_RECOVERY);
+ smgrcreate(bmr.rel->rd_locator, bmr.smgr, fork, flags & EB_PERFORMING_RECOVERY);
UnlockRelationForExtension(bmr.rel, ExclusiveLock);
}
@@ -4754,7 +4754,7 @@ CreateAndCopyRelationData(RelFileLocator src_rlocator,
* directory. Therefore, each individual relation doesn't need to be
* registered for cleanup.
*/
- RelationCreateStorage(dst_rlocator, relpersistence, false);
+ RelationCreateStorage(src_rlocator, dst_rlocator, relpersistence, false);
/* copy main fork. */
RelationCopyStorageUsingBuffer(src_rlocator, dst_rlocator, MAIN_FORKNUM,
@@ -4766,7 +4766,8 @@ CreateAndCopyRelationData(RelFileLocator src_rlocator,
{
if (smgrexists(src_rel, forkNum))
{
- smgrcreate(dst_rel, forkNum, false);
+ /* TODO: for sure? */
+ smgrcreate(src_rel->smgr_rlocator.locator, dst_rel, forkNum, false);
/*
* WAL log creation if the relation is persistent, or this is the
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 5a2072e0816..1766bbe1e57 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -245,7 +245,7 @@ mdexists(SMgrRelation reln, ForkNumber forknum)
* If isRedo is true, it's okay for the relation to exist already.
*/
void
-mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
+mdcreate(RelFileLocator /* reln */, SMgrRelation reln, ForkNumber forknum, bool isRedo)
{
MdSMgrRelation mdreln = (MdSMgrRelation) reln;
MdfdVec *mdfd;
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c
index 9b3e63aff55..0498fd6c317 100644
--- a/src/backend/storage/smgr/smgr.c
+++ b/src/backend/storage/smgr/smgr.c
@@ -408,9 +408,9 @@ smgrexists(SMgrRelation reln, ForkNumber forknum)
* to be created.
*/
void
-smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
+smgrcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo)
{
- smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
+ smgrsw[reln->smgr_which].smgr_create(relold, reln, forknum, isRedo);
}
/*
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index d1ae761b3f6..db3e241404d 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -3829,7 +3829,7 @@ RelationSetNewRelfilenumber(Relation relation, char persistence)
/* handle these directly, at least for now */
SMgrRelation srel;
- srel = RelationCreateStorage(newrlocator, persistence, true);
+ srel = RelationCreateStorage(relation->rd_locator, newrlocator, persistence, true);
smgrclose(srel);
}
else
diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h
index ba99225b0a3..ecc3b792f4f 100644
--- a/src/include/catalog/storage.h
+++ b/src/include/catalog/storage.h
@@ -22,7 +22,8 @@
/* GUC variables */
extern PGDLLIMPORT int wal_skip_threshold;
-extern SMgrRelation RelationCreateStorage(RelFileLocator rlocator,
+extern SMgrRelation RelationCreateStorage(RelFileLocator oldlocator,
+ RelFileLocator rlocator,
char relpersistence,
bool register_delete);
extern void RelationDropStorage(Relation rel);
diff --git a/src/include/storage/md.h b/src/include/storage/md.h
index da1d1d339be..61c0e85dd74 100644
--- a/src/include/storage/md.h
+++ b/src/include/storage/md.h
@@ -27,7 +27,7 @@ extern SMgrId MdSMgrId;
extern void mdinit(void);
extern void mdopen(SMgrRelation reln);
extern void mdclose(SMgrRelation reln, ForkNumber forknum);
-extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
+extern void mdcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo);
extern bool mdexists(SMgrRelation reln, ForkNumber forknum);
extern void mdunlink(RelFileLocatorBackend rlocator, ForkNumber forknum, bool isRedo);
extern void mdextend(SMgrRelation reln, ForkNumber forknum,
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index 629c78cfdde..5b2b6de91c4 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -87,7 +87,7 @@ typedef struct f_smgr
void (*smgr_shutdown) (void); /* may be NULL */
void (*smgr_open) (SMgrRelation reln);
void (*smgr_close) (SMgrRelation reln, ForkNumber forknum);
- void (*smgr_create) (SMgrRelation reln, ForkNumber forknum,
+ void (*smgr_create) (RelFileLocator relold, SMgrRelation reln, ForkNumber forknum,
bool isRedo);
bool (*smgr_exists) (SMgrRelation reln, ForkNumber forknum);
void (*smgr_unlink) (RelFileLocatorBackend rlocator, ForkNumber forknum,
@@ -128,7 +128,7 @@ extern void smgrdestroyall(void);
extern void smgrrelease(SMgrRelation reln);
extern void smgrreleaseall(void);
extern void smgrreleaserellocator(RelFileLocatorBackend rlocator);
-extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
+extern void smgrcreate(RelFileLocator relold, SMgrRelation reln, ForkNumber forknum, bool isRedo);
extern void smgrdosyncall(SMgrRelation *rels, int nrels);
extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
--
2.47.2