mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +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:
@ -816,7 +816,7 @@ ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum,
|
||||
* permanent = false for a RELPERSISTENCE_UNLOGGED relation. This function
|
||||
* cannot be used for temporary relations (and making that work might be
|
||||
* difficult, unless we only want to read temporary relations for our own
|
||||
* BackendId).
|
||||
* ProcNumber).
|
||||
*/
|
||||
Buffer
|
||||
ReadBufferWithoutRelcache(RelFileLocator rlocator, ForkNumber forkNum,
|
||||
@ -825,7 +825,7 @@ ReadBufferWithoutRelcache(RelFileLocator rlocator, ForkNumber forkNum,
|
||||
{
|
||||
bool hit;
|
||||
|
||||
SMgrRelation smgr = smgropen(rlocator, InvalidBackendId);
|
||||
SMgrRelation smgr = smgropen(rlocator, INVALID_PROC_NUMBER);
|
||||
|
||||
return ReadBuffer_common(smgr, permanent ? RELPERSISTENCE_PERMANENT :
|
||||
RELPERSISTENCE_UNLOGGED, forkNum, blockNum,
|
||||
@ -3322,7 +3322,7 @@ DebugPrintBufferRefcount(Buffer buffer)
|
||||
int32 loccount;
|
||||
char *path;
|
||||
char *result;
|
||||
BackendId backend;
|
||||
ProcNumber backend;
|
||||
uint32 buf_state;
|
||||
|
||||
Assert(BufferIsValid(buffer));
|
||||
@ -3330,13 +3330,13 @@ DebugPrintBufferRefcount(Buffer buffer)
|
||||
{
|
||||
buf = GetLocalBufferDescriptor(-buffer - 1);
|
||||
loccount = LocalRefCount[-buffer - 1];
|
||||
backend = MyBackendId;
|
||||
backend = MyProcNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = GetBufferDescriptor(buffer - 1);
|
||||
loccount = GetPrivateRefCount(buffer);
|
||||
backend = InvalidBackendId;
|
||||
backend = INVALID_PROC_NUMBER;
|
||||
}
|
||||
|
||||
/* theoretically we should lock the bufhdr here */
|
||||
@ -3461,7 +3461,7 @@ FlushBuffer(BufferDesc *buf, SMgrRelation reln, IOObject io_object,
|
||||
|
||||
/* Find smgr relation for buffer */
|
||||
if (reln == NULL)
|
||||
reln = smgropen(BufTagGetRelFileLocator(&buf->tag), InvalidBackendId);
|
||||
reln = smgropen(BufTagGetRelFileLocator(&buf->tag), INVALID_PROC_NUMBER);
|
||||
|
||||
TRACE_POSTGRESQL_BUFFER_FLUSH_START(BufTagGetForkNum(&buf->tag),
|
||||
buf->tag.blockNum,
|
||||
@ -3696,7 +3696,7 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
|
||||
/* If it's a local relation, it's localbuf.c's problem. */
|
||||
if (RelFileLocatorBackendIsTemp(rlocator))
|
||||
{
|
||||
if (rlocator.backend == MyBackendId)
|
||||
if (rlocator.backend == MyProcNumber)
|
||||
{
|
||||
for (j = 0; j < nforks; j++)
|
||||
DropRelationLocalBuffers(rlocator.locator, forkNum[j],
|
||||
@ -3826,7 +3826,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
|
||||
{
|
||||
if (RelFileLocatorBackendIsTemp(smgr_reln[i]->smgr_rlocator))
|
||||
{
|
||||
if (smgr_reln[i]->smgr_rlocator.backend == MyBackendId)
|
||||
if (smgr_reln[i]->smgr_rlocator.backend == MyProcNumber)
|
||||
DropRelationAllLocalBuffers(smgr_reln[i]->smgr_rlocator.locator);
|
||||
}
|
||||
else
|
||||
@ -4090,7 +4090,7 @@ PrintBufferDescs(void)
|
||||
"blockNum=%u, flags=0x%x, refcount=%u %d)",
|
||||
i, buf->freeNext,
|
||||
relpathbackend(BufTagGetRelFileLocator(&buf->tag),
|
||||
InvalidBackendId, BufTagGetForkNum(&buf->tag)),
|
||||
INVALID_PROC_NUMBER, BufTagGetForkNum(&buf->tag)),
|
||||
buf->tag.blockNum, buf->flags,
|
||||
buf->refcount, GetPrivateRefCount(b));
|
||||
}
|
||||
@ -4364,7 +4364,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
|
||||
use_wal = XLogIsNeeded() && (permanent || forkNum == INIT_FORKNUM);
|
||||
|
||||
/* Get number of blocks in the source relation. */
|
||||
nblocks = smgrnblocks(smgropen(srclocator, InvalidBackendId),
|
||||
nblocks = smgrnblocks(smgropen(srclocator, INVALID_PROC_NUMBER),
|
||||
forkNum);
|
||||
|
||||
/* Nothing to copy; just return. */
|
||||
@ -4376,7 +4376,7 @@ RelationCopyStorageUsingBuffer(RelFileLocator srclocator,
|
||||
* relation before starting to copy block by block.
|
||||
*/
|
||||
memset(buf.data, 0, BLCKSZ);
|
||||
smgrextend(smgropen(dstlocator, InvalidBackendId), forkNum, nblocks - 1,
|
||||
smgrextend(smgropen(dstlocator, INVALID_PROC_NUMBER), forkNum, nblocks - 1,
|
||||
buf.data, true);
|
||||
|
||||
/* This is a bulk operation, so use buffer access strategies. */
|
||||
@ -4443,8 +4443,8 @@ CreateAndCopyRelationData(RelFileLocator src_rlocator,
|
||||
relpersistence = permanent ?
|
||||
RELPERSISTENCE_PERMANENT : RELPERSISTENCE_UNLOGGED;
|
||||
|
||||
src_rel = smgropen(src_rlocator, InvalidBackendId);
|
||||
dst_rel = smgropen(dst_rlocator, InvalidBackendId);
|
||||
src_rel = smgropen(src_rlocator, INVALID_PROC_NUMBER);
|
||||
dst_rel = smgropen(dst_rlocator, INVALID_PROC_NUMBER);
|
||||
|
||||
/*
|
||||
* Create and copy all forks of the relation. During create database we
|
||||
@ -5348,7 +5348,7 @@ local_buffer_write_error_callback(void *arg)
|
||||
if (bufHdr != NULL)
|
||||
{
|
||||
char *path = relpathbackend(BufTagGetRelFileLocator(&bufHdr->tag),
|
||||
MyBackendId,
|
||||
MyProcNumber,
|
||||
BufTagGetForkNum(&bufHdr->tag));
|
||||
|
||||
errcontext("writing block %u of relation %s",
|
||||
@ -5653,7 +5653,7 @@ IssuePendingWritebacks(WritebackContext *wb_context, IOContext io_context)
|
||||
i += ahead;
|
||||
|
||||
/* and finally tell the kernel to write the data to storage */
|
||||
reln = smgropen(currlocator, InvalidBackendId);
|
||||
reln = smgropen(currlocator, INVALID_PROC_NUMBER);
|
||||
smgrwriteback(reln, BufTagGetForkNum(&tag), tag.blockNum, nblocks);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user