diff options
Diffstat (limited to 'src/include/storage/proc.h')
-rw-r--r-- | src/include/storage/proc.h | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 4453c6df877..1e804463370 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -186,16 +186,31 @@ struct PGPROC * vacuum must not remove tuples deleted by * xid >= xmin ! */ - LocalTransactionId lxid; /* local id of top-level transaction currently - * being executed by this proc, if running; - * else InvalidLocalTransactionId */ int pid; /* Backend's process ID; 0 if prepared xact */ int pgxactoff; /* offset into various ProcGlobal->arrays with * data mirrored from this PGPROC */ + /* + * Currently running top-level transaction's virtual xid. Together these + * form a VirtualTransactionId, but we don't use that struct because this + * is not atomically assignable as whole, and we want to enforce code to + * consider both parts separately. See comments at VirtualTransactionId. + */ + struct + { + BackendId backendId; /* For regular backends, equal to + * GetBackendIdFromPGProc(proc). For prepared + * xacts, ID of the original backend that + * processed the transaction. For unused + * PGPROC entries, InvalidBackendID. */ + LocalTransactionId lxid; /* local id of top-level transaction + * currently * being executed by this + * proc, if running; else + * InvalidLocaltransactionId */ + } vxid; + /* These fields are zero while a backend is still starting up: */ - BackendId backendId; /* This backend's backend ID (if assigned) */ Oid databaseId; /* OID of database this backend is using */ Oid roleId; /* OID of role using this backend */ @@ -406,9 +421,16 @@ extern PGDLLIMPORT PROC_HDR *ProcGlobal; extern PGDLLIMPORT PGPROC *PreparedXactProcs; -/* Accessor for PGPROC given a pgprocno, and vice versa. */ +/* + * Accessors for getting PGPROC given a pgprocno or BackendId, and vice versa. + * + * For historical reasons, some code uses 0-based "proc numbers", while other + * code uses 1-based backend IDs. + */ #define GetPGProcByNumber(n) (&ProcGlobal->allProcs[(n)]) #define GetNumberFromPGProc(proc) ((proc) - &ProcGlobal->allProcs[0]) +#define GetPGProcByBackendId(n) (&ProcGlobal->allProcs[(n) - 1]) +#define GetBackendIdFromPGProc(proc) (GetNumberFromPGProc(proc) + 1) /* * We set aside some extra PGPROC structures for auxiliary processes, |