1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +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:
Robert Haas
2022-07-06 11:39:09 -04:00
parent 7775c748db
commit b0a55e4329
138 changed files with 1640 additions and 1606 deletions

View File

@@ -38,7 +38,7 @@
int wal_skip_threshold = 2048; /* in kilobytes */
/*
* We keep a list of all relations (represented as RelFileNode values)
* We keep a list of all relations (represented as RelFileLocator values)
* that have been created or deleted in the current transaction. When
* a relation is created, we create the physical file immediately, but
* remember it so that we can delete the file again if the current
@@ -59,7 +59,7 @@ int wal_skip_threshold = 2048; /* in kilobytes */
typedef struct PendingRelDelete
{
RelFileNode relnode; /* relation that may need to be deleted */
RelFileLocator rlocator; /* relation that may need to be deleted */
BackendId backend; /* InvalidBackendId if not a temp rel */
bool atCommit; /* T=delete at commit; F=delete at abort */
int nestLevel; /* xact nesting level of request */
@@ -68,7 +68,7 @@ typedef struct PendingRelDelete
typedef struct PendingRelSync
{
RelFileNode rnode;
RelFileLocator rlocator;
bool is_truncated; /* Has the file experienced truncation? */
} PendingRelSync;
@@ -81,7 +81,7 @@ static HTAB *pendingSyncHash = NULL;
* Queue an at-commit fsync.
*/
static void
AddPendingSync(const RelFileNode *rnode)
AddPendingSync(const RelFileLocator *rlocator)
{
PendingRelSync *pending;
bool found;
@@ -91,14 +91,14 @@ AddPendingSync(const RelFileNode *rnode)
{
HASHCTL ctl;
ctl.keysize = sizeof(RelFileNode);
ctl.keysize = sizeof(RelFileLocator);
ctl.entrysize = sizeof(PendingRelSync);
ctl.hcxt = TopTransactionContext;
pendingSyncHash = hash_create("pending sync hash", 16, &ctl,
HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
}
pending = hash_search(pendingSyncHash, rnode, HASH_ENTER, &found);
pending = hash_search(pendingSyncHash, rlocator, HASH_ENTER, &found);
Assert(!found);
pending->is_truncated = false;
}
@@ -117,7 +117,7 @@ AddPendingSync(const RelFileNode *rnode)
* pass register_delete = false.
*/
SMgrRelation
RelationCreateStorage(RelFileNode rnode, char relpersistence,
RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
bool register_delete)
{
SMgrRelation srel;
@@ -145,11 +145,11 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence,
return NULL; /* placate compiler */
}
srel = smgropen(rnode, backend);
srel = smgropen(rlocator, backend);
smgrcreate(srel, MAIN_FORKNUM, false);
if (needs_wal)
log_smgrcreate(&srel->smgr_rnode.node, MAIN_FORKNUM);
log_smgrcreate(&srel->smgr_rlocator.locator, MAIN_FORKNUM);
/*
* Add the relation to the list of stuff to delete at abort, if we are
@@ -161,7 +161,7 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence,
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
pending->relnode = rnode;
pending->rlocator = rlocator;
pending->backend = backend;
pending->atCommit = false; /* delete if abort */
pending->nestLevel = GetCurrentTransactionNestLevel();
@@ -172,7 +172,7 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence,
if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded())
{
Assert(backend == InvalidBackendId);
AddPendingSync(&rnode);
AddPendingSync(&rlocator);
}
return srel;
@@ -182,14 +182,14 @@ RelationCreateStorage(RelFileNode rnode, char relpersistence,
* Perform XLogInsert of an XLOG_SMGR_CREATE record to WAL.
*/
void
log_smgrcreate(const RelFileNode *rnode, ForkNumber forkNum)
log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
{
xl_smgr_create xlrec;
/*
* Make an XLOG entry reporting the file creation.
*/
xlrec.rnode = *rnode;
xlrec.rlocator = *rlocator;
xlrec.forkNum = forkNum;
XLogBeginInsert();
@@ -209,7 +209,7 @@ RelationDropStorage(Relation rel)
/* Add the relation to the list of stuff to delete at commit */
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
pending->relnode = rel->rd_node;
pending->rlocator = rel->rd_locator;
pending->backend = rel->rd_backend;
pending->atCommit = true; /* delete if commit */
pending->nestLevel = GetCurrentTransactionNestLevel();
@@ -247,7 +247,7 @@ RelationDropStorage(Relation rel)
* No-op if the relation is not among those scheduled for deletion.
*/
void
RelationPreserveStorage(RelFileNode rnode, bool atCommit)
RelationPreserveStorage(RelFileLocator rlocator, bool atCommit)
{
PendingRelDelete *pending;
PendingRelDelete *prev;
@@ -257,7 +257,7 @@ RelationPreserveStorage(RelFileNode rnode, bool atCommit)
for (pending = pendingDeletes; pending != NULL; pending = next)
{
next = pending->next;
if (RelFileNodeEquals(rnode, pending->relnode)
if (RelFileLocatorEquals(rlocator, pending->rlocator)
&& pending->atCommit == atCommit)
{
/* unlink and delete list entry */
@@ -369,7 +369,7 @@ RelationTruncate(Relation rel, BlockNumber nblocks)
xl_smgr_truncate xlrec;
xlrec.blkno = nblocks;
xlrec.rnode = rel->rd_node;
xlrec.rlocator = rel->rd_locator;
xlrec.flags = SMGR_TRUNCATE_ALL;
XLogBeginInsert();
@@ -428,7 +428,7 @@ RelationPreTruncate(Relation rel)
return;
pending = hash_search(pendingSyncHash,
&(RelationGetSmgr(rel)->smgr_rnode.node),
&(RelationGetSmgr(rel)->smgr_rlocator.locator),
HASH_FIND, NULL);
if (pending)
pending->is_truncated = true;
@@ -472,7 +472,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
* We need to log the copied data in WAL iff WAL archiving/streaming is
* enabled AND it's a permanent relation. This gives the same answer as
* "RelationNeedsWAL(rel) || copying_initfork", because we know the
* current operation created a new relfilenode.
* current operation created new relation storage.
*/
use_wal = XLogIsNeeded() &&
(relpersistence == RELPERSISTENCE_PERMANENT || copying_initfork);
@@ -496,8 +496,8 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
* (errcontext callbacks shouldn't be risking any such thing, but
* people have been known to forget that rule.)
*/
char *relpath = relpathbackend(src->smgr_rnode.node,
src->smgr_rnode.backend,
char *relpath = relpathbackend(src->smgr_rlocator.locator,
src->smgr_rlocator.backend,
forkNum);
ereport(ERROR,
@@ -512,7 +512,7 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
* space.
*/
if (use_wal)
log_newpage(&dst->smgr_rnode.node, forkNum, blkno, page, false);
log_newpage(&dst->smgr_rlocator.locator, forkNum, blkno, page, false);
PageSetChecksumInplace(page, blkno);
@@ -538,19 +538,19 @@ RelationCopyStorage(SMgrRelation src, SMgrRelation dst,
}
/*
* RelFileNodeSkippingWAL
* Check if a BM_PERMANENT relfilenode is using WAL.
* RelFileLocatorSkippingWAL
* Check if a BM_PERMANENT relfilelocator is using WAL.
*
* Changes of certain relfilenodes must not write WAL; see "Skipping WAL for
* New RelFileNode" in src/backend/access/transam/README. Though it is known
* from Relation efficiently, this function is intended for the code paths not
* having access to Relation.
* Changes to certain relations must not write WAL; see "Skipping WAL for
* New RelFileLocator" in src/backend/access/transam/README. Though it is
* known from Relation efficiently, this function is intended for the code
* paths not having access to Relation.
*/
bool
RelFileNodeSkippingWAL(RelFileNode rnode)
RelFileLocatorSkippingWAL(RelFileLocator rlocator)
{
if (!pendingSyncHash ||
hash_search(pendingSyncHash, &rnode, HASH_FIND, NULL) == NULL)
hash_search(pendingSyncHash, &rlocator, HASH_FIND, NULL) == NULL)
return false;
return true;
@@ -566,7 +566,7 @@ EstimatePendingSyncsSpace(void)
long entries;
entries = pendingSyncHash ? hash_get_num_entries(pendingSyncHash) : 0;
return mul_size(1 + entries, sizeof(RelFileNode));
return mul_size(1 + entries, sizeof(RelFileLocator));
}
/*
@@ -581,57 +581,58 @@ SerializePendingSyncs(Size maxSize, char *startAddress)
HASH_SEQ_STATUS scan;
PendingRelSync *sync;
PendingRelDelete *delete;
RelFileNode *src;
RelFileNode *dest = (RelFileNode *) startAddress;
RelFileLocator *src;
RelFileLocator *dest = (RelFileLocator *) startAddress;
if (!pendingSyncHash)
goto terminate;
/* Create temporary hash to collect active relfilenodes */
ctl.keysize = sizeof(RelFileNode);
ctl.entrysize = sizeof(RelFileNode);
/* Create temporary hash to collect active relfilelocators */
ctl.keysize = sizeof(RelFileLocator);
ctl.entrysize = sizeof(RelFileLocator);
ctl.hcxt = CurrentMemoryContext;
tmphash = hash_create("tmp relfilenodes",
tmphash = hash_create("tmp relfilelocators",
hash_get_num_entries(pendingSyncHash), &ctl,
HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
/* collect all rnodes from pending syncs */
/* collect all rlocator from pending syncs */
hash_seq_init(&scan, pendingSyncHash);
while ((sync = (PendingRelSync *) hash_seq_search(&scan)))
(void) hash_search(tmphash, &sync->rnode, HASH_ENTER, NULL);
(void) hash_search(tmphash, &sync->rlocator, HASH_ENTER, NULL);
/* remove deleted rnodes */
for (delete = pendingDeletes; delete != NULL; delete = delete->next)
if (delete->atCommit)
(void) hash_search(tmphash, (void *) &delete->relnode,
(void) hash_search(tmphash, (void *) &delete->rlocator,
HASH_REMOVE, NULL);
hash_seq_init(&scan, tmphash);
while ((src = (RelFileNode *) hash_seq_search(&scan)))
while ((src = (RelFileLocator *) hash_seq_search(&scan)))
*dest++ = *src;
hash_destroy(tmphash);
terminate:
MemSet(dest, 0, sizeof(RelFileNode));
MemSet(dest, 0, sizeof(RelFileLocator));
}
/*
* RestorePendingSyncs
* Restore syncs within a parallel worker.
*
* RelationNeedsWAL() and RelFileNodeSkippingWAL() must offer the correct
* RelationNeedsWAL() and RelFileLocatorSkippingWAL() must offer the correct
* answer to parallel workers. Only smgrDoPendingSyncs() reads the
* is_truncated field, at end of transaction. Hence, don't restore it.
*/
void
RestorePendingSyncs(char *startAddress)
{
RelFileNode *rnode;
RelFileLocator *rlocator;
Assert(pendingSyncHash == NULL);
for (rnode = (RelFileNode *) startAddress; rnode->relNode != 0; rnode++)
AddPendingSync(rnode);
for (rlocator = (RelFileLocator *) startAddress; rlocator->relNumber != 0;
rlocator++)
AddPendingSync(rlocator);
}
/*
@@ -677,7 +678,7 @@ smgrDoPendingDeletes(bool isCommit)
{
SMgrRelation srel;
srel = smgropen(pending->relnode, pending->backend);
srel = smgropen(pending->rlocator, pending->backend);
/* allocate the initial array, or extend it, if needed */
if (maxrels == 0)
@@ -747,7 +748,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
/* Skip syncing nodes that smgrDoPendingDeletes() will delete. */
for (pending = pendingDeletes; pending != NULL; pending = pending->next)
if (pending->atCommit)
(void) hash_search(pendingSyncHash, (void *) &pending->relnode,
(void) hash_search(pendingSyncHash, (void *) &pending->rlocator,
HASH_REMOVE, NULL);
hash_seq_init(&scan, pendingSyncHash);
@@ -758,7 +759,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
BlockNumber total_blocks = 0;
SMgrRelation srel;
srel = smgropen(pendingsync->rnode, InvalidBackendId);
srel = smgropen(pendingsync->rlocator, InvalidBackendId);
/*
* We emit newpage WAL records for smaller relations.
@@ -832,7 +833,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
* page including any unused space. ReadBufferExtended()
* counts some pgstat events; unfortunately, we discard them.
*/
rel = CreateFakeRelcacheEntry(srel->smgr_rnode.node);
rel = CreateFakeRelcacheEntry(srel->smgr_rlocator.locator);
log_newpage_range(rel, fork, 0, n, false);
FreeFakeRelcacheEntry(rel);
}
@@ -852,7 +853,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
* smgrGetPendingDeletes() -- Get a list of non-temp relations to be deleted.
*
* The return value is the number of relations scheduled for termination.
* *ptr is set to point to a freshly-palloc'd array of RelFileNodes.
* *ptr is set to point to a freshly-palloc'd array of RelFileLocators.
* If there are no relations to be deleted, *ptr is set to NULL.
*
* Only non-temporary relations are included in the returned list. This is OK
@@ -866,11 +867,11 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
* by upper-level transactions.
*/
int
smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr)
smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr)
{
int nestLevel = GetCurrentTransactionNestLevel();
int nrels;
RelFileNode *rptr;
RelFileLocator *rptr;
PendingRelDelete *pending;
nrels = 0;
@@ -885,14 +886,14 @@ smgrGetPendingDeletes(bool forCommit, RelFileNode **ptr)
*ptr = NULL;
return 0;
}
rptr = (RelFileNode *) palloc(nrels * sizeof(RelFileNode));
rptr = (RelFileLocator *) palloc(nrels * sizeof(RelFileLocator));
*ptr = rptr;
for (pending = pendingDeletes; pending != NULL; pending = pending->next)
{
if (pending->nestLevel >= nestLevel && pending->atCommit == forCommit
&& pending->backend == InvalidBackendId)
{
*rptr = pending->relnode;
*rptr = pending->rlocator;
rptr++;
}
}
@@ -967,7 +968,7 @@ smgr_redo(XLogReaderState *record)
xl_smgr_create *xlrec = (xl_smgr_create *) XLogRecGetData(record);
SMgrRelation reln;
reln = smgropen(xlrec->rnode, InvalidBackendId);
reln = smgropen(xlrec->rlocator, InvalidBackendId);
smgrcreate(reln, xlrec->forkNum, true);
}
else if (info == XLOG_SMGR_TRUNCATE)
@@ -980,7 +981,7 @@ smgr_redo(XLogReaderState *record)
int nforks = 0;
bool need_fsm_vacuum = false;
reln = smgropen(xlrec->rnode, InvalidBackendId);
reln = smgropen(xlrec->rlocator, InvalidBackendId);
/*
* Forcibly create relation if it doesn't exist (which suggests that
@@ -1015,11 +1016,11 @@ smgr_redo(XLogReaderState *record)
nforks++;
/* Also tell xlogutils.c about it */
XLogTruncateRelation(xlrec->rnode, MAIN_FORKNUM, xlrec->blkno);
XLogTruncateRelation(xlrec->rlocator, MAIN_FORKNUM, xlrec->blkno);
}
/* Prepare for truncation of FSM and VM too */
rel = CreateFakeRelcacheEntry(xlrec->rnode);
rel = CreateFakeRelcacheEntry(xlrec->rlocator);
if ((xlrec->flags & SMGR_TRUNCATE_FSM) != 0 &&
smgrexists(reln, FSM_FORKNUM))