Skip to content

Commit cc03eac

Browse files
knizhnikkelvich
authored andcommitted
Accurartly decrement Mtm->nActiveTransactions
1 parent 51a4c4a commit cc03eac

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

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

multimaster.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -857,10 +857,10 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
857857
MtmLock(LW_SHARED);
858858
}
859859
if (!ts->votingCompleted) {
860-
ts->status = TRANSACTION_STATUS_ABORTED;
860+
MtmAbortTransaction(ts);
861861
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));
862862
} else if (nConfigChanges != Mtm->nConfigChanges) {
863-
ts->status = TRANSACTION_STATUS_ABORTED;
863+
MtmAbortTransaction(ts);
864864
elog(WARNING, "Transaction is aborted because cluster configuration is changed during commit");
865865
}
866866
x->status = ts->status;
@@ -917,12 +917,12 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
917917
}
918918
Mtm->lastCsn = ts->csn;
919919
ts->status = TRANSACTION_STATUS_COMMITTED;
920+
MtmAdjustSubtransactions(ts);
921+
Assert(Mtm->nActiveTransactions != 0);
922+
Mtm->nActiveTransactions -= 1;
920923
} else {
921-
ts->status = TRANSACTION_STATUS_ABORTED;
924+
MtmAbortTransaction(ts);
922925
}
923-
MtmAdjustSubtransactions(ts);
924-
Assert(Mtm->nActiveTransactions != 0);
925-
Mtm->nActiveTransactions -= 1;
926926
}
927927
if (!commit && x->isReplicated && TransactionIdIsValid(x->gtid.xid)) {
928928
Assert(Mtm->status != MTM_RECOVERY);
@@ -1066,9 +1066,11 @@ void MtmWakeUpBackend(MtmTransState* ts)
10661066

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

10741076
/*
@@ -1342,8 +1344,8 @@ bool MtmRefreshClusterStatus(bool nowait)
13421344
{
13431345
nodemask_t mask, clique;
13441346
nodemask_t matrix[MAX_NODES];
1345-
int clique_size;
13461347
MtmTransState *ts;
1348+
int clique_size;
13471349
int i;
13481350

13491351
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