diff --git a/src/gausskernel/storage/ipc/procarray.cpp b/src/gausskernel/storage/ipc/procarray.cpp index 6bec9d223..59b2c604b 100644 --- a/src/gausskernel/storage/ipc/procarray.cpp +++ b/src/gausskernel/storage/ipc/procarray.cpp @@ -904,6 +904,11 @@ RunningTransactions GetRunningTransactionData(void) oldestRunningXid = t_thrd.xact_cxt.ShmemVariableCache->nextXid; + /* xmax is always latestCompletedXid + 1 */ + TransactionId xmax = latestCompletedXid; + TransactionIdAdvance(xmax); + TransactionId globalXmin = xmax; + /* * Spin over procArray collecting all xids and subxids. */ @@ -914,6 +919,13 @@ RunningTransactions GetRunningTransactionData(void) TransactionId xid; int nxids; + /* Update globalxmin to be the smallest valid xmin */ + xid = pgxact->xmin; /* fetch just once */ + + if (TransactionIdIsNormal(xid) && TransactionIdPrecedes(xid, globalXmin)) { + globalXmin = xid; + } + /* Fetch xid just once - see GetNewTransactionId */ xid = pgxact->xid; @@ -955,6 +967,16 @@ RunningTransactions GetRunningTransactionData(void) */ } } + + /* + * Update globalxmin to include actual process xids. This is a slightly + * different way of computing it than GetOldestXmin uses, but should give + * the same result. + */ + if (TransactionIdPrecedes(oldestRunningXid, globalXmin)) { + globalXmin = oldestRunningXid; + } + /* * It's important *not* to include the limits set by slots here because * snapbuild.c uses oldestRunningXid to manage its xmin horizon. If those @@ -968,6 +990,7 @@ RunningTransactions GetRunningTransactionData(void) CurrentRunningXacts->nextXid = t_thrd.xact_cxt.ShmemVariableCache->nextXid; CurrentRunningXacts->oldestRunningXid = oldestRunningXid; CurrentRunningXacts->latestCompletedXid = latestCompletedXid; + CurrentRunningXacts->globalXmin = globalXmin; Assert(TransactionIdIsValid(CurrentRunningXacts->nextXid)); Assert(TransactionIdIsValid(CurrentRunningXacts->oldestRunningXid)); diff --git a/src/gausskernel/storage/ipc/standby.cpp b/src/gausskernel/storage/ipc/standby.cpp index b56dbf31d..b37ea4ba0 100755 --- a/src/gausskernel/storage/ipc/standby.cpp +++ b/src/gausskernel/storage/ipc/standby.cpp @@ -784,7 +784,7 @@ static XLogRecPtr LogCurrentRunningXacts(RunningTransactions CurrRunningXacts) { xl_running_xacts xlrec; XLogRecPtr recptr; - TransactionId recentXmin = t_thrd.xact_cxt.ShmemVariableCache->recentGlobalXmin; + TransactionId recentXmin = CurrRunningXacts->globalXmin; XLogBeginInsert(); XLogRegisterData((char*)(&recentXmin), sizeof(TransactionId)); diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h index a63c76baf..752efaf40 100644 --- a/src/include/storage/standby.h +++ b/src/include/storage/standby.h @@ -118,6 +118,7 @@ typedef struct RunningTransactionsData { bool subxid_overflow; /* snapshot overflowed, subxids missing */ TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */ TransactionId oldestRunningXid; /* *not* oldestXmin */ + TransactionId globalXmin; /* running xacts's snapshot xmin */ TransactionId latestCompletedXid; /* copy of ShmemVariableCache-> latestCompletedXid*/ TransactionId* xids; /* array of (sub)xids still running */ } RunningTransactionsData;