!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;
|
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.
|
* Spin over procArray collecting all xids and subxids.
|
||||||
*/
|
*/
|
||||||
@ -914,6 +919,13 @@ RunningTransactions GetRunningTransactionData(void)
|
|||||||
TransactionId xid;
|
TransactionId xid;
|
||||||
int nxids;
|
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 */
|
/* Fetch xid just once - see GetNewTransactionId */
|
||||||
xid = pgxact->xid;
|
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
|
* It's important *not* to include the limits set by slots here because
|
||||||
* snapbuild.c uses oldestRunningXid to manage its xmin horizon. If those
|
* 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->nextXid = t_thrd.xact_cxt.ShmemVariableCache->nextXid;
|
||||||
CurrentRunningXacts->oldestRunningXid = oldestRunningXid;
|
CurrentRunningXacts->oldestRunningXid = oldestRunningXid;
|
||||||
CurrentRunningXacts->latestCompletedXid = latestCompletedXid;
|
CurrentRunningXacts->latestCompletedXid = latestCompletedXid;
|
||||||
|
CurrentRunningXacts->globalXmin = globalXmin;
|
||||||
|
|
||||||
Assert(TransactionIdIsValid(CurrentRunningXacts->nextXid));
|
Assert(TransactionIdIsValid(CurrentRunningXacts->nextXid));
|
||||||
Assert(TransactionIdIsValid(CurrentRunningXacts->oldestRunningXid));
|
Assert(TransactionIdIsValid(CurrentRunningXacts->oldestRunningXid));
|
||||||
|
@ -784,7 +784,7 @@ static XLogRecPtr LogCurrentRunningXacts(RunningTransactions CurrRunningXacts)
|
|||||||
{
|
{
|
||||||
xl_running_xacts xlrec;
|
xl_running_xacts xlrec;
|
||||||
XLogRecPtr recptr;
|
XLogRecPtr recptr;
|
||||||
TransactionId recentXmin = t_thrd.xact_cxt.ShmemVariableCache->recentGlobalXmin;
|
TransactionId recentXmin = CurrRunningXacts->globalXmin;
|
||||||
|
|
||||||
XLogBeginInsert();
|
XLogBeginInsert();
|
||||||
XLogRegisterData((char*)(&recentXmin), sizeof(TransactionId));
|
XLogRegisterData((char*)(&recentXmin), sizeof(TransactionId));
|
||||||
|
@ -118,6 +118,7 @@ typedef struct RunningTransactionsData {
|
|||||||
bool subxid_overflow; /* snapshot overflowed, subxids missing */
|
bool subxid_overflow; /* snapshot overflowed, subxids missing */
|
||||||
TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
|
TransactionId nextXid; /* copy of ShmemVariableCache->nextXid */
|
||||||
TransactionId oldestRunningXid; /* *not* oldestXmin */
|
TransactionId oldestRunningXid; /* *not* oldestXmin */
|
||||||
|
TransactionId globalXmin; /* running xacts's snapshot xmin */
|
||||||
TransactionId latestCompletedXid; /* copy of ShmemVariableCache-> latestCompletedXid*/
|
TransactionId latestCompletedXid; /* copy of ShmemVariableCache-> latestCompletedXid*/
|
||||||
TransactionId* xids; /* array of (sub)xids still running */
|
TransactionId* xids; /* array of (sub)xids still running */
|
||||||
} RunningTransactionsData;
|
} RunningTransactionsData;
|
||||||
|
Reference in New Issue
Block a user