提交 7b21feb0 编写于 作者: P Paul Guo

Need to lock when accessing global prepared transaction data during checkpoint. (#10094)

Those data are stored as extended checkpoint so that prepared transactions are
not forgotten after checkpoint. If we access them without lock, it is possible
that we access some inconsistent data. That will lead to some unknown behaviors.
Reviewed-by: NHao Wu <hawu@pivotal.io>
Reviewed-by: NAshwin Agrawal <aagrawal@pivotal.io>

Cherry-picked from 3c284a3b
上级 73b4324c
......@@ -2298,8 +2298,8 @@ TwoPhaseRecoverMirror(void)
void
getTwoPhasePreparedTransactionData(prepared_transaction_agg_state **ptas, char *caller)
{
int numberOfPrepareXacts = TwoPhaseState->numPrepXacts;
GlobalTransaction *globalTransactionArray = TwoPhaseState->prepXacts;
int numberOfPrepareXacts;
GlobalTransaction *globalTransactionArray;
TransactionId xid;
XLogRecPtr *recordPtr = NULL;
int maxCount;
......@@ -2312,6 +2312,11 @@ getTwoPhasePreparedTransactionData(prepared_transaction_agg_state **ptas, char *
TwoPhaseAddPreparedTransactionInit(ptas, &maxCount);
LWLockAcquire(TwoPhaseStateLock, LW_SHARED);
numberOfPrepareXacts = TwoPhaseState->numPrepXacts;
globalTransactionArray = TwoPhaseState->prepXacts;
elog(PersistentRecovery_DebugPrintLevel(),
"getTwoPhasePreparedTransactionData: numberOfPrepareXacts = %d",
numberOfPrepareXacts);
......@@ -2336,6 +2341,8 @@ getTwoPhasePreparedTransactionData(prepared_transaction_agg_state **ptas, char *
recordPtr,
caller);
}
LWLockRelease(TwoPhaseStateLock);
} /* end getTwoPhasePreparedTransactionData */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册