aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-07-06 11:39:09 -0400
committerRobert Haas <rhaas@postgresql.org>2022-07-06 11:39:09 -0400
commitb0a55e43299c4ea2a9a8c757f9c26352407d0ccc (patch)
tree2c22c2965f9976ae4469595cd28df13db6b943c2 /src/backend/commands/dbcommands.c
parent7775c748db1257523ecbed1060dadb608bdff6de (diff)
downloadpostgresql-b0a55e43299c4ea2a9a8c757f9c26352407d0ccc.tar.gz
postgresql-b0a55e43299c4ea2a9a8c757f9c26352407d0ccc.zip
Change internal RelFileNode references to RelFileNumber or RelFileLocator.
We have been using the term RelFileNode to refer to either (1) the integer that is used to name the sequence of files for a certain relation within the directory set aside for that tablespace/database combination; or (2) that value plus the OIDs of the tablespace and database; or occasionally (3) the whole series of files created for a relation based on those values. Using the same name for more than one thing is confusing. Replace RelFileNode with RelFileNumber when we're talking about just the single number, i.e. (1) from above, and with RelFileLocator when we're talking about all the things that are needed to locate a relation's files on disk, i.e. (2) from above. In the places where we refer to (3) as a relfilenode, instead refer to "relation storage". Since there is a ton of SQL code in the world that knows about pg_class.relfilenode, don't change the name of that column, or of other SQL-facing things that derive their name from it. On the other hand, do adjust closely-related internal terminology. For example, the structure member names dbNode and spcNode appear to be derived from the fact that the structure itself was called RelFileNode, so change those to dbOid and spcOid. Likewise, various variables with names like rnode and relnode get renamed appropriately, according to how they're being used in context. Hopefully, this is clearer than before. It is also preparation for future patches that intend to widen the relfilenumber fields from its current width of 32 bits. Variables that store a relfilenumber are now declared as type RelFileNumber rather than type Oid; right now, these are the same, but that can now more easily be changed. Dilip Kumar, per an idea from me. Reviewed also by Andres Freund. I fixed some whitespace issues, changed a couple of words in a comment, and made one other minor correction. Discussion: http://postgr.es/m/CA+TgmoamOtXbVAQf9hWFzonUo6bhhjS6toZQd7HZ-pmojtAmag@mail.gmail.com Discussion: http://postgr.es/m/CA+Tgmobp7+7kmi4gkq7Y+4AM9fTvL+O1oQ4-5gFTT+6Ng-dQ=g@mail.gmail.com Discussion: http://postgr.es/m/CAFiTN-vTe79M8uDH1yprOU64MNFE+R3ODRuA+JWf27JbhY4hJw@mail.gmail.com
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r--src/backend/commands/dbcommands.c108
1 files changed, 54 insertions, 54 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index f2691684010..1901b434c58 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -101,7 +101,7 @@ typedef struct
*/
typedef struct CreateDBRelInfo
{
- RelFileNode rnode; /* physical relation identifier */
+ RelFileLocator rlocator; /* physical relation identifier */
Oid reloid; /* relation oid */
bool permanent; /* relation is permanent or unlogged */
} CreateDBRelInfo;
@@ -127,7 +127,7 @@ static void CreateDatabaseUsingWalLog(Oid src_dboid, Oid dboid, Oid src_tsid,
static List *ScanSourceDatabasePgClass(Oid srctbid, Oid srcdbid, char *srcpath);
static List *ScanSourceDatabasePgClassPage(Page page, Buffer buf, Oid tbid,
Oid dbid, char *srcpath,
- List *rnodelist, Snapshot snapshot);
+ List *rlocatorlist, Snapshot snapshot);
static CreateDBRelInfo *ScanSourceDatabasePgClassTuple(HeapTupleData *tuple,
Oid tbid, Oid dbid,
char *srcpath);
@@ -147,12 +147,12 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
{
char *srcpath;
char *dstpath;
- List *rnodelist = NULL;
+ List *rlocatorlist = NULL;
ListCell *cell;
LockRelId srcrelid;
LockRelId dstrelid;
- RelFileNode srcrnode;
- RelFileNode dstrnode;
+ RelFileLocator srcrlocator;
+ RelFileLocator dstrlocator;
CreateDBRelInfo *relinfo;
/* Get source and destination database paths. */
@@ -165,9 +165,9 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
/* Copy relmap file from source database to the destination database. */
RelationMapCopy(dst_dboid, dst_tsid, srcpath, dstpath);
- /* Get list of relfilenodes to copy from the source database. */
- rnodelist = ScanSourceDatabasePgClass(src_tsid, src_dboid, srcpath);
- Assert(rnodelist != NIL);
+ /* Get list of relfilelocators to copy from the source database. */
+ rlocatorlist = ScanSourceDatabasePgClass(src_tsid, src_dboid, srcpath);
+ Assert(rlocatorlist != NIL);
/*
* Database IDs will be the same for all relations so set them before
@@ -176,11 +176,11 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
srcrelid.dbId = src_dboid;
dstrelid.dbId = dst_dboid;
- /* Loop over our list of relfilenodes and copy each one. */
- foreach(cell, rnodelist)
+ /* Loop over our list of relfilelocators and copy each one. */
+ foreach(cell, rlocatorlist)
{
relinfo = lfirst(cell);
- srcrnode = relinfo->rnode;
+ srcrlocator = relinfo->rlocator;
/*
* If the relation is from the source db's default tablespace then we
@@ -188,13 +188,13 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
* Otherwise, we need to create in the same tablespace as it is in the
* source database.
*/
- if (srcrnode.spcNode == src_tsid)
- dstrnode.spcNode = dst_tsid;
+ if (srcrlocator.spcOid == src_tsid)
+ dstrlocator.spcOid = dst_tsid;
else
- dstrnode.spcNode = srcrnode.spcNode;
+ dstrlocator.spcOid = srcrlocator.spcOid;
- dstrnode.dbNode = dst_dboid;
- dstrnode.relNode = srcrnode.relNode;
+ dstrlocator.dbOid = dst_dboid;
+ dstrlocator.relNumber = srcrlocator.relNumber;
/*
* Acquire locks on source and target relations before copying.
@@ -210,7 +210,7 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
LockRelationId(&dstrelid, AccessShareLock);
/* Copy relation storage from source to the destination. */
- CreateAndCopyRelationData(srcrnode, dstrnode, relinfo->permanent);
+ CreateAndCopyRelationData(srcrlocator, dstrlocator, relinfo->permanent);
/* Release the relation locks. */
UnlockRelationId(&srcrelid, AccessShareLock);
@@ -219,7 +219,7 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
pfree(srcpath);
pfree(dstpath);
- list_free_deep(rnodelist);
+ list_free_deep(rlocatorlist);
}
/*
@@ -246,31 +246,31 @@ CreateDatabaseUsingWalLog(Oid src_dboid, Oid dst_dboid,
static List *
ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
{
- RelFileNode rnode;
+ RelFileLocator rlocator;
BlockNumber nblocks;
BlockNumber blkno;
Buffer buf;
- Oid relfilenode;
+ Oid relfilenumber;
Page page;
- List *rnodelist = NIL;
+ List *rlocatorlist = NIL;
LockRelId relid;
Relation rel;
Snapshot snapshot;
BufferAccessStrategy bstrategy;
- /* Get pg_class relfilenode. */
- relfilenode = RelationMapOidToFilenodeForDatabase(srcpath,
- RelationRelationId);
+ /* Get pg_class relfilenumber. */
+ relfilenumber = RelationMapOidToFilenumberForDatabase(srcpath,
+ RelationRelationId);
/* Don't read data into shared_buffers without holding a relation lock. */
relid.dbId = dbid;
relid.relId = RelationRelationId;
LockRelationId(&relid, AccessShareLock);
- /* Prepare a RelFileNode for the pg_class relation. */
- rnode.spcNode = tbid;
- rnode.dbNode = dbid;
- rnode.relNode = relfilenode;
+ /* Prepare a RelFileLocator for the pg_class relation. */
+ rlocator.spcOid = tbid;
+ rlocator.dbOid = dbid;
+ rlocator.relNumber = relfilenumber;
/*
* We can't use a real relcache entry for a relation in some other
@@ -279,7 +279,7 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
* used the smgr layer directly, we would have to worry about
* invalidations.
*/
- rel = CreateFakeRelcacheEntry(rnode);
+ rel = CreateFakeRelcacheEntry(rlocator);
nblocks = smgrnblocks(RelationGetSmgr(rel), MAIN_FORKNUM);
FreeFakeRelcacheEntry(rel);
@@ -299,7 +299,7 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
{
CHECK_FOR_INTERRUPTS();
- buf = ReadBufferWithoutRelcache(rnode, MAIN_FORKNUM, blkno,
+ buf = ReadBufferWithoutRelcache(rlocator, MAIN_FORKNUM, blkno,
RBM_NORMAL, bstrategy, false);
LockBuffer(buf, BUFFER_LOCK_SHARE);
@@ -310,10 +310,10 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
continue;
}
- /* Append relevant pg_class tuples for current page to rnodelist. */
- rnodelist = ScanSourceDatabasePgClassPage(page, buf, tbid, dbid,
- srcpath, rnodelist,
- snapshot);
+ /* Append relevant pg_class tuples for current page to rlocatorlist. */
+ rlocatorlist = ScanSourceDatabasePgClassPage(page, buf, tbid, dbid,
+ srcpath, rlocatorlist,
+ snapshot);
UnlockReleaseBuffer(buf);
}
@@ -321,16 +321,16 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
/* Release relation lock. */
UnlockRelationId(&relid, AccessShareLock);
- return rnodelist;
+ return rlocatorlist;
}
/*
* Scan one page of the source database's pg_class relation and add relevant
- * entries to rnodelist. The return value is the updated list.
+ * entries to rlocatorlist. The return value is the updated list.
*/
static List *
ScanSourceDatabasePgClassPage(Page page, Buffer buf, Oid tbid, Oid dbid,
- char *srcpath, List *rnodelist,
+ char *srcpath, List *rlocatorlist,
Snapshot snapshot)
{
BlockNumber blkno = BufferGetBlockNumber(buf);
@@ -376,11 +376,11 @@ ScanSourceDatabasePgClassPage(Page page, Buffer buf, Oid tbid, Oid dbid,
relinfo = ScanSourceDatabasePgClassTuple(&tuple, tbid, dbid,
srcpath);
if (relinfo != NULL)
- rnodelist = lappend(rnodelist, relinfo);
+ rlocatorlist = lappend(rlocatorlist, relinfo);
}
}
- return rnodelist;
+ return rlocatorlist;
}
/*
@@ -397,7 +397,7 @@ ScanSourceDatabasePgClassTuple(HeapTupleData *tuple, Oid tbid, Oid dbid,
{
CreateDBRelInfo *relinfo;
Form_pg_class classForm;
- Oid relfilenode = InvalidOid;
+ Oid relfilenumber = InvalidRelFileNumber;
classForm = (Form_pg_class) GETSTRUCT(tuple);
@@ -418,29 +418,29 @@ ScanSourceDatabasePgClassTuple(HeapTupleData *tuple, Oid tbid, Oid dbid,
return NULL;
/*
- * If relfilenode is valid then directly use it. Otherwise, consult the
+ * If relfilenumber is valid then directly use it. Otherwise, consult the
* relmap.
*/
- if (OidIsValid(classForm->relfilenode))
- relfilenode = classForm->relfilenode;
+ if (RelFileNumberIsValid(classForm->relfilenode))
+ relfilenumber = classForm->relfilenode;
else
- relfilenode = RelationMapOidToFilenodeForDatabase(srcpath,
- classForm->oid);
+ relfilenumber = RelationMapOidToFilenumberForDatabase(srcpath,
+ classForm->oid);
- /* We must have a valid relfilenode oid. */
- if (!OidIsValid(relfilenode))
- elog(ERROR, "relation with OID %u does not have a valid relfilenode",
+ /* We must have a valid relfilenumber. */
+ if (!RelFileNumberIsValid(relfilenumber))
+ elog(ERROR, "relation with OID %u does not have a valid relfilenumber",
classForm->oid);
/* Prepare a rel info element and add it to the list. */
relinfo = (CreateDBRelInfo *) palloc(sizeof(CreateDBRelInfo));
if (OidIsValid(classForm->reltablespace))
- relinfo->rnode.spcNode = classForm->reltablespace;
+ relinfo->rlocator.spcOid = classForm->reltablespace;
else
- relinfo->rnode.spcNode = tbid;
+ relinfo->rlocator.spcOid = tbid;
- relinfo->rnode.dbNode = dbid;
- relinfo->rnode.relNode = relfilenode;
+ relinfo->rlocator.dbOid = dbid;
+ relinfo->rlocator.relNumber = relfilenumber;
relinfo->reloid = classForm->oid;
/* Temporary relations were rejected above. */
@@ -2867,8 +2867,8 @@ remove_dbtablespaces(Oid db_id)
* try to remove that already-existing subdirectory during the cleanup in
* remove_dbtablespaces. Nuking existing files seems like a bad idea, so
* instead we make this extra check before settling on the OID of the new
- * database. This exactly parallels what GetNewRelFileNode() does for table
- * relfilenode values.
+ * database. This exactly parallels what GetNewRelFileNumber() does for table
+ * relfilenumber values.
*/
static bool
check_db_file_conflict(Oid db_id)