Replace BackendIds with 0-based ProcNumbers
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sun, 3 Mar 2024 17:38:22 +0000 (19:38 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sun, 3 Mar 2024 17:38:22 +0000 (19:38 +0200)
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

71 files changed:
doc/src/sgml/config.sgml
doc/src/sgml/monitoring.sgml
doc/src/sgml/storage.sgml
doc/src/sgml/xact.sgml
src/backend/access/transam/README
src/backend/access/transam/clog.c
src/backend/access/transam/multixact.c
src/backend/access/transam/parallel.c
src/backend/access/transam/twophase.c
src/backend/access/transam/xact.c
src/backend/access/transam/xlogprefetcher.c
src/backend/access/transam/xlogutils.c
src/backend/backup/basebackup_incremental.c
src/backend/catalog/catalog.c
src/backend/catalog/namespace.c
src/backend/catalog/storage.c
src/backend/commands/async.c
src/backend/commands/dbcommands.c
src/backend/commands/indexcmds.c
src/backend/commands/sequence.c
src/backend/libpq/pqmq.c
src/backend/postmaster/pgarch.c
src/backend/postmaster/walsummarizer.c
src/backend/replication/logical/applyparallelworker.c
src/backend/replication/slot.c
src/backend/replication/walsender.c
src/backend/storage/buffer/buf_init.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/localbuf.c
src/backend/storage/ipc/procarray.c
src/backend/storage/ipc/procsignal.c
src/backend/storage/ipc/sinvaladt.c
src/backend/storage/ipc/standby.c
src/backend/storage/lmgr/lmgr.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/predicate.c
src/backend/storage/lmgr/proc.c
src/backend/storage/smgr/md.c
src/backend/storage/smgr/smgr.c
src/backend/utils/activity/backend_status.c
src/backend/utils/adt/dbsize.c
src/backend/utils/adt/lockfuncs.c
src/backend/utils/adt/mcxtfuncs.c
src/backend/utils/adt/pgstatfuncs.c
src/backend/utils/cache/inval.c
src/backend/utils/cache/relcache.c
src/backend/utils/error/csvlog.c
src/backend/utils/error/elog.c
src/backend/utils/error/jsonlog.c
src/backend/utils/init/globals.c
src/backend/utils/time/snapmgr.c
src/common/relpath.c
src/include/access/twophase.h
src/include/catalog/namespace.h
src/include/common/relpath.h
src/include/libpq/pqmq.h
src/include/miscadmin.h
src/include/postmaster/postmaster.h
src/include/storage/backendid.h [deleted file]
src/include/storage/lock.h
src/include/storage/proc.h
src/include/storage/procarray.h
src/include/storage/proclist.h
src/include/storage/proclist_types.h
src/include/storage/procnumber.h [new file with mode: 0644]
src/include/storage/procsignal.h
src/include/storage/relfilelocator.h
src/include/storage/sinval.h
src/include/storage/smgr.h
src/include/utils/backend_status.h
src/include/utils/rel.h

index 43b1a132a2c866b67c2e0059b7b48023bc7f006c..b38cbd714aad3aac51810ad97f3afd3048b2c487 100644 (file)
@@ -7495,7 +7495,7 @@ local0.*    /var/log/postgresql
             </row>
             <row>
              <entry><literal>%v</literal></entry>
-             <entry>Virtual transaction ID (backendID/localXID);  see
+             <entry>Virtual transaction ID (procNumber/localXID);  see
              <xref linkend="transaction-id"/></entry>
              <entry>no</entry>
             </row>
index 4b8b38b70ef0b6e8d51c790ddaf898f354c88c9f..8aca08140ea79017d2d2c3c601d1dbbb14350db1 100644 (file)
@@ -4940,7 +4940,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage
    access functions can be used; these are shown in <xref
    linkend="monitoring-stats-backend-funcs-table"/>.
    These access functions use the session's backend ID number, which is a
-   small positive integer that is distinct from the backend ID of any
+   small integer (>= 0) that is distinct from the backend ID of any
    concurrent session, although a session's ID can be recycled as soon as
    it exits.  The backend ID is used, among other things, to identify the
    session's temporary schema if it has one.
@@ -6813,7 +6813,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
        arg0 contains the fork to be extended. arg1, arg2, and arg3 contain the
        tablespace, database, and relation OIDs identifying the relation.  arg4
        is the ID of the backend which created the temporary relation for a
-       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared
+       local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared
        buffer. arg5 is the number of blocks the caller would like to extend
        by.</entry>
     </row>
@@ -6824,7 +6824,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
        arg0 contains the fork to be extended. arg1, arg2, and arg3 contain the
        tablespace, database, and relation OIDs identifying the relation.  arg4
        is the ID of the backend which created the temporary relation for a
-       local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared
+       local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared
        buffer. arg5 is the number of blocks the relation was extended by, this
        can be less than the number in the
        <literal>buffer-extend-start</literal> due to resource
@@ -6839,7 +6839,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
       identifying the relation.
       arg5 is the ID of the backend which created the temporary relation for a
-      local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
+      local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared buffer.
       </entry>
     </row>
     <row>
@@ -6850,7 +6850,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
       identifying the relation.
       arg5 is the ID of the backend which created the temporary relation for a
-      local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
+      local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared buffer.
       arg6 is true if the buffer was found in the pool, false if not.</entry>
     </row>
     <row>
@@ -6903,7 +6903,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
       identifying the relation.
       arg5 is the ID of the backend which created the temporary relation for a
-      local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
+      local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared buffer.</entry>
     </row>
     <row>
      <entry><literal>smgr-md-read-done</literal></entry>
@@ -6913,7 +6913,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
       identifying the relation.
       arg5 is the ID of the backend which created the temporary relation for a
-      local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
+      local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared buffer.
       arg6 is the number of bytes actually read, while arg7 is the number
       requested (if these are different it indicates a short read).</entry>
     </row>
@@ -6925,7 +6925,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
       identifying the relation.
       arg5 is the ID of the backend which created the temporary relation for a
-      local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.</entry>
+      local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared buffer.</entry>
     </row>
     <row>
      <entry><literal>smgr-md-write-done</literal></entry>
@@ -6935,7 +6935,7 @@ FROM pg_stat_get_backend_idset() AS backendid;
       arg2, arg3, and arg4 contain the tablespace, database, and relation OIDs
       identifying the relation.
       arg5 is the ID of the backend which created the temporary relation for a
-      local buffer, or <symbol>InvalidBackendId</symbol> (-1) for a shared buffer.
+      local buffer, or <symbol>INVALID_PROC_NUMBER</symbol> (-1) for a shared buffer.
       arg6 is the number of bytes actually written, while arg7 is the number
       requested (if these are different it indicates a short write).</entry>
     </row>
index 3ea4e5526df5a054360345dc08ba4ee0072aaaab..652946db7d78af5d3c1052cc736db8997c214ae4 100644 (file)
@@ -202,7 +202,7 @@ these files are named after the table or index's <firstterm>filenode</firstterm>
 which can be found in <structname>pg_class</structname>.<structfield>relfilenode</structfield>. But
 for temporary relations, the file name is of the form
 <literal>t<replaceable>BBB</replaceable>_<replaceable>FFF</replaceable></literal>, where <replaceable>BBB</replaceable>
-is the backend ID of the backend which created the file, and <replaceable>FFF</replaceable>
+is the process number of the backend which created the file, and <replaceable>FFF</replaceable>
 is the filenode number.  In either case, in addition to the main file (a/k/a
 main fork), each table and index has a <firstterm>free space map</firstterm> (see <xref
 linkend="storage-fsm"/>), which stores information about free space available in
index 07b94b11329c07bbea46e3792903bda6a8eb9d4b..3aa7ee1383e424095026cbb85d319cc2e2157550 100644 (file)
    Every transaction is identified by a unique
    <literal>VirtualTransactionId</literal> (also called
    <literal>virtualXID</literal> or <literal>vxid</literal>), which
-   is comprised of a backend ID (or <literal>backendID</literal>)
+   is comprised of a backend's process number (or <literal>procNumber</literal>)
    and a sequentially-assigned number local to each backend, known as
    <literal>localXID</literal>.  For example, the virtual transaction
-   ID <literal>4/12532</literal> has a <literal>backendID</literal>
+   ID <literal>4/12532</literal> has a <literal>procNumber</literal>
    of <literal>4</literal> and a <literal>localXID</literal> of
    <literal>12532</literal>.
   </para>
index 6de2378748a70dfaeb6d9cb6ae712b00abfa5aa5..28d196cf62b33baa08b88004548d09d197aa9f47 100644 (file)
@@ -203,12 +203,12 @@ pg_subtrans and PGPROC are done at the time it is assigned.
 A transaction that has no XID still needs to be identified for various
 purposes, notably holding locks.  For this purpose we assign a "virtual
 transaction ID" or VXID to each top-level transaction.  VXIDs are formed from
-two fields, the backendID and a backend-local counter; this arrangement allows
-assignment of a new VXID at transaction start without any contention for
-shared memory.  To ensure that a VXID isn't re-used too soon after backend
+two fields, the procNumber and a backend-local counter; this arrangement
+allows assignment of a new VXID at transaction start without any contention
+for shared memory.  To ensure that a VXID isn't re-used too soon after backend
 exit, we store the last local counter value into shared memory at backend
-exit, and initialize it from the previous value for the same backendID slot
-at backend start.  All these counters go back to zero at shared memory
+exit, and initialize it from the previous value for the same PGPROC slot at
+backend start.  All these counters go back to zero at shared memory
 re-initialization, but that's OK because VXIDs never appear anywhere on-disk.
 
 Internally, a backend needs a way to identify subtransactions whether or not
index a787b374dac00e4e17586f66f28b82993e8bd302..44c253246b9c452fc4bba4b9db65b6ec525fc242 100644 (file)
@@ -501,7 +501,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
                 * still work, just less efficiently -- we handle this case by
                 * switching to a different bank lock in the loop below.
                 */
-               if (nextidx != INVALID_PGPROCNO &&
+               if (nextidx != INVALID_PROC_NUMBER &&
                        GetPGProcByNumber(nextidx)->clogGroupMemberPage != proc->clogGroupMemberPage)
                {
                        /*
@@ -509,7 +509,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
                         * needs an XID status update.
                         */
                        proc->clogGroupMember = false;
-                       pg_atomic_write_u32(&proc->clogGroupNext, INVALID_PGPROCNO);
+                       pg_atomic_write_u32(&proc->clogGroupNext, INVALID_PROC_NUMBER);
                        return false;
                }
 
@@ -525,9 +525,9 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
         * If the list was not empty, the leader will update the status of our
         * XID. It is impossible to have followers without a leader because the
         * first process that has added itself to the list will always have
-        * nextidx as INVALID_PGPROCNO.
+        * nextidx as INVALID_PROC_NUMBER.
         */
-       if (nextidx != INVALID_PGPROCNO)
+       if (nextidx != INVALID_PROC_NUMBER)
        {
                int                     extraWaits = 0;
 
@@ -543,7 +543,7 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
                }
                pgstat_report_wait_end();
 
-               Assert(pg_atomic_read_u32(&proc->clogGroupNext) == INVALID_PGPROCNO);
+               Assert(pg_atomic_read_u32(&proc->clogGroupNext) == INVALID_PROC_NUMBER);
 
                /* Fix semaphore count for any absorbed wakeups */
                while (extraWaits-- > 0)
@@ -568,13 +568,13 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
         * group.
         */
        nextidx = pg_atomic_exchange_u32(&procglobal->clogGroupFirst,
-                                                                        INVALID_PGPROCNO);
+                                                                        INVALID_PROC_NUMBER);
 
        /* Remember head of list so we can perform wakeups after dropping lock. */
        wakeidx = nextidx;
 
        /* Walk the list and update the status of all XIDs. */
-       while (nextidx != INVALID_PGPROCNO)
+       while (nextidx != INVALID_PROC_NUMBER)
        {
                PGPROC     *nextproc = &ProcGlobal->allProcs[nextidx];
                int                     thispageno = nextproc->clogGroupMemberPage;
@@ -633,12 +633,12 @@ TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status,
         * clogGroupNext to invalid while saving the semaphores to an array, then
         * a single write barrier, then another pass unlocking the semaphores.)
         */
-       while (wakeidx != INVALID_PGPROCNO)
+       while (wakeidx != INVALID_PROC_NUMBER)
        {
                PGPROC     *wakeproc = &ProcGlobal->allProcs[wakeidx];
 
                wakeidx = pg_atomic_read_u32(&wakeproc->clogGroupNext);
-               pg_atomic_write_u32(&wakeproc->clogGroupNext, INVALID_PGPROCNO);
+               pg_atomic_write_u32(&wakeproc->clogGroupNext, INVALID_PROC_NUMBER);
 
                /* ensure all previous writes are visible before follower continues. */
                pg_write_barrier();
index 9b815061452fb4654908289fd38e25f701429db4..9dc7aa9c2f47d4591cbed5fdbe21971a8863fbba 100644 (file)
@@ -237,11 +237,11 @@ typedef struct MultiXactStateData
        /*
         * Per-backend data starts here.  We have two arrays stored in the area
         * immediately following the MultiXactStateData struct. Each is indexed by
-        * BackendId.
+        * ProcNumber.
         *
-        * In both arrays, there's a slot for all normal backends (1..MaxBackends)
-        * followed by a slot for max_prepared_xacts prepared transactions. Valid
-        * BackendIds start from 1; element zero of each array is never used.
+        * In both arrays, there's a slot for all normal backends
+        * (0..MaxBackends-1) followed by a slot for max_prepared_xacts prepared
+        * transactions.
         *
         * OldestMemberMXactId[k] is the oldest MultiXactId each backend's current
         * transaction(s) could possibly be a member of, or InvalidMultiXactId
@@ -285,8 +285,7 @@ typedef struct MultiXactStateData
 } MultiXactStateData;
 
 /*
- * Last element of OldestMemberMXactId and OldestVisibleMXactId arrays.
- * Valid elements are (1..MaxOldestSlot); element 0 is never used.
+ * Size of OldestMemberMXactId and OldestVisibleMXactId arrays.
  */
 #define MaxOldestSlot  (MaxBackends + max_prepared_xacts)
 
@@ -397,7 +396,7 @@ MultiXactIdCreate(TransactionId xid1, MultiXactStatus status1,
        Assert(!TransactionIdEquals(xid1, xid2) || (status1 != status2));
 
        /* MultiXactIdSetOldestMember() must have been called already. */
-       Assert(MultiXactIdIsValid(OldestMemberMXactId[MyBackendId]));
+       Assert(MultiXactIdIsValid(OldestMemberMXactId[MyProcNumber]));
 
        /*
         * Note: unlike MultiXactIdExpand, we don't bother to check that both XIDs
@@ -451,7 +450,7 @@ MultiXactIdExpand(MultiXactId multi, TransactionId xid, MultiXactStatus status)
        Assert(TransactionIdIsValid(xid));
 
        /* MultiXactIdSetOldestMember() must have been called already. */
-       Assert(MultiXactIdIsValid(OldestMemberMXactId[MyBackendId]));
+       Assert(MultiXactIdIsValid(OldestMemberMXactId[MyProcNumber]));
 
        debug_elog5(DEBUG2, "Expand: received multi %u, xid %u status %s",
                                multi, xid, mxstatus_to_string(status));
@@ -626,7 +625,7 @@ MultiXactIdIsRunning(MultiXactId multi, bool isLockOnly)
 void
 MultiXactIdSetOldestMember(void)
 {
-       if (!MultiXactIdIsValid(OldestMemberMXactId[MyBackendId]))
+       if (!MultiXactIdIsValid(OldestMemberMXactId[MyProcNumber]))
        {
                MultiXactId nextMXact;
 
@@ -655,12 +654,12 @@ MultiXactIdSetOldestMember(void)
                if (nextMXact < FirstMultiXactId)
                        nextMXact = FirstMultiXactId;
 
-               OldestMemberMXactId[MyBackendId] = nextMXact;
+               OldestMemberMXactId[MyProcNumber] = nextMXact;
 
                LWLockRelease(MultiXactGenLock);
 
                debug_elog4(DEBUG2, "MultiXact: setting OldestMember[%d] = %u",
-                                       MyBackendId, nextMXact);
+                                       MyProcNumber, nextMXact);
        }
 }
 
@@ -683,7 +682,7 @@ MultiXactIdSetOldestMember(void)
 static void
 MultiXactIdSetOldestVisible(void)
 {
-       if (!MultiXactIdIsValid(OldestVisibleMXactId[MyBackendId]))
+       if (!MultiXactIdIsValid(OldestVisibleMXactId[MyProcNumber]))
        {
                MultiXactId oldestMXact;
                int                     i;
@@ -699,7 +698,7 @@ MultiXactIdSetOldestVisible(void)
                if (oldestMXact < FirstMultiXactId)
                        oldestMXact = FirstMultiXactId;
 
-               for (i = 1; i <= MaxOldestSlot; i++)
+               for (i = 0; i < MaxOldestSlot; i++)
                {
                        MultiXactId thisoldest = OldestMemberMXactId[i];
 
@@ -708,12 +707,12 @@ MultiXactIdSetOldestVisible(void)
                                oldestMXact = thisoldest;
                }
 
-               OldestVisibleMXactId[MyBackendId] = oldestMXact;
+               OldestVisibleMXactId[MyProcNumber] = oldestMXact;
 
                LWLockRelease(MultiXactGenLock);
 
                debug_elog4(DEBUG2, "MultiXact: setting OldestVisible[%d] = %u",
-                                       MyBackendId, oldestMXact);
+                                       MyProcNumber, oldestMXact);
        }
 }
 
@@ -1285,7 +1284,7 @@ GetMultiXactIdMembers(MultiXactId multi, MultiXactMember **members,
         * multi.  It cannot possibly still be running.
         */
        if (isLockOnly &&
-               MultiXactIdPrecedes(multi, OldestVisibleMXactId[MyBackendId]))
+               MultiXactIdPrecedes(multi, OldestVisibleMXactId[MyProcNumber]))
        {
                debug_elog2(DEBUG2, "GetMembers: a locker-only multi is too old");
                *members = NULL;
@@ -1752,8 +1751,8 @@ AtEOXact_MultiXact(void)
         * We assume that storing a MultiXactId is atomic and so we need not take
         * MultiXactGenLock to do this.
         */
-       OldestMemberMXactId[MyBackendId] = InvalidMultiXactId;
-       OldestVisibleMXactId[MyBackendId] = InvalidMultiXactId;
+       OldestMemberMXactId[MyProcNumber] = InvalidMultiXactId;
+       OldestVisibleMXactId[MyProcNumber] = InvalidMultiXactId;
 
        /*
         * Discard the local MultiXactId cache.  Since MXactContext was created as
@@ -1773,7 +1772,7 @@ AtEOXact_MultiXact(void)
 void
 AtPrepare_MultiXact(void)
 {
-       MultiXactId myOldestMember = OldestMemberMXactId[MyBackendId];
+       MultiXactId myOldestMember = OldestMemberMXactId[MyProcNumber];
 
        if (MultiXactIdIsValid(myOldestMember))
                RegisterTwoPhaseRecord(TWOPHASE_RM_MULTIXACT_ID, 0,
@@ -1793,10 +1792,10 @@ PostPrepare_MultiXact(TransactionId xid)
         * Transfer our OldestMemberMXactId value to the slot reserved for the
         * prepared transaction.
         */
-       myOldestMember = OldestMemberMXactId[MyBackendId];
+       myOldestMember = OldestMemberMXactId[MyProcNumber];
        if (MultiXactIdIsValid(myOldestMember))
        {
-               BackendId       dummyBackendId = TwoPhaseGetDummyBackendId(xid, false);
+               ProcNumber      dummyProcNumber = TwoPhaseGetDummyProcNumber(xid, false);
 
                /*
                 * Even though storing MultiXactId is atomic, acquire lock to make
@@ -1806,8 +1805,8 @@ PostPrepare_MultiXact(TransactionId xid)
                 */
                LWLockAcquire(MultiXactGenLock, LW_EXCLUSIVE);
 
-               OldestMemberMXactId[dummyBackendId] = myOldestMember;
-               OldestMemberMXactId[MyBackendId] = InvalidMultiXactId;
+               OldestMemberMXactId[dummyProcNumber] = myOldestMember;
+               OldestMemberMXactId[MyProcNumber] = InvalidMultiXactId;
 
                LWLockRelease(MultiXactGenLock);
        }
@@ -1820,7 +1819,7 @@ PostPrepare_MultiXact(TransactionId xid)
         * We assume that storing a MultiXactId is atomic and so we need not take
         * MultiXactGenLock to do this.
         */
-       OldestVisibleMXactId[MyBackendId] = InvalidMultiXactId;
+       OldestVisibleMXactId[MyProcNumber] = InvalidMultiXactId;
 
        /*
         * Discard the local MultiXactId cache like in AtEOXact_MultiXact.
@@ -1837,7 +1836,7 @@ void
 multixact_twophase_recover(TransactionId xid, uint16 info,
                                                   void *recdata, uint32 len)
 {
-       BackendId       dummyBackendId = TwoPhaseGetDummyBackendId(xid, false);
+       ProcNumber      dummyProcNumber = TwoPhaseGetDummyProcNumber(xid, false);
        MultiXactId oldestMember;
 
        /*
@@ -1847,7 +1846,7 @@ multixact_twophase_recover(TransactionId xid, uint16 info,
        Assert(len == sizeof(MultiXactId));
        oldestMember = *((MultiXactId *) recdata);
 
-       OldestMemberMXactId[dummyBackendId] = oldestMember;
+       OldestMemberMXactId[dummyProcNumber] = oldestMember;
 }
 
 /*
@@ -1858,11 +1857,11 @@ void
 multixact_twophase_postcommit(TransactionId xid, uint16 info,
                                                          void *recdata, uint32 len)
 {
-       BackendId       dummyBackendId = TwoPhaseGetDummyBackendId(xid, true);
+       ProcNumber      dummyProcNumber = TwoPhaseGetDummyProcNumber(xid, true);
 
        Assert(len == sizeof(MultiXactId));
 
-       OldestMemberMXactId[dummyBackendId] = InvalidMultiXactId;
+       OldestMemberMXactId[dummyProcNumber] = InvalidMultiXactId;
 }
 
 /*
@@ -1886,9 +1885,9 @@ MultiXactShmemSize(void)
 {
        Size            size;
 
-       /* We need 2*MaxOldestSlot + 1 perBackendXactIds[] entries */
+       /* We need 2*MaxOldestSlot perBackendXactIds[] entries */
 #define SHARED_MULTIXACT_STATE_SIZE \
-       add_size(offsetof(MultiXactStateData, perBackendXactIds) + sizeof(MultiXactId), \
+       add_size(offsetof(MultiXactStateData, perBackendXactIds), \
                         mul_size(sizeof(MultiXactId) * 2, MaxOldestSlot))
 
        size = SHARED_MULTIXACT_STATE_SIZE;
@@ -1938,8 +1937,7 @@ MultiXactShmemInit(void)
                Assert(found);
 
        /*
-        * Set up array pointers.  Note that perBackendXactIds[0] is wasted space
-        * since we only use indexes 1..MaxOldestSlot in each array.
+        * Set up array pointers.
         */
        OldestMemberMXactId = MultiXactState->perBackendXactIds;
        OldestVisibleMXactId = OldestMemberMXactId + MaxOldestSlot;
@@ -2617,7 +2615,7 @@ GetOldestMultiXactId(void)
                nextMXact = FirstMultiXactId;
 
        oldestMXact = nextMXact;
-       for (i = 1; i <= MaxOldestSlot; i++)
+       for (i = 0; i < MaxOldestSlot; i++)
        {
                MultiXactId thisoldest;
 
index 849a03e4b65300e43ba969bf97b47c3308fa107c..cbfe6087da44a4d595a072a3b3356fca92bd0bc5 100644 (file)
@@ -94,7 +94,7 @@ typedef struct FixedParallelState
        bool            is_superuser;
        PGPROC     *parallel_leader_pgproc;
        pid_t           parallel_leader_pid;
-       BackendId       parallel_leader_backend_id;
+       ProcNumber      parallel_leader_proc_number;
        TimestampTz xact_ts;
        TimestampTz stmt_ts;
        SerializableXactHandle serializable_xact_handle;
@@ -337,7 +337,7 @@ InitializeParallelDSM(ParallelContext *pcxt)
                                                  &fps->temp_toast_namespace_id);
        fps->parallel_leader_pgproc = MyProc;
        fps->parallel_leader_pid = MyProcPid;
-       fps->parallel_leader_backend_id = MyBackendId;
+       fps->parallel_leader_proc_number = MyProcNumber;
        fps->xact_ts = GetCurrentTransactionStartTimestamp();
        fps->stmt_ts = GetCurrentStatementStartTimestamp();
        fps->serializable_xact_handle = ShareSerializableXact();
@@ -1351,7 +1351,7 @@ ParallelWorkerMain(Datum main_arg)
 
        /* Arrange to signal the leader if we exit. */
        ParallelLeaderPid = fps->parallel_leader_pid;
-       ParallelLeaderBackendId = fps->parallel_leader_backend_id;
+       ParallelLeaderProcNumber = fps->parallel_leader_proc_number;
        before_shmem_exit(ParallelWorkerShutdown, PointerGetDatum(seg));
 
        /*
@@ -1367,7 +1367,7 @@ ParallelWorkerMain(Datum main_arg)
        mqh = shm_mq_attach(mq, seg, NULL);
        pq_redirect_to_shm_mq(seg, mqh);
        pq_set_parallel_leader(fps->parallel_leader_pid,
-                                                  fps->parallel_leader_backend_id);
+                                                  fps->parallel_leader_proc_number);
 
        /*
         * Send a BackendKeyData message to the process that initiated parallelism
@@ -1594,7 +1594,7 @@ ParallelWorkerShutdown(int code, Datum arg)
 {
        SendProcSignal(ParallelLeaderPid,
                                   PROCSIG_PARALLEL_MESSAGE,
-                                  ParallelLeaderBackendId);
+                                  ParallelLeaderProcNumber);
 
        dsm_detach((dsm_segment *) DatumGetPointer(arg));
 }
index 5c2820029000ea7162d588adffcbc92711f6514f..a42af2934377efaba7ab96a53382f71a218fa7c4 100644 (file)
@@ -132,7 +132,7 @@ int                 max_prepared_xacts = 0;
  *
  * 3. To begin COMMIT PREPARED or ROLLBACK PREPARED, check that the entry is
  * valid and not locked, then mark the entry as locked by storing my current
- * backend ID into locking_backend.  This prevents concurrent attempts to
+ * proc number into locking_backend.  This prevents concurrent attempts to
  * commit or rollback the same prepared xact.
  *
  * 4. On completion of COMMIT PREPARED or ROLLBACK PREPARED, remove the entry
@@ -165,7 +165,7 @@ typedef struct GlobalTransactionData
        TransactionId xid;                      /* The GXACT id */
 
        Oid                     owner;                  /* ID of user that executed the xact */
-       BackendId       locking_backend;        /* backend currently working on the xact */
+       ProcNumber      locking_backend;        /* backend currently working on the xact */
        bool            valid;                  /* true if PGPROC entry is in proc array */
        bool            ondisk;                 /* true if prepare state file is on disk */
        bool            inredo;                 /* true if entry was added via xlog_redo */
@@ -333,7 +333,7 @@ AtAbort_Twophase(void)
        if (!MyLockedGxact->valid)
                RemoveGXact(MyLockedGxact);
        else
-               MyLockedGxact->locking_backend = InvalidBackendId;
+               MyLockedGxact->locking_backend = INVALID_PROC_NUMBER;
        LWLockRelease(TwoPhaseStateLock);
 
        MyLockedGxact = NULL;
@@ -347,7 +347,7 @@ void
 PostPrepare_Twophase(void)
 {
        LWLockAcquire(TwoPhaseStateLock, LW_EXCLUSIVE);
-       MyLockedGxact->locking_backend = InvalidBackendId;
+       MyLockedGxact->locking_backend = INVALID_PROC_NUMBER;
        LWLockRelease(TwoPhaseStateLock);
 
        MyLockedGxact = NULL;
@@ -452,14 +452,14 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
        {
                /* clone VXID, for TwoPhaseGetXidByVirtualXID() to find */
                proc->vxid.lxid = MyProc->vxid.lxid;
-               proc->vxid.backendId = MyBackendId;
+               proc->vxid.procNumber = MyProcNumber;
        }
        else
        {
                Assert(AmStartupProcess() || !IsPostmasterEnvironment);
                /* GetLockConflicts() uses this to specify a wait on the XID */
                proc->vxid.lxid = xid;
-               proc->vxid.backendId = InvalidBackendId;
+               proc->vxid.procNumber = INVALID_PROC_NUMBER;
        }
        proc->xid = xid;
        Assert(proc->xmin == InvalidTransactionId);
@@ -484,7 +484,7 @@ MarkAsPreparingGuts(GlobalTransaction gxact, TransactionId xid, const char *gid,
        gxact->prepared_at = prepared_at;
        gxact->xid = xid;
        gxact->owner = owner;
-       gxact->locking_backend = MyBackendId;
+       gxact->locking_backend = MyProcNumber;
        gxact->valid = false;
        gxact->inredo = false;
        strcpy(gxact->gid, gid);
@@ -577,7 +577,7 @@ LockGXact(const char *gid, Oid user)
                        continue;
 
                /* Found it, but has someone else got it locked? */
-               if (gxact->locking_backend != InvalidBackendId)
+               if (gxact->locking_backend != INVALID_PROC_NUMBER)
                        ereport(ERROR,
                                        (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                                         errmsg("prepared transaction with identifier \"%s\" is busy",
@@ -602,7 +602,7 @@ LockGXact(const char *gid, Oid user)
                                         errhint("Connect to the database where the transaction was prepared to finish it.")));
 
                /* OK for me to lock it */
-               gxact->locking_backend = MyBackendId;
+               gxact->locking_backend = MyProcNumber;
                MyLockedGxact = gxact;
 
                LWLockRelease(TwoPhaseStateLock);
@@ -849,7 +849,7 @@ TwoPhaseGetGXact(TransactionId xid, bool lock_held)
  *
  * (This won't find recovered xacts.)  If more than one matches, return any
  * and set "have_more" to true.  To witness multiple matches, a single
- * BackendId must consume 2^32 LXIDs, with no intervening database restart.
+ * proc number must consume 2^32 LXIDs, with no intervening database restart.
  */
 TransactionId
 TwoPhaseGetXidByVirtualXID(VirtualTransactionId vxid,
@@ -873,7 +873,10 @@ TwoPhaseGetXidByVirtualXID(VirtualTransactionId vxid,
                GET_VXID_FROM_PGPROC(proc_vxid, *proc);
                if (VirtualTransactionIdEquals(vxid, proc_vxid))
                {
-                       /* Startup process sets proc->backendId to InvalidBackendId. */
+                       /*
+                        * Startup process sets proc->vxid.procNumber to
+                        * INVALID_PROC_NUMBER.
+                        */
                        Assert(!gxact->inredo);
 
                        if (result != InvalidTransactionId)
@@ -891,20 +894,20 @@ TwoPhaseGetXidByVirtualXID(VirtualTransactionId vxid,
 }
 
 /*
- * TwoPhaseGetDummyBackendId
- *             Get the dummy backend ID for prepared transaction specified by XID
+ * TwoPhaseGetDummyProcNumber
+ *             Get the dummy proc number for prepared transaction specified by XID
  *
- * Dummy backend IDs are similar to real backend IDs of real backends.
- * They start at MaxBackends + 1, and are unique across all currently active
- * real backends and prepared transactions.  If lock_held is set to true,
+ * Dummy proc numbers are similar to proc numbers of real backends.  They
+ * start at MaxBackends, and are unique across all currently active real
+ * backends and prepared transactions.  If lock_held is set to true,
  * TwoPhaseStateLock will not be taken, so the caller had better hold it.
  */
-BackendId
-TwoPhaseGetDummyBackendId(TransactionId xid, bool lock_held)
+ProcNumber
+TwoPhaseGetDummyProcNumber(TransactionId xid, bool lock_held)
 {
        GlobalTransaction gxact = TwoPhaseGetGXact(xid, lock_held);
 
-       return gxact->pgprocno + 1;
+       return gxact->pgprocno;
 }
 
 /*
@@ -2549,7 +2552,7 @@ PrepareRedoAdd(char *buf, XLogRecPtr start_lsn,
        gxact->prepare_end_lsn = end_lsn;
        gxact->xid = hdr->xid;
        gxact->owner = hdr->owner;
-       gxact->locking_backend = InvalidBackendId;
+       gxact->locking_backend = INVALID_PROC_NUMBER;
        gxact->valid = false;
        gxact->ondisk = XLogRecPtrIsInvalid(start_lsn);
        gxact->inredo = true;           /* yes, added in redo */
index 4ac5b9ea834e1efa1210870a908c0b46f6a186dc..e270007e28eba6132aed35af3b7f0ea5ede00fff 100644 (file)
@@ -2084,10 +2084,10 @@ StartTransaction(void)
        AtStart_ResourceOwner();
 
        /*
-        * Assign a new LocalTransactionId, and combine it with the backendId to
+        * Assign a new LocalTransactionId, and combine it with the proc number to
         * form a virtual transaction id.
         */
-       vxid.backendId = MyBackendId;
+       vxid.procNumber = MyProcNumber;
        vxid.localTransactionId = GetNextLocalTransactionId();
 
        /*
@@ -2097,9 +2097,10 @@ StartTransaction(void)
 
        /*
         * Advertise it in the proc array.  We assume assignment of
-        * localTransactionId is atomic, and the backendId should be set already.
+        * localTransactionId is atomic, and the proc number should be set
+        * already.
         */
-       Assert(MyProc->vxid.backendId == vxid.backendId);
+       Assert(MyProc->vxid.procNumber == vxid.procNumber);
        MyProc->vxid.lxid = vxid.localTransactionId;
 
        TRACE_POSTGRESQL_TRANSACTION_START(vxid.localTransactionId);
index 5885f5f643ad914b97752ef070a63036178e1a61..aa26ea2ef733b4d40edf88e552bae68626166e1e 100644 (file)
@@ -722,7 +722,7 @@ XLogPrefetcherNextBlock(uintptr_t pgsr_private, XLogRecPtr *lsn)
                         * same relation (with some scheme to handle invalidations
                         * safely), but for now we'll call smgropen() every time.
                         */
-                       reln = smgropen(block->rlocator, InvalidBackendId);
+                       reln = smgropen(block->rlocator, INVALID_PROC_NUMBER);
 
                        /*
                         * If the relation file doesn't exist on disk, for example because
index ad93035d508aa752f6c4262ee72c982629fc6a77..f65554eb8f790979e80eeae86beb4f3f01ae6446 100644 (file)
@@ -491,7 +491,7 @@ XLogReadBufferExtended(RelFileLocator rlocator, ForkNumber forknum,
        }
 
        /* Open the relation at smgr level */
-       smgr = smgropen(rlocator, InvalidBackendId);
+       smgr = smgropen(rlocator, INVALID_PROC_NUMBER);
 
        /*
         * Create the target file if it doesn't already exist.  This lets us cope
@@ -598,7 +598,7 @@ CreateFakeRelcacheEntry(RelFileLocator rlocator)
         * We will never be working with temp rels during recovery or while
         * syncing WAL-skipped files.
         */
-       rel->rd_backend = InvalidBackendId;
+       rel->rd_backend = INVALID_PROC_NUMBER;
 
        /* It must be a permanent table here */
        rel->rd_rel->relpersistence = RELPERSISTENCE_PERMANENT;
@@ -620,7 +620,7 @@ CreateFakeRelcacheEntry(RelFileLocator rlocator)
         * Set up a non-pinned SMgrRelation reference, so that we don't need to
         * worry about unpinning it on error.
         */
-       rel->rd_smgr = smgropen(rlocator, InvalidBackendId);
+       rel->rd_smgr = smgropen(rlocator, INVALID_PROC_NUMBER);
 
        return rel;
 }
index 99562d943231843e562d9946902afab3ca29bf76..0919b85b442f6e7f1369476b847bd4a990c2b017 100644 (file)
@@ -672,7 +672,7 @@ GetIncrementalFilePath(Oid dboid, Oid spcoid, RelFileNumber relfilenumber,
        char       *lastslash;
        char       *ipath;
 
-       path = GetRelationPath(dboid, spcoid, relfilenumber, InvalidBackendId,
+       path = GetRelationPath(dboid, spcoid, relfilenumber, INVALID_PROC_NUMBER,
                                                   forknum);
 
        lastslash = strrchr(path, '/');
index 1cf4e303ce6ea0c9853342844a11d14779be52e8..e151dddab29596b9f45e80bc5fcfbe283aa4b28c 100644 (file)
@@ -504,7 +504,7 @@ GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
        RelFileLocatorBackend rlocator;
        char       *rpath;
        bool            collides;
-       BackendId       backend;
+       ProcNumber      procNumber;
 
        /*
         * If we ever get here during pg_upgrade, there's something wrong; all
@@ -516,11 +516,11 @@ GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
        switch (relpersistence)
        {
                case RELPERSISTENCE_TEMP:
-                       backend = BackendIdForTempRelations();
+                       procNumber = ProcNumberForTempRelations();
                        break;
                case RELPERSISTENCE_UNLOGGED:
                case RELPERSISTENCE_PERMANENT:
-                       backend = InvalidBackendId;
+                       procNumber = INVALID_PROC_NUMBER;
                        break;
                default:
                        elog(ERROR, "invalid relpersistence: %c", relpersistence);
@@ -534,11 +534,11 @@ GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)
                InvalidOid : MyDatabaseId;
 
        /*
-        * The relpath will vary based on the backend ID, so we must initialize
-        * that properly here to make sure that any collisions based on filename
-        * are properly detected.
+        * The relpath will vary based on the backend number, so we must
+        * initialize that properly here to make sure that any collisions based on
+        * filename are properly detected.
         */
-       rlocator.backend = backend;
+       rlocator.backend = procNumber;
 
        do
        {
index 620ce7e75d29d4002f3ef88ff57802421de7b841..5521f5bd137c08c02994c95c0f1c55cc42f5663e 100644 (file)
@@ -3714,18 +3714,18 @@ TempNamespaceStatus
 checkTempNamespaceStatus(Oid namespaceId)
 {
        PGPROC     *proc;
-       int                     backendId;
+       ProcNumber      procNumber;
 
        Assert(OidIsValid(MyDatabaseId));
 
-       backendId = GetTempNamespaceBackendId(namespaceId);
+       procNumber = GetTempNamespaceProcNumber(namespaceId);
 
        /* No such namespace, or its name shows it's not temp? */
-       if (backendId == InvalidBackendId)
+       if (procNumber == INVALID_PROC_NUMBER)
                return TEMP_NAMESPACE_NOT_TEMP;
 
        /* Is the backend alive? */
-       proc = BackendIdGetProc(backendId);
+       proc = ProcNumberGetProc(procNumber);
        if (proc == NULL)
                return TEMP_NAMESPACE_IDLE;
 
@@ -3742,13 +3742,13 @@ checkTempNamespaceStatus(Oid namespaceId)
 }
 
 /*
- * GetTempNamespaceBackendId - if the given namespace is a temporary-table
- * namespace (either my own, or another backend's), return the BackendId
+ * GetTempNamespaceProcNumber - if the given namespace is a temporary-table
+ * namespace (either my own, or another backend's), return the proc number
  * that owns it.  Temporary-toast-table namespaces are included, too.
- * If it isn't a temp namespace, return InvalidBackendId.
+ * If it isn't a temp namespace, return INVALID_PROC_NUMBER.
  */
-int
-GetTempNamespaceBackendId(Oid namespaceId)
+ProcNumber
+GetTempNamespaceProcNumber(Oid namespaceId)
 {
        int                     result;
        char       *nspname;
@@ -3756,13 +3756,13 @@ GetTempNamespaceBackendId(Oid namespaceId)
        /* See if the namespace name starts with "pg_temp_" or "pg_toast_temp_" */
        nspname = get_namespace_name(namespaceId);
        if (!nspname)
-               return InvalidBackendId;        /* no such namespace? */
+               return INVALID_PROC_NUMBER; /* no such namespace? */
        if (strncmp(nspname, "pg_temp_", 8) == 0)
                result = atoi(nspname + 8);
        else if (strncmp(nspname, "pg_toast_temp_", 14) == 0)
                result = atoi(nspname + 14);
        else
-               result = InvalidBackendId;
+               result = INVALID_PROC_NUMBER;
        pfree(nspname);
        return result;
 }
@@ -4400,8 +4400,8 @@ InitTempTableNamespace(void)
        /*
         * Do not allow a Hot Standby session to make temp tables.  Aside from
         * problems with modifying the system catalogs, there is a naming
-        * conflict: pg_temp_N belongs to the session with BackendId N on the
-        * primary, not to a hot standby session with the same BackendId.  We
+        * conflict: pg_temp_N belongs to the session with proc number N on the
+        * primary, not to a hot standby session with the same proc number.  We
         * should not be able to get here anyway due to XactReadOnly checks, but
         * let's just make real sure.  Note that this also backstops various
         * operations that allow XactReadOnly transactions to modify temp tables;
@@ -4418,7 +4418,7 @@ InitTempTableNamespace(void)
                                (errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
                                 errmsg("cannot create temporary tables during a parallel operation")));
 
-       snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
+       snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyProcNumber);
 
        namespaceId = get_namespace_oid(namespaceName, true);
        if (!OidIsValid(namespaceId))
@@ -4451,7 +4451,7 @@ InitTempTableNamespace(void)
         * dropping a parent table should make its toast table go away.)
         */
        snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%d",
-                        MyBackendId);
+                        MyProcNumber);
 
        toastspaceId = get_namespace_oid(namespaceName, true);
        if (!OidIsValid(toastspaceId))
index a17cf4bb0cca51a6bed339609c9a85b439b0d6b8..29f6621f92554af0a25c5ee60c10eea59ee61628 100644 (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
index 23444f2a80020d797c264a7e158f62758b49d2f0..bbea5abd27aebca45e64a0edd0b0a04e849aa6e0 100644 (file)
@@ -247,7 +247,7 @@ typedef struct QueueBackendStatus
 {
        int32           pid;                    /* either a PID or InvalidPid */
        Oid                     dboid;                  /* backend's database OID, or InvalidOid */
-       BackendId       nextListener;   /* id of next listener, or InvalidBackendId */
+       ProcNumber      nextListener;   /* id of next listener, or INVALID_PROC_NUMBER */
        QueuePosition pos;                      /* backend has read queue up to here */
 } QueueBackendStatus;
 
@@ -273,13 +273,12 @@ typedef struct QueueBackendStatus
  * NotifyQueueTailLock, then NotifyQueueLock, and lastly SLRU bank lock.
  *
  * Each backend uses the backend[] array entry with index equal to its
- * BackendId (which can range from 1 to MaxBackends).  We rely on this to make
- * SendProcSignal fast.
+ * ProcNumber.  We rely on this to make SendProcSignal fast.
  *
  * The backend[] array entries for actively-listening backends are threaded
  * together using firstListener and the nextListener links, so that we can
  * scan them without having to iterate over inactive entries.  We keep this
- * list in order by BackendId so that the scan is cache-friendly when there
+ * list in order by ProcNumber so that the scan is cache-friendly when there
  * are many active entries.
  */
 typedef struct AsyncQueueControl
@@ -289,10 +288,10 @@ typedef struct AsyncQueueControl
                                                                 * listening backend */
        int                     stopPage;               /* oldest unrecycled page; must be <=
                                                                 * tail.page */
-       BackendId       firstListener;  /* id of first listener, or InvalidBackendId */
+       ProcNumber      firstListener;  /* id of first listener, or
+                                                                * INVALID_PROC_NUMBER */
        TimestampTz lastQueueFillWarn;  /* time of last queue-full msg */
        QueueBackendStatus backend[FLEXIBLE_ARRAY_MEMBER];
-       /* backend[0] is not used; used entries are from [1] to [MaxBackends] */
 } AsyncQueueControl;
 
 static AsyncQueueControl *asyncQueueControl;
@@ -491,7 +490,7 @@ AsyncShmemSize(void)
        Size            size;
 
        /* This had better match AsyncShmemInit */
-       size = mul_size(MaxBackends + 1, sizeof(QueueBackendStatus));
+       size = mul_size(MaxBackends, sizeof(QueueBackendStatus));
        size = add_size(size, offsetof(AsyncQueueControl, backend));
 
        size = add_size(size, SimpleLruShmemSize(notify_buffers, 0));
@@ -510,11 +509,8 @@ AsyncShmemInit(void)
 
        /*
         * Create or attach to the AsyncQueueControl structure.
-        *
-        * The used entries in the backend[] array run from 1 to MaxBackends; the
-        * zero'th entry is unused but must be allocated.
         */
-       size = mul_size(MaxBackends + 1, sizeof(QueueBackendStatus));
+       size = mul_size(MaxBackends, sizeof(QueueBackendStatus));
        size = add_size(size, offsetof(AsyncQueueControl, backend));
 
        asyncQueueControl = (AsyncQueueControl *)
@@ -526,14 +522,13 @@ AsyncShmemInit(void)
                SET_QUEUE_POS(QUEUE_HEAD, 0, 0);
                SET_QUEUE_POS(QUEUE_TAIL, 0, 0);
                QUEUE_STOP_PAGE = 0;
-               QUEUE_FIRST_LISTENER = InvalidBackendId;
+               QUEUE_FIRST_LISTENER = INVALID_PROC_NUMBER;
                asyncQueueControl->lastQueueFillWarn = 0;
-               /* zero'th entry won't be used, but let's initialize it anyway */
-               for (int i = 0; i <= MaxBackends; i++)
+               for (int i = 0; i < MaxBackends; i++)
                {
                        QUEUE_BACKEND_PID(i) = InvalidPid;
                        QUEUE_BACKEND_DBOID(i) = InvalidOid;
-                       QUEUE_NEXT_LISTENER(i) = InvalidBackendId;
+                       QUEUE_NEXT_LISTENER(i) = INVALID_PROC_NUMBER;
                        SET_QUEUE_POS(QUEUE_BACKEND_POS(i), 0, 0);
                }
        }
@@ -1050,7 +1045,7 @@ Exec_ListenPreCommit(void)
 {
        QueuePosition head;
        QueuePosition max;
-       BackendId       prevListener;
+       ProcNumber      prevListener;
 
        /*
         * Nothing to do if we are already listening to something, nor if we
@@ -1095,28 +1090,28 @@ Exec_ListenPreCommit(void)
        LWLockAcquire(NotifyQueueLock, LW_EXCLUSIVE);
        head = QUEUE_HEAD;
        max = QUEUE_TAIL;
-       prevListener = InvalidBackendId;
-       for (BackendId i = QUEUE_FIRST_LISTENER; i > 0; i = QUEUE_NEXT_LISTENER(i))
+       prevListener = INVALID_PROC_NUMBER;
+       for (ProcNumber i = QUEUE_FIRST_LISTENER; i != INVALID_PROC_NUMBER; i = QUEUE_NEXT_LISTENER(i))
        {
                if (QUEUE_BACKEND_DBOID(i) == MyDatabaseId)
                        max = QUEUE_POS_MAX(max, QUEUE_BACKEND_POS(i));
                /* Also find last listening backend before this one */
-               if (i < MyBackendId)
+               if (i < MyProcNumber)
                        prevListener = i;
        }
-       QUEUE_BACKEND_POS(MyBackendId) = max;
-       QUEUE_BACKEND_PID(MyBackendId) = MyProcPid;
-       QUEUE_BACKEND_DBOID(MyBackendId) = MyDatabaseId;
+       QUEUE_BACKEND_POS(MyProcNumber) = max;
+       QUEUE_BACKEND_PID(MyProcNumber) = MyProcPid;
+       QUEUE_BACKEND_DBOID(MyProcNumber) = MyDatabaseId;
        /* Insert backend into list of listeners at correct position */
-       if (prevListener > 0)
+       if (prevListener != INVALID_PROC_NUMBER)
        {
-               QUEUE_NEXT_LISTENER(MyBackendId) = QUEUE_NEXT_LISTENER(prevListener);
-               QUEUE_NEXT_LISTENER(prevListener) = MyBackendId;
+               QUEUE_NEXT_LISTENER(MyProcNumber) = QUEUE_NEXT_LISTENER(prevListener);
+               QUEUE_NEXT_LISTENER(prevListener) = MyProcNumber;
        }
        else
        {
-               QUEUE_NEXT_LISTENER(MyBackendId) = QUEUE_FIRST_LISTENER;
-               QUEUE_FIRST_LISTENER = MyBackendId;
+               QUEUE_NEXT_LISTENER(MyProcNumber) = QUEUE_FIRST_LISTENER;
+               QUEUE_FIRST_LISTENER = MyProcNumber;
        }
        LWLockRelease(NotifyQueueLock);
 
@@ -1248,23 +1243,23 @@ asyncQueueUnregister(void)
         */
        LWLockAcquire(NotifyQueueLock, LW_EXCLUSIVE);
        /* Mark our entry as invalid */
-       QUEUE_BACKEND_PID(MyBackendId) = InvalidPid;
-       QUEUE_BACKEND_DBOID(MyBackendId) = InvalidOid;
+       QUEUE_BACKEND_PID(MyProcNumber) = InvalidPid;
+       QUEUE_BACKEND_DBOID(MyProcNumber) = InvalidOid;
        /* and remove it from the list */
-       if (QUEUE_FIRST_LISTENER == MyBackendId)
-               QUEUE_FIRST_LISTENER = QUEUE_NEXT_LISTENER(MyBackendId);
+       if (QUEUE_FIRST_LISTENER == MyProcNumber)
+               QUEUE_FIRST_LISTENER = QUEUE_NEXT_LISTENER(MyProcNumber);
        else
        {
-               for (BackendId i = QUEUE_FIRST_LISTENER; i > 0; i = QUEUE_NEXT_LISTENER(i))
+               for (ProcNumber i = QUEUE_FIRST_LISTENER; i != INVALID_PROC_NUMBER; i = QUEUE_NEXT_LISTENER(i))
                {
-                       if (QUEUE_NEXT_LISTENER(i) == MyBackendId)
+                       if (QUEUE_NEXT_LISTENER(i) == MyProcNumber)
                        {
-                               QUEUE_NEXT_LISTENER(i) = QUEUE_NEXT_LISTENER(MyBackendId);
+                               QUEUE_NEXT_LISTENER(i) = QUEUE_NEXT_LISTENER(MyProcNumber);
                                break;
                        }
                }
        }
-       QUEUE_NEXT_LISTENER(MyBackendId) = InvalidBackendId;
+       QUEUE_NEXT_LISTENER(MyProcNumber) = INVALID_PROC_NUMBER;
        LWLockRelease(NotifyQueueLock);
 
        /* mark ourselves as no longer listed in the global array */
@@ -1549,7 +1544,7 @@ asyncQueueFillWarning(void)
                QueuePosition min = QUEUE_HEAD;
                int32           minPid = InvalidPid;
 
-               for (BackendId i = QUEUE_FIRST_LISTENER; i > 0; i = QUEUE_NEXT_LISTENER(i))
+               for (ProcNumber i = QUEUE_FIRST_LISTENER; i != INVALID_PROC_NUMBER; i = QUEUE_NEXT_LISTENER(i))
                {
                        Assert(QUEUE_BACKEND_PID(i) != InvalidPid);
                        min = QUEUE_POS_MIN(min, QUEUE_BACKEND_POS(i));
@@ -1580,7 +1575,7 @@ asyncQueueFillWarning(void)
  * behind.  Waken them anyway if they're far enough behind, so that they'll
  * advance their queue position pointers, allowing the global tail to advance.
  *
- * Since we know the BackendId and the Pid the signaling is quite cheap.
+ * Since we know the ProcNumber and the Pid the signaling is quite cheap.
  *
  * This is called during CommitTransaction(), so it's important for it
  * to have very low probability of failure.
@@ -1589,7 +1584,7 @@ static void
 SignalBackends(void)
 {
        int32      *pids;
-       BackendId  *ids;
+       ProcNumber *procnos;
        int                     count;
 
        /*
@@ -1601,11 +1596,11 @@ SignalBackends(void)
         * preallocate the arrays?  They're not that large, though.
         */
        pids = (int32 *) palloc(MaxBackends * sizeof(int32));
-       ids = (BackendId *) palloc(MaxBackends * sizeof(BackendId));
+       procnos = (ProcNumber *) palloc(MaxBackends * sizeof(ProcNumber));
        count = 0;
 
        LWLockAcquire(NotifyQueueLock, LW_EXCLUSIVE);
-       for (BackendId i = QUEUE_FIRST_LISTENER; i > 0; i = QUEUE_NEXT_LISTENER(i))
+       for (ProcNumber i = QUEUE_FIRST_LISTENER; i != INVALID_PROC_NUMBER; i = QUEUE_NEXT_LISTENER(i))
        {
                int32           pid = QUEUE_BACKEND_PID(i);
                QueuePosition pos;
@@ -1633,7 +1628,7 @@ SignalBackends(void)
                }
                /* OK, need to signal this one */
                pids[count] = pid;
-               ids[count] = i;
+               procnos[count] = i;
                count++;
        }
        LWLockRelease(NotifyQueueLock);
@@ -1659,12 +1654,12 @@ SignalBackends(void)
                 * NotifyQueueLock; which is unlikely but certainly possible. So we
                 * just log a low-level debug message if it happens.
                 */
-               if (SendProcSignal(pid, PROCSIG_NOTIFY_INTERRUPT, ids[i]) < 0)
+               if (SendProcSignal(pid, PROCSIG_NOTIFY_INTERRUPT, procnos[i]) < 0)
                        elog(DEBUG3, "could not signal backend with PID %d: %m", pid);
        }
 
        pfree(pids);
-       pfree(ids);
+       pfree(procnos);
 }
 
 /*
@@ -1872,8 +1867,8 @@ asyncQueueReadAllNotifications(void)
        /* Fetch current state */
        LWLockAcquire(NotifyQueueLock, LW_SHARED);
        /* Assert checks that we have a valid state entry */
-       Assert(MyProcPid == QUEUE_BACKEND_PID(MyBackendId));
-       pos = QUEUE_BACKEND_POS(MyBackendId);
+       Assert(MyProcPid == QUEUE_BACKEND_PID(MyProcNumber));
+       pos = QUEUE_BACKEND_POS(MyProcNumber);
        head = QUEUE_HEAD;
        LWLockRelease(NotifyQueueLock);
 
@@ -1995,7 +1990,7 @@ asyncQueueReadAllNotifications(void)
        {
                /* Update shared state */
                LWLockAcquire(NotifyQueueLock, LW_SHARED);
-               QUEUE_BACKEND_POS(MyBackendId) = pos;
+               QUEUE_BACKEND_POS(MyProcNumber) = pos;
                LWLockRelease(NotifyQueueLock);
        }
        PG_END_TRY();
@@ -2142,7 +2137,7 @@ asyncQueueAdvanceTail(void)
         */
        LWLockAcquire(NotifyQueueLock, LW_EXCLUSIVE);
        min = QUEUE_HEAD;
-       for (BackendId i = QUEUE_FIRST_LISTENER; i > 0; i = QUEUE_NEXT_LISTENER(i))
+       for (ProcNumber i = QUEUE_FIRST_LISTENER; i != INVALID_PROC_NUMBER; i = QUEUE_NEXT_LISTENER(i))
        {
                Assert(QUEUE_BACKEND_PID(i) != InvalidPid);
                min = QUEUE_POS_MIN(min, QUEUE_BACKEND_POS(i));
index b1327de71e846ed8159ada17dec3778a1491f40c..78a158c3da4c90fbb7cb7f3998d185e4e4b3e834 100644 (file)
@@ -276,7 +276,7 @@ ScanSourceDatabasePgClass(Oid tbid, Oid dbid, char *srcpath)
        rlocator.dbOid = dbid;
        rlocator.relNumber = relfilenumber;
 
-       smgr = smgropen(rlocator, InvalidBackendId);
+       smgr = smgropen(rlocator, INVALID_PROC_NUMBER);
        nblocks = smgrnblocks(smgr, MAIN_FORKNUM);
        smgrclose(smgr);
 
index 7a87626f5f01822e19aecfb5819bc05189a072d2..06f90ff7522ac62cf6a1f878a6305853196f2dd9 100644 (file)
@@ -476,7 +476,7 @@ WaitForOlderSnapshots(TransactionId limitXmin, bool progress)
                        /* If requested, publish who we're going to wait for. */
                        if (progress)
                        {
-                               PGPROC     *holder = BackendIdGetProc(old_snapshots[i].backendId);
+                               PGPROC     *holder = ProcNumberGetProc(old_snapshots[i].procNumber);
 
                                if (holder)
                                        pgstat_progress_update_param(PROGRESS_WAITFOR_CURRENT_PID,
index 24b9ee42c2a9d75882f0193b92971598ab32bce8..46103561c31185ec00a93119a0445e63c0e155e5 100644 (file)
@@ -343,7 +343,7 @@ fill_seq_with_data(Relation rel, HeapTuple tuple)
        {
                SMgrRelation srel;
 
-               srel = smgropen(rel->rd_locator, InvalidBackendId);
+               srel = smgropen(rel->rd_locator, INVALID_PROC_NUMBER);
                smgrcreate(srel, INIT_FORKNUM, false);
                log_smgrcreate(&rel->rd_locator, INIT_FORKNUM);
                fill_seq_fork_with_data(rel, tuple, INIT_FORKNUM);
index 5764f8b22254d4b659293aff17e932ac438bbe59..00a44ca803fb4ac6bf4c6147cea2fcebc6d50a3d 100644 (file)
@@ -26,7 +26,7 @@
 static shm_mq_handle *pq_mq_handle;
 static bool pq_mq_busy = false;
 static pid_t pq_mq_parallel_leader_pid = 0;
-static pid_t pq_mq_parallel_leader_backend_id = InvalidBackendId;
+static pid_t pq_mq_parallel_leader_proc_number = INVALID_PROC_NUMBER;
 
 static void pq_cleanup_redirect_to_shm_mq(dsm_segment *seg, Datum arg);
 static void mq_comm_reset(void);
@@ -75,11 +75,11 @@ pq_cleanup_redirect_to_shm_mq(dsm_segment *seg, Datum arg)
  * message data via the shm_mq.
  */
 void
-pq_set_parallel_leader(pid_t pid, BackendId backend_id)
+pq_set_parallel_leader(pid_t pid, ProcNumber procNumber)
 {
        Assert(PqCommMethods == &PqCommMqMethods);
        pq_mq_parallel_leader_pid = pid;
-       pq_mq_parallel_leader_backend_id = backend_id;
+       pq_mq_parallel_leader_proc_number = procNumber;
 }
 
 static void
@@ -168,13 +168,13 @@ mq_putmessage(char msgtype, const char *s, size_t len)
                        if (IsLogicalParallelApplyWorker())
                                SendProcSignal(pq_mq_parallel_leader_pid,
                                                           PROCSIG_PARALLEL_APPLY_MESSAGE,
-                                                          pq_mq_parallel_leader_backend_id);
+                                                          pq_mq_parallel_leader_proc_number);
                        else
                        {
                                Assert(IsParallelWorker());
                                SendProcSignal(pq_mq_parallel_leader_pid,
                                                           PROCSIG_PARALLEL_MESSAGE,
-                                                          pq_mq_parallel_leader_backend_id);
+                                                          pq_mq_parallel_leader_proc_number);
                        }
                }
 
index 04fedfae2fa6791d28d01ac5442e90965d7814c2..bb0eb13a898881b7d3304b704c6421effc3f5402 100644 (file)
@@ -79,7 +79,7 @@
 /* Shared memory area for archiver process */
 typedef struct PgArchData
 {
-       int                     pgprocno;               /* pgprocno of archiver process */
+       int                     pgprocno;               /* proc number of archiver process */
 
        /*
         * Forces a directory scan in pgarch_readyXlog().
@@ -170,7 +170,7 @@ PgArchShmemInit(void)
        {
                /* First time through, so initialize */
                MemSet(PgArch, 0, PgArchShmemSize());
-               PgArch->pgprocno = INVALID_PGPROCNO;
+               PgArch->pgprocno = INVALID_PROC_NUMBER;
                pg_atomic_init_u32(&PgArch->force_dir_scan, 0);
        }
 }
@@ -236,8 +236,8 @@ PgArchiverMain(void)
        on_shmem_exit(pgarch_die, 0);
 
        /*
-        * Advertise our pgprocno so that backends can use our latch to wake us up
-        * while we're sleeping.
+        * Advertise our proc number so that backends can use our latch to wake us
+        * up while we're sleeping.
         */
        PgArch->pgprocno = MyProcNumber;
 
@@ -271,7 +271,7 @@ PgArchWakeup(void)
         * process' (or no process') latch.  Even in that case the archiver will
         * be relaunched shortly and will start archiving.
         */
-       if (arch_pgprocno != INVALID_PGPROCNO)
+       if (arch_pgprocno != INVALID_PROC_NUMBER)
                SetLatch(&ProcGlobal->allProcs[arch_pgprocno].procLatch);
 }
 
@@ -741,7 +741,7 @@ pgarch_archiveDone(char *xlog)
 static void
 pgarch_die(int code, Datum arg)
 {
-       PgArch->pgprocno = INVALID_PGPROCNO;
+       PgArch->pgprocno = INVALID_PROC_NUMBER;
 }
 
 /*
index f295eff32f476fdd114522235551126f3b6891ef..8636d9424ec696a76ffd4fae2d7bc4a260a61fa7 100644 (file)
@@ -71,8 +71,8 @@ typedef struct
         * and so the LSN might point to the start of the next file even though
         * that might happen to be in the middle of a WAL record.
         *
-        * summarizer_pgprocno is the pgprocno value for the summarizer process,
-        * if one is running, or else INVALID_PGPROCNO.
+        * summarizer_pgprocno is the proc number of the summarizer process, if
+        * one is running, or else INVALID_PROC_NUMBER.
         *
         * pending_lsn is used by the summarizer to advertise the ending LSN of a
         * record it has recently read. It shouldn't ever be less than
@@ -83,7 +83,7 @@ typedef struct
        TimeLineID      summarized_tli;
        XLogRecPtr      summarized_lsn;
        bool            lsn_is_exact;
-       int                     summarizer_pgprocno;
+       ProcNumber      summarizer_pgprocno;
        XLogRecPtr      pending_lsn;
 
        /*
@@ -195,7 +195,7 @@ WalSummarizerShmemInit(void)
                WalSummarizerCtl->summarized_tli = 0;
                WalSummarizerCtl->summarized_lsn = InvalidXLogRecPtr;
                WalSummarizerCtl->lsn_is_exact = false;
-               WalSummarizerCtl->summarizer_pgprocno = INVALID_PGPROCNO;
+               WalSummarizerCtl->summarizer_pgprocno = INVALID_PROC_NUMBER;
                WalSummarizerCtl->pending_lsn = InvalidXLogRecPtr;
                ConditionVariableInit(&WalSummarizerCtl->summary_file_cv);
        }
@@ -444,7 +444,7 @@ GetWalSummarizerState(TimeLineID *summarized_tli, XLogRecPtr *summarized_lsn,
 
                *summarized_tli = WalSummarizerCtl->summarized_tli;
                *summarized_lsn = WalSummarizerCtl->summarized_lsn;
-               if (summarizer_pgprocno == INVALID_PGPROCNO)
+               if (summarizer_pgprocno == INVALID_PROC_NUMBER)
                {
                        /*
                         * If the summarizer has exited, the fact that it had processed
@@ -613,7 +613,7 @@ GetOldestUnsummarizedLSN(TimeLineID *tli, bool *lsn_is_exact,
 void
 SetWalSummarizerLatch(void)
 {
-       int                     pgprocno;
+       ProcNumber      pgprocno;
 
        if (WalSummarizerCtl == NULL)
                return;
@@ -622,7 +622,7 @@ SetWalSummarizerLatch(void)
        pgprocno = WalSummarizerCtl->summarizer_pgprocno;
        LWLockRelease(WALSummarizerLock);
 
-       if (pgprocno != INVALID_PGPROCNO)
+       if (pgprocno != INVALID_PROC_NUMBER)
                SetLatch(&ProcGlobal->allProcs[pgprocno].procLatch);
 }
 
@@ -683,7 +683,7 @@ static void
 WalSummarizerShutdown(int code, Datum arg)
 {
        LWLockAcquire(WALSummarizerLock, LW_EXCLUSIVE);
-       WalSummarizerCtl->summarizer_pgprocno = INVALID_PGPROCNO;
+       WalSummarizerCtl->summarizer_pgprocno = INVALID_PROC_NUMBER;
        LWLockRelease(WALSummarizerLock);
 }
 
index fb79ee1e7bf1b9e395d4c925df762fb96784a687..e7f7d4c5e4bd3ff63687cb21b84534a05a3962cc 100644 (file)
@@ -845,7 +845,7 @@ pa_shutdown(int code, Datum arg)
 {
        SendProcSignal(MyLogicalRepWorker->leader_pid,
                                   PROCSIG_PARALLEL_APPLY_MESSAGE,
-                                  InvalidBackendId);
+                                  INVALID_PROC_NUMBER);
 
        dsm_detach((dsm_segment *) DatumGetPointer(arg));
 }
@@ -934,7 +934,7 @@ ParallelApplyWorkerMain(Datum main_arg)
 
        pq_redirect_to_shm_mq(seg, error_mqh);
        pq_set_parallel_leader(MyLogicalRepWorker->leader_pid,
-                                                  InvalidBackendId);
+                                                  INVALID_PROC_NUMBER);
 
        MyLogicalRepWorker->last_send_time = MyLogicalRepWorker->last_recv_time =
                MyLogicalRepWorker->reply_time = 0;
index 0f173f63a28ca8e4be2fe5484ee812a873d73c00..2614f98ddd2d62344a8e4c3b8e8eb072d7e01634 100644 (file)
@@ -1651,7 +1651,7 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause,
                                if (MyBackendType == B_STARTUP)
                                        (void) SendProcSignal(active_pid,
                                                                                  PROCSIG_RECOVERY_CONFLICT_LOGICALSLOT,
-                                                                                 InvalidBackendId);
+                                                                                 INVALID_PROC_NUMBER);
                                else
                                        (void) kill(active_pid, SIGTERM);
 
index 13bc3e0aee406764b4ca4cb545b2439afb2e4afb..6bc2711cbe586a87a11bf3274f5991da4c525a91 100644 (file)
@@ -3646,7 +3646,7 @@ WalSndInitStopping(void)
                if (pid == 0)
                        continue;
 
-               SendProcSignal(pid, PROCSIG_WALSND_INIT_STOPPING, InvalidBackendId);
+               SendProcSignal(pid, PROCSIG_WALSND_INIT_STOPPING, INVALID_PROC_NUMBER);
        }
 }
 
index 6a99372ca19f55eed38dfdc0f3286f5d6cb49c25..46116a1f64be10d98f71fa7912f84258dc5dcd54 100644 (file)
@@ -122,7 +122,7 @@ InitBufferPool(void)
                        ClearBufferTag(&buf->tag);
 
                        pg_atomic_init_u32(&buf->state, 0);
-                       buf->wait_backend_pgprocno = INVALID_PGPROCNO;
+                       buf->wait_backend_pgprocno = INVALID_PROC_NUMBER;
 
                        buf->buf_id = i;
 
index bdf89bbc4dc79e64e66b91362e067859f7a67adb..c99730e0e5c39f27dca43ace4040508d8b524a7d 100644 (file)
@@ -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);
        }
 
index 1f02fed250e8d4d90ce2c39a48af61cabe6e2496..f4b294476e5d3727454cfd07c31608a956c62155 100644 (file)
@@ -242,7 +242,7 @@ GetLocalVictimBuffer(void)
                Page            localpage = (char *) LocalBufHdrGetBlock(bufHdr);
 
                /* Find smgr relation for buffer */
-               oreln = smgropen(BufTagGetRelFileLocator(&bufHdr->tag), MyBackendId);
+               oreln = smgropen(BufTagGetRelFileLocator(&bufHdr->tag), MyProcNumber);
 
                PageSetChecksumInplace(localpage, bufHdr->tag.blockNum);
 
@@ -509,7 +509,7 @@ DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum,
                                elog(ERROR, "block %u of %s is still referenced (local %u)",
                                         bufHdr->tag.blockNum,
                                         relpathbackend(BufTagGetRelFileLocator(&bufHdr->tag),
-                                                                       MyBackendId,
+                                                                       MyProcNumber,
                                                                        BufTagGetForkNum(&bufHdr->tag)),
                                         LocalRefCount[i]);
 
@@ -554,7 +554,7 @@ DropRelationAllLocalBuffers(RelFileLocator rlocator)
                                elog(ERROR, "block %u of %s is still referenced (local %u)",
                                         bufHdr->tag.blockNum,
                                         relpathbackend(BufTagGetRelFileLocator(&bufHdr->tag),
-                                                                       MyBackendId,
+                                                                       MyProcNumber,
                                                                        BufTagGetForkNum(&bufHdr->tag)),
                                         LocalRefCount[i]);
                        /* Remove entry from hashtable */
index d96606ebba5398962d7face54d8ce5fef36f9780..04b50204b8128ac632f6ad43090795caccffbab8 100644 (file)
@@ -818,9 +818,9 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
         * If the list was not empty, the leader will clear our XID.  It is
         * impossible to have followers without a leader because the first process
         * that has added itself to the list will always have nextidx as
-        * INVALID_PGPROCNO.
+        * INVALID_PROC_NUMBER.
         */
-       if (nextidx != INVALID_PGPROCNO)
+       if (nextidx != INVALID_PROC_NUMBER)
        {
                int                     extraWaits = 0;
 
@@ -836,7 +836,7 @@ ProcArrayGroupClearXid(PGPROC *proc, TransactionId latestXid)
                }
                pgstat_report_wait_end();
 
-               Assert(pg_atomic_read_u32(&proc->procArrayGroupNext) == INVALID_PGPROCNO);
+               Assert(pg_atomic_read_u32(&proc->procArrayGroupNext) == INVALID_PROC_NUMBER);
 
                /* Fix semaphore count for any absorbed wakeups */
                while (extraWaits-- > 0)