未验证 提交 3c284a3b 编写于 作者: P Paul Guo 提交者: GitHub

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>
上级 1bb9ce2c
......@@ -2203,8 +2203,8 @@ RecordTransactionAbortPrepared(TransactionId xid,
void
getTwoPhasePreparedTransactionData(prepared_transaction_agg_state **ptas)
{
int numberOfPrepareXacts = TwoPhaseState->numPrepXacts;
GlobalTransaction *globalTransactionArray = TwoPhaseState->prepXacts;
int numberOfPrepareXacts;
GlobalTransaction *globalTransactionArray;
TransactionId xid;
XLogRecPtr *recordPtr = NULL;
int maxCount;
......@@ -2213,6 +2213,11 @@ getTwoPhasePreparedTransactionData(prepared_transaction_agg_state **ptas)
TwoPhaseAddPreparedTransactionInit(ptas, &maxCount);
LWLockAcquire(TwoPhaseStateLock, LW_SHARED);
numberOfPrepareXacts = TwoPhaseState->numPrepXacts;
globalTransactionArray = TwoPhaseState->prepXacts;
for (int i = 0; i < numberOfPrepareXacts; i++)
{
GlobalTransaction gxact = globalTransactionArray[i];
......@@ -2227,6 +2232,8 @@ getTwoPhasePreparedTransactionData(prepared_transaction_agg_state **ptas)
xid,
recordPtr);
}
LWLockRelease(TwoPhaseStateLock);
} /* end getTwoPhasePreparedTransactionData */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册