1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +03:00

Replace BackendIds with 0-based ProcNumbers

Now that BackendId was just another index into the proc array, it was
redundant with the 0-based proc numbers used in other places. Replace
all usage of backend IDs with proc numbers.

The only place where the term "backend id" remains is in a few pgstat
functions that expose backend IDs at the SQL level. Those IDs are now
in fact 0-based ProcNumbers too, but the documentation still calls
them "backend ids". That term still seems appropriate to describe what
the numbers are, so I let it be.

One user-visible effect is that pg_temp_0 is now a valid temp schema
name, for backend with ProcNumber 0.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
This commit is contained in:
Heikki Linnakangas
2024-03-03 19:38:22 +02:00
parent ab355e3a88
commit 024c521117
71 changed files with 571 additions and 579 deletions

View File

@@ -61,7 +61,7 @@ int wal_skip_threshold = 2048; /* in kilobytes */
typedef struct PendingRelDelete
{
RelFileLocator rlocator; /* relation that may need to be deleted */
BackendId backend; /* InvalidBackendId if not a temp rel */
ProcNumber procNumber; /* INVALID_PROC_NUMBER if not a temp rel */
bool atCommit; /* T=delete at commit; F=delete at abort */
int nestLevel; /* xact nesting level of request */
struct PendingRelDelete *next; /* linked-list link */
@@ -122,7 +122,7 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
bool register_delete)
{
SMgrRelation srel;
BackendId backend;
ProcNumber procNumber;
bool needs_wal;
Assert(!IsInParallelMode()); /* couldn't update pendingSyncHash */
@@ -130,15 +130,15 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
switch (relpersistence)
{
case RELPERSISTENCE_TEMP:
backend = BackendIdForTempRelations();
procNumber = ProcNumberForTempRelations();
needs_wal = false;
break;
case RELPERSISTENCE_UNLOGGED:
backend = InvalidBackendId;
procNumber = INVALID_PROC_NUMBER;
needs_wal = false;
break;
case RELPERSISTENCE_PERMANENT:
backend = InvalidBackendId;
procNumber = INVALID_PROC_NUMBER;
needs_wal = true;
break;
default:
@@ -146,7 +146,7 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
return NULL; /* placate compiler */
}
srel = smgropen(rlocator, backend);
srel = smgropen(rlocator, procNumber);
smgrcreate(srel, MAIN_FORKNUM, false);
if (needs_wal)
@@ -163,7 +163,7 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
pending->rlocator = rlocator;
pending->backend = backend;
pending->procNumber = procNumber;
pending->atCommit = false; /* delete if abort */
pending->nestLevel = GetCurrentTransactionNestLevel();
pending->next = pendingDeletes;
@@ -172,7 +172,7 @@ RelationCreateStorage(RelFileLocator rlocator, char relpersistence,
if (relpersistence == RELPERSISTENCE_PERMANENT && !XLogIsNeeded())
{
Assert(backend == InvalidBackendId);
Assert(procNumber == INVALID_PROC_NUMBER);
AddPendingSync(&rlocator);
}
@@ -211,7 +211,7 @@ RelationDropStorage(Relation rel)
pending = (PendingRelDelete *)
MemoryContextAlloc(TopMemoryContext, sizeof(PendingRelDelete));
pending->rlocator = rel->rd_locator;
pending->backend = rel->rd_backend;
pending->procNumber = rel->rd_backend;
pending->atCommit = true; /* delete if commit */
pending->nestLevel = GetCurrentTransactionNestLevel();
pending->next = pendingDeletes;
@@ -660,7 +660,7 @@ smgrDoPendingDeletes(bool isCommit)
{
SMgrRelation srel;
srel = smgropen(pending->rlocator, pending->backend);
srel = smgropen(pending->rlocator, pending->procNumber);
/* allocate the initial array, or extend it, if needed */
if (maxrels == 0)
@@ -741,7 +741,7 @@ smgrDoPendingSyncs(bool isCommit, bool isParallelWorker)
BlockNumber total_blocks = 0;
SMgrRelation srel;
srel = smgropen(pendingsync->rlocator, InvalidBackendId);
srel = smgropen(pendingsync->rlocator, INVALID_PROC_NUMBER);
/*
* We emit newpage WAL records for smaller relations.
@@ -860,7 +860,7 @@ smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr)
for (pending = pendingDeletes; pending != NULL; pending = pending->next)
{
if (pending->nestLevel >= nestLevel && pending->atCommit == forCommit
&& pending->backend == InvalidBackendId)
&& pending->procNumber == INVALID_PROC_NUMBER)
nrels++;
}
if (nrels == 0)
@@ -873,7 +873,7 @@ smgrGetPendingDeletes(bool forCommit, RelFileLocator **ptr)
for (pending = pendingDeletes; pending != NULL; pending = pending->next)
{
if (pending->nestLevel >= nestLevel && pending->atCommit == forCommit
&& pending->backend == InvalidBackendId)
&& pending->procNumber == INVALID_PROC_NUMBER)
{
*rptr = pending->rlocator;
rptr++;
@@ -950,7 +950,7 @@ smgr_redo(XLogReaderState *record)
xl_smgr_create *xlrec = (xl_smgr_create *) XLogRecGetData(record);
SMgrRelation reln;
reln = smgropen(xlrec->rlocator, InvalidBackendId);
reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
smgrcreate(reln, xlrec->forkNum, true);
}
else if (info == XLOG_SMGR_TRUNCATE)
@@ -963,7 +963,7 @@ smgr_redo(XLogReaderState *record)
int nforks = 0;
bool need_fsm_vacuum = false;
reln = smgropen(xlrec->rlocator, InvalidBackendId);
reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
/*
* Forcibly create relation if it doesn't exist (which suggests that