Skip to content

Commit e494d0c

Browse files
committed
Accurartly decrement Mtm->nActiveTransactions
1 parent db23ecf commit e494d0c

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

contrib/mmts/arbiter.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ static void MtmSendHeartbeat()
341341
{
342342
if (sockets[i] >= 0 && sockets[i] != busy_socket && !BIT_CHECK(Mtm->disabledNodeMask|Mtm->reconnectMask, i))
343343
{
344-
int rc = send(sockets[i], &msg, sizeof(msg), 0);
345-
Assert(rc <= 0 || (size_t)rc == sizeof(msg));
344+
size_t rc = send(sockets[i], &msg, sizeof(msg), 0);
345+
if ((size_t)rc != sizeof(msg)) {
346+
elog(LOG, "Failed to send heartbeat to node %d: %d", i, errno);
347+
}
346348
}
347349
}
348350

contrib/mmts/multimaster.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -858,10 +858,10 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
858858
MtmLock(LW_SHARED);
859859
}
860860
if (!ts->votingCompleted) {
861-
ts->status = TRANSACTION_STATUS_ABORTED;
861+
MtmAbortTransaction(ts);
862862
elog(WARNING, "Transaction is aborted because of %d msec timeout expiration, prepare time %d msec", (int)transTimeout, (int)USEC_TO_MSEC(ts->csn - x->snapshot));
863863
} else if (nConfigChanges != Mtm->nConfigChanges) {
864-
ts->status = TRANSACTION_STATUS_ABORTED;
864+
MtmAbortTransaction(ts);
865865
elog(WARNING, "Transaction is aborted because cluster configuration is changed during commit");
866866
}
867867
x->status = ts->status;
@@ -918,12 +918,12 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
918918
}
919919
Mtm->lastCsn = ts->csn;
920920
ts->status = TRANSACTION_STATUS_COMMITTED;
921+
MtmAdjustSubtransactions(ts);
922+
Assert(Mtm->nActiveTransactions != 0);
923+
Mtm->nActiveTransactions -= 1;
921924
} else {
922-
ts->status = TRANSACTION_STATUS_ABORTED;
925+
MtmAbortTransaction(ts);
923926
}
924-
MtmAdjustSubtransactions(ts);
925-
Assert(Mtm->nActiveTransactions != 0);
926-
Mtm->nActiveTransactions -= 1;
927927
}
928928
if (!commit && x->isReplicated && TransactionIdIsValid(x->gtid.xid)) {
929929
Assert(Mtm->status != MTM_RECOVERY);
@@ -1067,9 +1067,11 @@ void MtmWakeUpBackend(MtmTransState* ts)
10671067

10681068
void MtmAbortTransaction(MtmTransState* ts)
10691069
{
1070-
ts->status = TRANSACTION_STATUS_ABORTED;
1071-
MtmAdjustSubtransactions(ts);
1072-
Mtm->nActiveTransactions -= 1;
1070+
if (ts->status != TRANSACTION_STATUS_ABORTED) {
1071+
ts->status = TRANSACTION_STATUS_ABORTED;
1072+
MtmAdjustSubtransactions(ts);
1073+
Mtm->nActiveTransactions -= 1;
1074+
}
10731075
}
10741076

10751077
/*
@@ -1343,8 +1345,8 @@ bool MtmRefreshClusterStatus(bool nowait)
13431345
{
13441346
nodemask_t mask, clique;
13451347
nodemask_t matrix[MAX_NODES];
1346-
int clique_size;
13471348
MtmTransState *ts;
1349+
int clique_size;
13481350
int i;
13491351

13501352
if (!MtmUseRaftable || !MtmBuildConnectivityMatrix(matrix, nowait)) {

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