Skip to content

Commit 9d743ba

Browse files
committed
Fix nested lock
1 parent f840aff commit 9d743ba

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

contrib/mmts/multimaster.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,10 @@ static void MtmProcessUtility(Node *parsetree, const char *queryString,
265265
void MtmLock(LWLockMode mode)
266266
{
267267
timestamp_t start, stop;
268-
if (mode == LW_EXCLUSIVE && MtmLockCount++ != 0) {
269-
return;
268+
if (mode == LW_EXCLUSIVE || MtmLockCount != 0) {
269+
if (MtmLockCount++ != 0) {
270+
return;
271+
}
270272
}
271273
#ifdef USE_SPINLOCK
272274
SpinLockAcquire(&Mtm->spinlock);
@@ -984,7 +986,7 @@ Mtm2PCVoting(MtmCurrentTrans* x, MtmTransState* ts)
984986
deadline = Max(MSEC_TO_USEC(MtmMin2PCTimeout), elapsed*MtmMax2PCRatio/100);
985987
} else {
986988
if (ts->isPrepared) {
987-
/* reset precommit message */
989+
/* resend precommit message */
988990
MtmSend2PCMessage(ts, MSG_PRECOMMIT);
989991
} else {
990992
if (elapsed > deadline) {
@@ -1291,7 +1293,7 @@ void MtmBroadcastPollMessage(MtmTransState* ts)
12911293

12921294
for (i = 0; i < Mtm->nAllNodes; i++)
12931295
{
1294-
if (BIT_CHECK(ts->participantsMask & ~Mtm->disabledNodeMask, i) && !BIT_CHECK(ts->votedMask, i))
1296+
if (BIT_CHECK(ts->participantsMask & ~Mtm->disabledNodeMask & ~ts->votedMask, i))
12951297
{
12961298
msg.node = i+1;
12971299
MTM_LOG3("Send request for transaction %s to node %d", msg.gid, msg.node);
@@ -1478,13 +1480,16 @@ static void MtmPollStatusOfPreparedTransactions(int disabledNodeId)
14781480
Assert(ts->gid[0]);
14791481
if (ts->status == TRANSACTION_STATUS_IN_PROGRESS) {
14801482
elog(LOG, "Abort transaction %s because its coordinator is disabled and it is not prepared at node %d", ts->gid, MtmNodeId);
1483+
//MtmUnlock();
14811484
MtmFinishPreparedTransaction(ts, false);
1485+
//MtmLock(LW_EXCLUSIVE);
14821486
} else {
14831487
MTM_LOG1("Poll state of transaction %d (%s)", ts->xid, ts->gid);
14841488
MtmBroadcastPollMessage(ts);
14851489
}
14861490
} else {
1487-
MTM_LOG2("Skip transaction %d (%s) with status %d gtid.node=%d gtid.xid=%d votedMask=%lx", ts->xid, ts->gid, ts->status, ts->gtid.node, ts->gtid.xid, ts->votedMask);
1491+
MTM_LOG2("Skip transaction %d (%s) with status %d gtid.node=%d gtid.xid=%d votedMask=%lx",
1492+
ts->xid, ts->gid, ts->status, ts->gtid.node, ts->gtid.xid, ts->votedMask);
14881493
}
14891494
}
14901495
}
@@ -1501,9 +1506,7 @@ static void MtmDisableNode(int nodeId)
15011506
if (nodeId != MtmNodeId) {
15021507
Mtm->nLiveNodes -= 1;
15031508
}
1504-
MtmUnlock();
15051509
MtmPollStatusOfPreparedTransactions(nodeId);
1506-
MtmLock(LW_EXCLUSIVE);
15071510
}
15081511

15091512
static void MtmEnableNode(int nodeId)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy