public inbox for [email protected]
help / color / mirror / Atom feedFrom: Heikki Linnakangas <[email protected]>
To: [email protected]
Subject: pgsql: Redefine backend ID to be an index into the proc array
Date: Sun, 03 Mar 2024 17:39:48 +0000
Message-ID: <[email protected]> (raw)
Redefine backend ID to be an index into the proc array
Previously, backend ID was an index into the ProcState array, in the
shared cache invalidation manager (sinvaladt.c). The entry in the
ProcState array was reserved at backend startup by scanning the array
for a free entry, and that was also when the backend got its backend
ID. Things become slightly simpler if we redefine backend ID to be the
index into the PGPROC array, and directly use it also as an index to
the ProcState array. This uses a little more memory, as we reserve a
few extra slots in the ProcState array for aux processes that don't
need them, but the simplicity is worth it.
Aux processes now also have a backend ID. This simplifies the
reservation of BackendStatusArray and ProcSignal slots.
You can now convert a backend ID into an index into the PGPROC array
simply by subtracting 1. We still use 0-based "pgprocnos" in various
places, for indexes into the PGPROC array, but the only difference now
is that backend IDs start at 1 while pgprocnos start at 0. (The next
commmit will get rid of the term "backend ID" altogether and make
everything 0-based.)
There is still a 'backendId' field in PGPROC, now part of 'vxid' which
encapsulates the backend ID and local transaction ID together. It's
needed for prepared xacts. For regular backends, the backendId is
always equal to pgprocno + 1, but for prepared xact PGPROC entries,
it's the ID of the original backend that processed the transaction.
Reviewed-by: Andres Freund, Reid Thompson
Discussion: https://www.postgresql.org/message-id/[email protected]
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ab355e3a88de745607f6dd4c21f0119b5c68f2ad
Modified Files
--------------
src/backend/access/transam/twophase.c | 37 ++---
src/backend/access/transam/xact.c | 12 +-
src/backend/catalog/namespace.c | 2 +-
src/backend/commands/sequence.c | 2 +-
src/backend/executor/functions.c | 4 +-
src/backend/postmaster/auxprocess.c | 12 +-
src/backend/storage/ipc/procarray.c | 73 +++++++++-
src/backend/storage/ipc/procsignal.c | 27 ++--
src/backend/storage/ipc/sinvaladt.c | 200 +++++++++-------------------
src/backend/storage/ipc/standby.c | 1 +
src/backend/storage/lmgr/lock.c | 28 ++--
src/backend/storage/lmgr/proc.c | 32 +++--
src/backend/utils/activity/backend_status.c | 52 +++-----
src/backend/utils/adt/lockfuncs.c | 2 +-
src/backend/utils/adt/mcxtfuncs.c | 14 +-
src/backend/utils/error/csvlog.c | 4 +-
src/backend/utils/error/elog.c | 6 +-
src/backend/utils/error/jsonlog.c | 6 +-
src/backend/utils/init/postinit.c | 10 +-
src/backend/utils/time/snapmgr.c | 5 +-
src/include/miscadmin.h | 2 -
src/include/storage/backendid.h | 12 +-
src/include/storage/lock.h | 9 +-
src/include/storage/proc.h | 32 ++++-
src/include/storage/procarray.h | 4 +
src/include/storage/procsignal.h | 2 +-
src/include/storage/sinvaladt.h | 4 -
src/pl/plpgsql/src/pl_exec.c | 10 +-
28 files changed, 282 insertions(+), 322 deletions(-)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: pgsql: Redefine backend ID to be an index into the proc array
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox