From 140a44328770b0780e11acf2c36cb2647838471d Mon Sep 17 00:00:00 2001 From: naisila Date: Wed, 10 Jul 2024 17:58:16 +0200 Subject: [PATCH] pgprocno and lxid have been combined into a struct in PGPROC Relevant PG commits: 28f3915b73f75bd1b50ba070f56b34241fe53fd1 https://github.com/postgres/postgres/commit/28f3915b73f75bd1b50ba070f56b34241fe53fd1 ab355e3a88de745607f6dd4c21f0119b5c68f2ad https://github.com/postgres/postgres/commit/ab355e3a88de745607f6dd4c21f0119b5c68f2ad 024c521117579a6d356050ad3d78fdc95e44eefa https://github.com/postgres/postgres/commit/024c521117579a6d356050ad3d78fdc95e44eefa --- src/backend/distributed/transaction/backend_data.c | 13 +++++++------ src/backend/distributed/transaction/lock_graph.c | 6 ++++-- src/include/pg_version_compat.h | 6 ++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/backend/distributed/transaction/backend_data.c b/src/backend/distributed/transaction/backend_data.c index 63f29e8ea8f..e2afd18f74a 100644 --- a/src/backend/distributed/transaction/backend_data.c +++ b/src/backend/distributed/transaction/backend_data.c @@ -33,7 +33,7 @@ #include "storage/spin.h" #include "utils/timestamp.h" -#include "pg_version_constants.h" +#include "pg_version_compat.h" #include "distributed/backend_data.h" #include "distributed/connection_management.h" @@ -700,7 +700,7 @@ InitializeBackendData(const char *applicationName) uint64 gpid = ExtractGlobalPID(applicationName); - MyBackendData = &backendManagementShmemData->backends[MyProc->pgprocno]; + MyBackendData = &backendManagementShmemData->backends[getProcNo_compat(MyProc)]; Assert(MyBackendData); @@ -1174,11 +1174,11 @@ CurrentDistributedTransactionNumber(void) void GetBackendDataForProc(PGPROC *proc, BackendData *result) { - int pgprocno = proc->pgprocno; + int pgprocno = getProcNo_compat(proc); if (proc->lockGroupLeader != NULL) { - pgprocno = proc->lockGroupLeader->pgprocno; + pgprocno = getProcNo_compat(proc->lockGroupLeader); } BackendData *backendData = &backendManagementShmemData->backends[pgprocno]; @@ -1198,7 +1198,8 @@ GetBackendDataForProc(PGPROC *proc, BackendData *result) void CancelTransactionDueToDeadlock(PGPROC *proc) { - BackendData *backendData = &backendManagementShmemData->backends[proc->pgprocno]; + BackendData *backendData = &backendManagementShmemData->backends[getProcNo_compat( + proc)]; /* backend might not have used citus yet and thus not initialized backend data */ if (!backendData) @@ -1330,7 +1331,7 @@ ActiveDistributedTransactionNumbers(void) LocalTransactionId GetMyProcLocalTransactionId(void) { - return MyProc->lxid; + return getLxid_compat(MyProc); } diff --git a/src/backend/distributed/transaction/lock_graph.c b/src/backend/distributed/transaction/lock_graph.c index a04dd0c78b1..11982ec5a30 100644 --- a/src/backend/distributed/transaction/lock_graph.c +++ b/src/backend/distributed/transaction/lock_graph.c @@ -23,6 +23,8 @@ #include "utils/hsearch.h" #include "utils/timestamp.h" +#include "pg_version_compat.h" + #include "distributed/backend_data.h" #include "distributed/connection_management.h" #include "distributed/hash_helpers.h" @@ -993,7 +995,7 @@ AllocWaitEdge(WaitGraph *waitGraph) static void AddProcToVisit(PROCStack *remaining, PGPROC *proc) { - if (remaining->procAdded[proc->pgprocno]) + if (remaining->procAdded[getProcNo_compat(proc)]) { return; } @@ -1001,7 +1003,7 @@ AddProcToVisit(PROCStack *remaining, PGPROC *proc) Assert(remaining->procCount < TotalProcCount()); remaining->procs[remaining->procCount++] = proc; - remaining->procAdded[proc->pgprocno] = true; + remaining->procAdded[getProcNo_compat(proc)] = true; } diff --git a/src/include/pg_version_compat.h b/src/include/pg_version_compat.h index e177e43815b..ef938ffe601 100644 --- a/src/include/pg_version_compat.h +++ b/src/include/pg_version_compat.h @@ -108,6 +108,9 @@ getStxstattarget_compat(HeapTuple tup) k) create_foreignscan_path(a, b, c, d, e, f, g, h, \ i, j, k) +#define getProcNo_compat(a) (a->vxid.procNumber) +#define getLxid_compat(a) (a->vxid.lxid) + #else #include "access/htup_details.h" @@ -139,6 +142,9 @@ getStxstattarget_compat(HeapTuple tup) k) create_foreignscan_path(a, b, c, d, e, f, g, h, \ i, k) +#define getProcNo_compat(a) (a->pgprocno) +#define getLxid_compat(a) (a->lxid) + #endif #if PG_VERSION_NUM >= PG_VERSION_16