mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
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
This commit is contained in:
@@ -293,7 +293,7 @@ cluster_multiple_rels(List *rtcs, ClusterParams *params)
|
||||
* cluster_rel
|
||||
*
|
||||
* This clusters the table by creating a new, clustered table and
|
||||
* swapping the relfilenodes of the new table and the old table, so
|
||||
* swapping the relfilenumbers of the new table and the old table, so
|
||||
* the OID of the original table is preserved. Thus we do not lose
|
||||
* GRANT, inheritance nor references to this table (this was a bug
|
||||
* in releases through 7.3).
|
||||
@@ -1025,8 +1025,8 @@ copy_table_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
|
||||
/*
|
||||
* Swap the physical files of two given relations.
|
||||
*
|
||||
* We swap the physical identity (reltablespace, relfilenode) while keeping the
|
||||
* same logical identities of the two relations. relpersistence is also
|
||||
* We swap the physical identity (reltablespace, relfilenumber) while keeping
|
||||
* the same logical identities of the two relations. relpersistence is also
|
||||
* swapped, which is critical since it determines where buffers live for each
|
||||
* relation.
|
||||
*
|
||||
@@ -1061,9 +1061,9 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
reltup2;
|
||||
Form_pg_class relform1,
|
||||
relform2;
|
||||
Oid relfilenode1,
|
||||
relfilenode2;
|
||||
Oid swaptemp;
|
||||
RelFileNumber relfilenumber1,
|
||||
relfilenumber2;
|
||||
RelFileNumber swaptemp;
|
||||
char swptmpchr;
|
||||
|
||||
/* We need writable copies of both pg_class tuples. */
|
||||
@@ -1079,13 +1079,14 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
elog(ERROR, "cache lookup failed for relation %u", r2);
|
||||
relform2 = (Form_pg_class) GETSTRUCT(reltup2);
|
||||
|
||||
relfilenode1 = relform1->relfilenode;
|
||||
relfilenode2 = relform2->relfilenode;
|
||||
relfilenumber1 = relform1->relfilenode;
|
||||
relfilenumber2 = relform2->relfilenode;
|
||||
|
||||
if (OidIsValid(relfilenode1) && OidIsValid(relfilenode2))
|
||||
if (RelFileNumberIsValid(relfilenumber1) &&
|
||||
RelFileNumberIsValid(relfilenumber2))
|
||||
{
|
||||
/*
|
||||
* Normal non-mapped relations: swap relfilenodes, reltablespaces,
|
||||
* Normal non-mapped relations: swap relfilenumbers, reltablespaces,
|
||||
* relpersistence
|
||||
*/
|
||||
Assert(!target_is_pg_class);
|
||||
@@ -1120,7 +1121,8 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
* Mapped-relation case. Here we have to swap the relation mappings
|
||||
* instead of modifying the pg_class columns. Both must be mapped.
|
||||
*/
|
||||
if (OidIsValid(relfilenode1) || OidIsValid(relfilenode2))
|
||||
if (RelFileNumberIsValid(relfilenumber1) ||
|
||||
RelFileNumberIsValid(relfilenumber2))
|
||||
elog(ERROR, "cannot swap mapped relation \"%s\" with non-mapped relation",
|
||||
NameStr(relform1->relname));
|
||||
|
||||
@@ -1148,12 +1150,12 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
/*
|
||||
* Fetch the mappings --- shouldn't fail, but be paranoid
|
||||
*/
|
||||
relfilenode1 = RelationMapOidToFilenode(r1, relform1->relisshared);
|
||||
if (!OidIsValid(relfilenode1))
|
||||
relfilenumber1 = RelationMapOidToFilenumber(r1, relform1->relisshared);
|
||||
if (!RelFileNumberIsValid(relfilenumber1))
|
||||
elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u",
|
||||
NameStr(relform1->relname), r1);
|
||||
relfilenode2 = RelationMapOidToFilenode(r2, relform2->relisshared);
|
||||
if (!OidIsValid(relfilenode2))
|
||||
relfilenumber2 = RelationMapOidToFilenumber(r2, relform2->relisshared);
|
||||
if (!RelFileNumberIsValid(relfilenumber2))
|
||||
elog(ERROR, "could not find relation mapping for relation \"%s\", OID %u",
|
||||
NameStr(relform2->relname), r2);
|
||||
|
||||
@@ -1161,15 +1163,15 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
* Send replacement mappings to relmapper. Note these won't actually
|
||||
* take effect until CommandCounterIncrement.
|
||||
*/
|
||||
RelationMapUpdateMap(r1, relfilenode2, relform1->relisshared, false);
|
||||
RelationMapUpdateMap(r2, relfilenode1, relform2->relisshared, false);
|
||||
RelationMapUpdateMap(r1, relfilenumber2, relform1->relisshared, false);
|
||||
RelationMapUpdateMap(r2, relfilenumber1, relform2->relisshared, false);
|
||||
|
||||
/* Pass OIDs of mapped r2 tables back to caller */
|
||||
*mapped_tables++ = r2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Recognize that rel1's relfilenode (swapped from rel2) is new in this
|
||||
* Recognize that rel1's relfilenumber (swapped from rel2) is new in this
|
||||
* subtransaction. The rel2 storage (swapped from rel1) may or may not be
|
||||
* new.
|
||||
*/
|
||||
@@ -1180,9 +1182,9 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
|
||||
rel1 = relation_open(r1, NoLock);
|
||||
rel2 = relation_open(r2, NoLock);
|
||||
rel2->rd_createSubid = rel1->rd_createSubid;
|
||||
rel2->rd_newRelfilenodeSubid = rel1->rd_newRelfilenodeSubid;
|
||||
rel2->rd_firstRelfilenodeSubid = rel1->rd_firstRelfilenodeSubid;
|
||||
RelationAssumeNewRelfilenode(rel1);
|
||||
rel2->rd_newRelfilelocatorSubid = rel1->rd_newRelfilelocatorSubid;
|
||||
rel2->rd_firstRelfilelocatorSubid = rel1->rd_firstRelfilelocatorSubid;
|
||||
RelationAssumeNewRelfilelocator(rel1);
|
||||
relation_close(rel1, NoLock);
|
||||
relation_close(rel2, NoLock);
|
||||
}
|
||||
@@ -1523,7 +1525,7 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
|
||||
table_close(relRelation, RowExclusiveLock);
|
||||
}
|
||||
|
||||
/* Destroy new heap with old filenode */
|
||||
/* Destroy new heap with old filenumber */
|
||||
object.classId = RelationRelationId;
|
||||
object.objectId = OIDNewHeap;
|
||||
object.objectSubId = 0;
|
||||
|
@@ -593,12 +593,12 @@ CopyFrom(CopyFromState cstate)
|
||||
*/
|
||||
if (RELKIND_HAS_STORAGE(cstate->rel->rd_rel->relkind) &&
|
||||
(cstate->rel->rd_createSubid != InvalidSubTransactionId ||
|
||||
cstate->rel->rd_firstRelfilenodeSubid != InvalidSubTransactionId))
|
||||
cstate->rel->rd_firstRelfilelocatorSubid != InvalidSubTransactionId))
|
||||
ti_options |= TABLE_INSERT_SKIP_FSM;
|
||||
|
||||
/*
|
||||
* Optimize if new relfilenode was created in this subxact or one of its
|
||||
* committed children and we won't see those rows later as part of an
|
||||
* Optimize if new relation storage was created in this subxact or one of
|
||||
* its committed children and we won't see those rows later as part of an
|
||||
* earlier scan or command. The subxact test ensures that if this subxact
|
||||
* aborts then the frozen rows won't be visible after xact cleanup. Note
|
||||
* that the stronger test of exactly which subtransaction created it is
|
||||
@@ -640,7 +640,7 @@ CopyFrom(CopyFromState cstate)
|
||||
errmsg("cannot perform COPY FREEZE because of prior transaction activity")));
|
||||
|
||||
if (cstate->rel->rd_createSubid != GetCurrentSubTransactionId() &&
|
||||
cstate->rel->rd_newRelfilenodeSubid != GetCurrentSubTransactionId())
|
||||
cstate->rel->rd_newRelfilelocatorSubid != GetCurrentSubTransactionId())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("cannot perform COPY FREEZE because the table was not created or truncated in the current subtransaction")));
|
||||
|
@@ -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)
|
||||
|
@@ -1109,10 +1109,10 @@ DefineIndex(Oid relationId,
|
||||
}
|
||||
|
||||
/*
|
||||
* A valid stmt->oldNode implies that we already have a built form of the
|
||||
* index. The caller should also decline any index build.
|
||||
* A valid stmt->oldNumber implies that we already have a built form of
|
||||
* the index. The caller should also decline any index build.
|
||||
*/
|
||||
Assert(!OidIsValid(stmt->oldNode) || (skip_build && !concurrent));
|
||||
Assert(!RelFileNumberIsValid(stmt->oldNumber) || (skip_build && !concurrent));
|
||||
|
||||
/*
|
||||
* Make the catalog entries for the index, including constraints. This
|
||||
@@ -1154,7 +1154,7 @@ DefineIndex(Oid relationId,
|
||||
indexRelationId =
|
||||
index_create(rel, indexRelationName, indexRelationId, parentIndexId,
|
||||
parentConstraintId,
|
||||
stmt->oldNode, indexInfo, indexColNames,
|
||||
stmt->oldNumber, indexInfo, indexColNames,
|
||||
accessMethodId, tablespaceId,
|
||||
collationObjectId, classObjectId,
|
||||
coloptions, reloptions,
|
||||
@@ -1361,15 +1361,15 @@ DefineIndex(Oid relationId,
|
||||
* We can't use the same index name for the child index,
|
||||
* so clear idxname to let the recursive invocation choose
|
||||
* a new name. Likewise, the existing target relation
|
||||
* field is wrong, and if indexOid or oldNode are set,
|
||||
* field is wrong, and if indexOid or oldNumber are set,
|
||||
* they mustn't be applied to the child either.
|
||||
*/
|
||||
childStmt->idxname = NULL;
|
||||
childStmt->relation = NULL;
|
||||
childStmt->indexOid = InvalidOid;
|
||||
childStmt->oldNode = InvalidOid;
|
||||
childStmt->oldNumber = InvalidRelFileNumber;
|
||||
childStmt->oldCreateSubid = InvalidSubTransactionId;
|
||||
childStmt->oldFirstRelfilenodeSubid = InvalidSubTransactionId;
|
||||
childStmt->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
|
||||
|
||||
/*
|
||||
* Adjust any Vars (both in expressions and in the index's
|
||||
@@ -3015,7 +3015,7 @@ ReindexMultipleTables(const char *objectName, ReindexObjectType objectKind,
|
||||
* particular this eliminates all shared catalogs.).
|
||||
*/
|
||||
if (RELKIND_HAS_STORAGE(classtuple->relkind) &&
|
||||
!OidIsValid(classtuple->relfilenode))
|
||||
!RelFileNumberIsValid(classtuple->relfilenode))
|
||||
skip_rel = true;
|
||||
|
||||
/*
|
||||
|
@@ -118,7 +118,7 @@ SetMatViewPopulatedState(Relation relation, bool newstate)
|
||||
* ExecRefreshMatView -- execute a REFRESH MATERIALIZED VIEW command
|
||||
*
|
||||
* This refreshes the materialized view by creating a new table and swapping
|
||||
* the relfilenodes of the new table and the old materialized view, so the OID
|
||||
* the relfilenumbers of the new table and the old materialized view, so the OID
|
||||
* of the original materialized view is preserved. Thus we do not lose GRANT
|
||||
* nor references to this materialized view.
|
||||
*
|
||||
|
@@ -75,7 +75,7 @@ typedef struct sequence_magic
|
||||
typedef struct SeqTableData
|
||||
{
|
||||
Oid relid; /* pg_class OID of this sequence (hash key) */
|
||||
Oid filenode; /* last seen relfilenode of this sequence */
|
||||
RelFileNumber filenumber; /* last seen relfilenumber of this sequence */
|
||||
LocalTransactionId lxid; /* xact in which we last did a seq op */
|
||||
bool last_valid; /* do we have a valid "last" value? */
|
||||
int64 last; /* value last returned by nextval */
|
||||
@@ -255,7 +255,7 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
|
||||
*
|
||||
* The change is made transactionally, so that on failure of the current
|
||||
* transaction, the sequence will be restored to its previous state.
|
||||
* We do that by creating a whole new relfilenode for the sequence; so this
|
||||
* We do that by creating a whole new relfilenumber for the sequence; so this
|
||||
* works much like the rewriting forms of ALTER TABLE.
|
||||
*
|
||||
* Caller is assumed to have acquired AccessExclusiveLock on the sequence,
|
||||
@@ -310,7 +310,7 @@ ResetSequence(Oid seq_relid)
|
||||
/*
|
||||
* Create a new storage file for the sequence.
|
||||
*/
|
||||
RelationSetNewRelfilenode(seq_rel, seq_rel->rd_rel->relpersistence);
|
||||
RelationSetNewRelfilenumber(seq_rel, seq_rel->rd_rel->relpersistence);
|
||||
|
||||
/*
|
||||
* Ensure sequence's relfrozenxid is at 0, since it won't contain any
|
||||
@@ -347,9 +347,9 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
|
||||
{
|
||||
SMgrRelation srel;
|
||||
|
||||
srel = smgropen(rel->rd_node, InvalidBackendId);
|
||||
srel = smgropen(rel->rd_locator, InvalidBackendId);
|
||||
smgrcreate(srel, INIT_FORKNUM, false);
|
||||
log_smgrcreate(&rel->rd_node, INIT_FORKNUM);
|
||||
log_smgrcreate(&rel->rd_locator, INIT_FORKNUM);
|
||||
fill_seq_fork_with_data(rel, tuple, INIT_FORKNUM);
|
||||
FlushRelationBuffers(rel);
|
||||
smgrclose(srel);
|
||||
@@ -418,7 +418,7 @@ fill_seq_fork_with_data(Relation rel, HeapTuple tuple, ForkNumber forkNum)
|
||||
XLogBeginInsert();
|
||||
XLogRegisterBuffer(0, buf, REGBUF_WILL_INIT);
|
||||
|
||||
xlrec.node = rel->rd_node;
|
||||
xlrec.locator = rel->rd_locator;
|
||||
|
||||
XLogRegisterData((char *) &xlrec, sizeof(xl_seq_rec));
|
||||
XLogRegisterData((char *) tuple->t_data, tuple->t_len);
|
||||
@@ -509,7 +509,7 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
|
||||
* Create a new storage file for the sequence, making the state
|
||||
* changes transactional.
|
||||
*/
|
||||
RelationSetNewRelfilenode(seqrel, seqrel->rd_rel->relpersistence);
|
||||
RelationSetNewRelfilenumber(seqrel, seqrel->rd_rel->relpersistence);
|
||||
|
||||
/*
|
||||
* Ensure sequence's relfrozenxid is at 0, since it won't contain any
|
||||
@@ -557,7 +557,7 @@ SequenceChangePersistence(Oid relid, char newrelpersistence)
|
||||
GetTopTransactionId();
|
||||
|
||||
(void) read_seq_tuple(seqrel, &buf, &seqdatatuple);
|
||||
RelationSetNewRelfilenode(seqrel, newrelpersistence);
|
||||
RelationSetNewRelfilenumber(seqrel, newrelpersistence);
|
||||
fill_seq_with_data(seqrel, &seqdatatuple);
|
||||
UnlockReleaseBuffer(buf);
|
||||
|
||||
@@ -836,7 +836,7 @@ nextval_internal(Oid relid, bool check_permissions)
|
||||
seq->is_called = true;
|
||||
seq->log_cnt = 0;
|
||||
|
||||
xlrec.node = seqrel->rd_node;
|
||||
xlrec.locator = seqrel->rd_locator;
|
||||
|
||||
XLogRegisterData((char *) &xlrec, sizeof(xl_seq_rec));
|
||||
XLogRegisterData((char *) seqdatatuple.t_data, seqdatatuple.t_len);
|
||||
@@ -1023,7 +1023,7 @@ do_setval(Oid relid, int64 next, bool iscalled)
|
||||
XLogBeginInsert();
|
||||
XLogRegisterBuffer(0, buf, REGBUF_WILL_INIT);
|
||||
|
||||
xlrec.node = seqrel->rd_node;
|
||||
xlrec.locator = seqrel->rd_locator;
|
||||
XLogRegisterData((char *) &xlrec, sizeof(xl_seq_rec));
|
||||
XLogRegisterData((char *) seqdatatuple.t_data, seqdatatuple.t_len);
|
||||
|
||||
@@ -1147,7 +1147,7 @@ init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel)
|
||||
if (!found)
|
||||
{
|
||||
/* relid already filled in */
|
||||
elm->filenode = InvalidOid;
|
||||
elm->filenumber = InvalidRelFileNumber;
|
||||
elm->lxid = InvalidLocalTransactionId;
|
||||
elm->last_valid = false;
|
||||
elm->last = elm->cached = 0;
|
||||
@@ -1169,9 +1169,9 @@ init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel)
|
||||
* discard any cached-but-unissued values. We do not touch the currval()
|
||||
* state, however.
|
||||
*/
|
||||
if (seqrel->rd_rel->relfilenode != elm->filenode)
|
||||
if (seqrel->rd_rel->relfilenode != elm->filenumber)
|
||||
{
|
||||
elm->filenode = seqrel->rd_rel->relfilenode;
|
||||
elm->filenumber = seqrel->rd_rel->relfilenode;
|
||||
elm->cached = elm->last;
|
||||
}
|
||||
|
||||
@@ -1254,7 +1254,8 @@ read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple)
|
||||
* changed. This allows ALTER SEQUENCE to behave transactionally. Currently,
|
||||
* the only option that doesn't cause that is OWNED BY. It's *necessary* for
|
||||
* ALTER SEQUENCE OWNED BY to not rewrite the sequence, because that would
|
||||
* break pg_upgrade by causing unwanted changes in the sequence's relfilenode.
|
||||
* break pg_upgrade by causing unwanted changes in the sequence's
|
||||
* relfilenumber.
|
||||
*/
|
||||
static void
|
||||
init_params(ParseState *pstate, List *options, bool for_identity,
|
||||
|
@@ -596,7 +596,7 @@ static void ATExecForceNoForceRowSecurity(Relation rel, bool force_rls);
|
||||
static ObjectAddress ATExecSetCompression(AlteredTableInfo *tab, Relation rel,
|
||||
const char *column, Node *newValue, LOCKMODE lockmode);
|
||||
|
||||
static void index_copy_data(Relation rel, RelFileNode newrnode);
|
||||
static void index_copy_data(Relation rel, RelFileLocator newrlocator);
|
||||
static const char *storage_name(char c);
|
||||
|
||||
static void RangeVarCallbackForDropRelation(const RangeVar *rel, Oid relOid,
|
||||
@@ -1986,12 +1986,12 @@ ExecuteTruncateGuts(List *explicit_rels,
|
||||
/*
|
||||
* Normally, we need a transaction-safe truncation here. However, if
|
||||
* the table was either created in the current (sub)transaction or has
|
||||
* a new relfilenode in the current (sub)transaction, then we can just
|
||||
* truncate it in-place, because a rollback would cause the whole
|
||||
* a new relfilenumber in the current (sub)transaction, then we can
|
||||
* just truncate it in-place, because a rollback would cause the whole
|
||||
* table or the current physical file to be thrown away anyway.
|
||||
*/
|
||||
if (rel->rd_createSubid == mySubid ||
|
||||
rel->rd_newRelfilenodeSubid == mySubid)
|
||||
rel->rd_newRelfilelocatorSubid == mySubid)
|
||||
{
|
||||
/* Immediate, non-rollbackable truncation is OK */
|
||||
heap_truncate_one_rel(rel);
|
||||
@@ -2014,10 +2014,10 @@ ExecuteTruncateGuts(List *explicit_rels,
|
||||
* Need the full transaction-safe pushups.
|
||||
*
|
||||
* Create a new empty storage file for the relation, and assign it
|
||||
* as the relfilenode value. The old storage file is scheduled for
|
||||
* deletion at commit.
|
||||
* as the relfilenumber value. The old storage file is scheduled
|
||||
* for deletion at commit.
|
||||
*/
|
||||
RelationSetNewRelfilenode(rel, rel->rd_rel->relpersistence);
|
||||
RelationSetNewRelfilenumber(rel, rel->rd_rel->relpersistence);
|
||||
|
||||
heap_relid = RelationGetRelid(rel);
|
||||
|
||||
@@ -2030,8 +2030,8 @@ ExecuteTruncateGuts(List *explicit_rels,
|
||||
Relation toastrel = relation_open(toast_relid,
|
||||
AccessExclusiveLock);
|
||||
|
||||
RelationSetNewRelfilenode(toastrel,
|
||||
toastrel->rd_rel->relpersistence);
|
||||
RelationSetNewRelfilenumber(toastrel,
|
||||
toastrel->rd_rel->relpersistence);
|
||||
table_close(toastrel, NoLock);
|
||||
}
|
||||
|
||||
@@ -3315,11 +3315,11 @@ CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
|
||||
|
||||
/*
|
||||
* SetRelationTableSpace
|
||||
* Set new reltablespace and relfilenode in pg_class entry.
|
||||
* Set new reltablespace and relfilenumber in pg_class entry.
|
||||
*
|
||||
* newTableSpaceId is the new tablespace for the relation, and
|
||||
* newRelFileNode its new filenode. If newRelFileNode is InvalidOid,
|
||||
* this field is not updated.
|
||||
* newRelFilenumber its new filenumber. If newRelFilenumber is
|
||||
* InvalidRelFileNumber, this field is not updated.
|
||||
*
|
||||
* NOTE: The caller must hold AccessExclusiveLock on the relation.
|
||||
*
|
||||
@@ -3331,7 +3331,7 @@ CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)
|
||||
void
|
||||
SetRelationTableSpace(Relation rel,
|
||||
Oid newTableSpaceId,
|
||||
Oid newRelFileNode)
|
||||
RelFileNumber newRelFilenumber)
|
||||
{
|
||||
Relation pg_class;
|
||||
HeapTuple tuple;
|
||||
@@ -3351,8 +3351,8 @@ SetRelationTableSpace(Relation rel,
|
||||
/* Update the pg_class row. */
|
||||
rd_rel->reltablespace = (newTableSpaceId == MyDatabaseTableSpace) ?
|
||||
InvalidOid : newTableSpaceId;
|
||||
if (OidIsValid(newRelFileNode))
|
||||
rd_rel->relfilenode = newRelFileNode;
|
||||
if (RelFileNumberIsValid(newRelFilenumber))
|
||||
rd_rel->relfilenode = newRelFilenumber;
|
||||
CatalogTupleUpdate(pg_class, &tuple->t_self, tuple);
|
||||
|
||||
/*
|
||||
@@ -5420,7 +5420,7 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
|
||||
* persistence: on one hand, we need to ensure that the buffers
|
||||
* belonging to each of the two relations are marked with or without
|
||||
* BM_PERMANENT properly. On the other hand, since rewriting creates
|
||||
* and assigns a new relfilenode, we automatically create or drop an
|
||||
* and assigns a new relfilenumber, we automatically create or drop an
|
||||
* init fork for the relation as appropriate.
|
||||
*/
|
||||
if (tab->rewrite > 0 && tab->relkind != RELKIND_SEQUENCE)
|
||||
@@ -5506,12 +5506,13 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqueue, LOCKMODE lockmode,
|
||||
* Create transient table that will receive the modified data.
|
||||
*
|
||||
* Ensure it is marked correctly as logged or unlogged. We have
|
||||
* to do this here so that buffers for the new relfilenode will
|
||||
* to do this here so that buffers for the new relfilenumber will
|
||||
* have the right persistence set, and at the same time ensure
|
||||
* that the original filenode's buffers will get read in with the
|
||||
* correct setting (i.e. the original one). Otherwise a rollback
|
||||
* after the rewrite would possibly result with buffers for the
|
||||
* original filenode having the wrong persistence setting.
|
||||
* that the original filenumbers's buffers will get read in with
|
||||
* the correct setting (i.e. the original one). Otherwise a
|
||||
* rollback after the rewrite would possibly result with buffers
|
||||
* for the original filenumbers having the wrong persistence
|
||||
* setting.
|
||||
*
|
||||
* NB: This relies on swap_relation_files() also swapping the
|
||||
* persistence. That wouldn't work for pg_class, but that can't be
|
||||
@@ -8597,7 +8598,7 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
|
||||
/* suppress schema rights check when rebuilding existing index */
|
||||
check_rights = !is_rebuild;
|
||||
/* skip index build if phase 3 will do it or we're reusing an old one */
|
||||
skip_build = tab->rewrite > 0 || OidIsValid(stmt->oldNode);
|
||||
skip_build = tab->rewrite > 0 || RelFileNumberIsValid(stmt->oldNumber);
|
||||
/* suppress notices when rebuilding existing index */
|
||||
quiet = is_rebuild;
|
||||
|
||||
@@ -8613,21 +8614,21 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
|
||||
quiet);
|
||||
|
||||
/*
|
||||
* If TryReuseIndex() stashed a relfilenode for us, we used it for the new
|
||||
* index instead of building from scratch. Restore associated fields.
|
||||
* If TryReuseIndex() stashed a relfilenumber for us, we used it for the
|
||||
* new index instead of building from scratch. Restore associated fields.
|
||||
* This may store InvalidSubTransactionId in both fields, in which case
|
||||
* relcache.c will assume it can rebuild the relcache entry. Hence, do
|
||||
* this after the CCI that made catalog rows visible to any rebuild. The
|
||||
* DROP of the old edition of this index will have scheduled the storage
|
||||
* for deletion at commit, so cancel that pending deletion.
|
||||
*/
|
||||
if (OidIsValid(stmt->oldNode))
|
||||
if (RelFileNumberIsValid(stmt->oldNumber))
|
||||
{
|
||||
Relation irel = index_open(address.objectId, NoLock);
|
||||
|
||||
irel->rd_createSubid = stmt->oldCreateSubid;
|
||||
irel->rd_firstRelfilenodeSubid = stmt->oldFirstRelfilenodeSubid;
|
||||
RelationPreserveStorage(irel->rd_node, true);
|
||||
irel->rd_firstRelfilelocatorSubid = stmt->oldFirstRelfilelocatorSubid;
|
||||
RelationPreserveStorage(irel->rd_locator, true);
|
||||
index_close(irel, NoLock);
|
||||
}
|
||||
|
||||
@@ -13491,9 +13492,9 @@ TryReuseIndex(Oid oldId, IndexStmt *stmt)
|
||||
/* If it's a partitioned index, there is no storage to share. */
|
||||
if (irel->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
|
||||
{
|
||||
stmt->oldNode = irel->rd_node.relNode;
|
||||
stmt->oldNumber = irel->rd_locator.relNumber;
|
||||
stmt->oldCreateSubid = irel->rd_createSubid;
|
||||
stmt->oldFirstRelfilenodeSubid = irel->rd_firstRelfilenodeSubid;
|
||||
stmt->oldFirstRelfilelocatorSubid = irel->rd_firstRelfilelocatorSubid;
|
||||
}
|
||||
index_close(irel, NoLock);
|
||||
}
|
||||
@@ -14340,8 +14341,8 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode)
|
||||
{
|
||||
Relation rel;
|
||||
Oid reltoastrelid;
|
||||
Oid newrelfilenode;
|
||||
RelFileNode newrnode;
|
||||
RelFileNumber newrelfilenumber;
|
||||
RelFileLocator newrlocator;
|
||||
List *reltoastidxids = NIL;
|
||||
ListCell *lc;
|
||||
|
||||
@@ -14370,26 +14371,26 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode)
|
||||
}
|
||||
|
||||
/*
|
||||
* Relfilenodes are not unique in databases across tablespaces, so we need
|
||||
* to allocate a new one in the new tablespace.
|
||||
* Relfilenumbers are not unique in databases across tablespaces, so we
|
||||
* need to allocate a new one in the new tablespace.
|
||||
*/
|
||||
newrelfilenode = GetNewRelFileNode(newTableSpace, NULL,
|
||||
rel->rd_rel->relpersistence);
|
||||
newrelfilenumber = GetNewRelFileNumber(newTableSpace, NULL,
|
||||
rel->rd_rel->relpersistence);
|
||||
|
||||
/* Open old and new relation */
|
||||
newrnode = rel->rd_node;
|
||||
newrnode.relNode = newrelfilenode;
|
||||
newrnode.spcNode = newTableSpace;
|
||||
newrlocator = rel->rd_locator;
|
||||
newrlocator.relNumber = newrelfilenumber;
|
||||
newrlocator.spcOid = newTableSpace;
|
||||
|
||||
/* hand off to AM to actually create the new filenode and copy the data */
|
||||
/* hand off to AM to actually create new rel storage and copy the data */
|
||||
if (rel->rd_rel->relkind == RELKIND_INDEX)
|
||||
{
|
||||
index_copy_data(rel, newrnode);
|
||||
index_copy_data(rel, newrlocator);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert(RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind));
|
||||
table_relation_copy_data(rel, &newrnode);
|
||||
table_relation_copy_data(rel, &newrlocator);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -14400,11 +14401,11 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, LOCKMODE lockmode)
|
||||
* the updated pg_class entry), but that's forbidden with
|
||||
* CheckRelationTableSpaceMove().
|
||||
*/
|
||||
SetRelationTableSpace(rel, newTableSpace, newrelfilenode);
|
||||
SetRelationTableSpace(rel, newTableSpace, newrelfilenumber);
|
||||
|
||||
InvokeObjectPostAlterHook(RelationRelationId, RelationGetRelid(rel), 0);
|
||||
|
||||
RelationAssumeNewRelfilenode(rel);
|
||||
RelationAssumeNewRelfilelocator(rel);
|
||||
|
||||
relation_close(rel, NoLock);
|
||||
|
||||
@@ -14630,11 +14631,11 @@ AlterTableMoveAll(AlterTableMoveAllStmt *stmt)
|
||||
}
|
||||
|
||||
static void
|
||||
index_copy_data(Relation rel, RelFileNode newrnode)
|
||||
index_copy_data(Relation rel, RelFileLocator newrlocator)
|
||||
{
|
||||
SMgrRelation dstrel;
|
||||
|
||||
dstrel = smgropen(newrnode, rel->rd_backend);
|
||||
dstrel = smgropen(newrlocator, rel->rd_backend);
|
||||
|
||||
/*
|
||||
* Since we copy the file directly without looking at the shared buffers,
|
||||
@@ -14648,10 +14649,10 @@ index_copy_data(Relation rel, RelFileNode newrnode)
|
||||
* Create and copy all forks of the relation, and schedule unlinking of
|
||||
* old physical files.
|
||||
*
|
||||
* NOTE: any conflict in relfilenode value will be caught in
|
||||
* NOTE: any conflict in relfilenumber value will be caught in
|
||||
* RelationCreateStorage().
|
||||
*/
|
||||
RelationCreateStorage(newrnode, rel->rd_rel->relpersistence, true);
|
||||
RelationCreateStorage(newrlocator, rel->rd_rel->relpersistence, true);
|
||||
|
||||
/* copy main fork */
|
||||
RelationCopyStorage(RelationGetSmgr(rel), dstrel, MAIN_FORKNUM,
|
||||
@@ -14672,7 +14673,7 @@ index_copy_data(Relation rel, RelFileNode newrnode)
|
||||
if (RelationIsPermanent(rel) ||
|
||||
(rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&
|
||||
forkNum == INIT_FORKNUM))
|
||||
log_smgrcreate(&newrnode, forkNum);
|
||||
log_smgrcreate(&newrlocator, forkNum);
|
||||
RelationCopyStorage(RelationGetSmgr(rel), dstrel, forkNum,
|
||||
rel->rd_rel->relpersistence);
|
||||
}
|
||||
|
@@ -12,12 +12,12 @@
|
||||
* remove the possibility of having file name conflicts, we isolate
|
||||
* files within a tablespace into database-specific subdirectories.
|
||||
*
|
||||
* To support file access via the information given in RelFileNode, we
|
||||
* To support file access via the information given in RelFileLocator, we
|
||||
* maintain a symbolic-link map in $PGDATA/pg_tblspc. The symlinks are
|
||||
* named by tablespace OIDs and point to the actual tablespace directories.
|
||||
* There is also a per-cluster version directory in each tablespace.
|
||||
* Thus the full path to an arbitrary file is
|
||||
* $PGDATA/pg_tblspc/spcoid/PG_MAJORVER_CATVER/dboid/relfilenode
|
||||
* $PGDATA/pg_tblspc/spcoid/PG_MAJORVER_CATVER/dboid/relfilenumber
|
||||
* e.g.
|
||||
* $PGDATA/pg_tblspc/20981/PG_9.0_201002161/719849/83292814
|
||||
*
|
||||
@@ -25,8 +25,8 @@
|
||||
* tables) and pg_default (for everything else). For backwards compatibility
|
||||
* and to remain functional on platforms without symlinks, these tablespaces
|
||||
* are accessed specially: they are respectively
|
||||
* $PGDATA/global/relfilenode
|
||||
* $PGDATA/base/dboid/relfilenode
|
||||
* $PGDATA/global/relfilenumber
|
||||
* $PGDATA/base/dboid/relfilenumber
|
||||
*
|
||||
* To allow CREATE DATABASE to give a new database a default tablespace
|
||||
* that's different from the template database's default, we make the
|
||||
@@ -115,7 +115,7 @@ static bool destroy_tablespace_directories(Oid tablespaceoid, bool redo);
|
||||
* re-create a database subdirectory (of $PGDATA/base) during WAL replay.
|
||||
*/
|
||||
void
|
||||
TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo)
|
||||
TablespaceCreateDbspace(Oid spcOid, Oid dbOid, bool isRedo)
|
||||
{
|
||||
struct stat st;
|
||||
char *dir;
|
||||
@@ -124,13 +124,13 @@ TablespaceCreateDbspace(Oid spcNode, Oid dbNode, bool isRedo)
|
||||
* The global tablespace doesn't have per-database subdirectories, so
|
||||
* nothing to do for it.
|
||||
*/
|
||||
if (spcNode == GLOBALTABLESPACE_OID)
|
||||
if (spcOid == GLOBALTABLESPACE_OID)
|
||||
return;
|
||||
|
||||
Assert(OidIsValid(spcNode));
|
||||
Assert(OidIsValid(dbNode));
|
||||
Assert(OidIsValid(spcOid));
|
||||
Assert(OidIsValid(dbOid));
|
||||
|
||||
dir = GetDatabasePath(dbNode, spcNode);
|
||||
dir = GetDatabasePath(dbOid, spcOid);
|
||||
|
||||
if (stat(dir, &st) < 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user