Skip to content

Commit

Permalink
pgprocno and lxid have been combined into a struct in PGPROC
Browse files Browse the repository at this point in the history
Relevant PG commits:
28f3915b73f75bd1b50ba070f56b34241fe53fd1
postgres/postgres@28f3915

ab355e3a88de745607f6dd4c21f0119b5c68f2ad
postgres/postgres@ab355e3

024c521117579a6d356050ad3d78fdc95e44eefa
postgres/postgres@024c521
  • Loading branch information
naisila committed Jul 11, 2024
1 parent 293e0f9 commit ce1a029
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/backend/distributed/transaction/backend_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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];
Expand All @@ -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)
Expand Down Expand Up @@ -1330,7 +1331,7 @@ ActiveDistributedTransactionNumbers(void)
LocalTransactionId
GetMyProcLocalTransactionId(void)
{
return MyProc->lxid;
return getLxid_compat(MyProc);
}


Expand Down
6 changes: 4 additions & 2 deletions src/backend/distributed/transaction/lock_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -993,15 +995,15 @@ AllocWaitEdge(WaitGraph *waitGraph)
static void
AddProcToVisit(PROCStack *remaining, PGPROC *proc)
{
if (remaining->procAdded[proc->pgprocno])
if (remaining->procAdded[getProcNo_compat(proc)])
{
return;
}

Assert(remaining->procCount < TotalProcCount());

remaining->procs[remaining->procCount++] = proc;
remaining->procAdded[proc->pgprocno] = true;
remaining->procAdded[getProcNo_compat(proc)] = true;
}


Expand Down
6 changes: 6 additions & 0 deletions src/include/pg_version_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ce1a029

Please sign in to comment.