!362 fix standby node cannot be connected when startup, due to t_thrd.xact_cxt.ShmemVariableCache->recentGlobalXmin is invalid
Merge pull request !362 from xiong_xjun/master_1028
This commit is contained in:
@ -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));
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user