Skip to content

Commit 74fc707

Browse files
committed
Abort transaction ni case of cluster configuration change
1 parent 494e6dc commit 74fc707

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

contrib/mmts/multimaster.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ void MtmSleep(timestamp_t interval)
274274
{
275275
struct timespec ts;
276276
struct timespec rem;
277-
ts.tv_sec = interval/1000000;
278-
ts.tv_nsec = interval%1000000*1000;
277+
ts.tv_sec = interval/USECS_PER_SEC;
278+
ts.tv_nsec = interval%USECS_PER_SEC*1000;
279279

280280
while (nanosleep(&ts, &rem) < 0) {
281281
Assert(errno == EINTR);
@@ -752,16 +752,20 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
752752
} else {
753753
time_t timeout = Max(Mtm2PCMinTimeout, (ts->csn - ts->snapshot)*Mtm2PCPrepareRatio/100000); /* usec->msec and percents */
754754
int result = 0;
755+
int nConfigChanges = Mtm->nConfigChanges;
755756
/* wait votes from all nodes */
756757
while (!ts->votingCompleted && !(result & WL_TIMEOUT)) {
757758
MtmUnlock();
758759
result = WaitLatch(&MyProc->procLatch, WL_LATCH_SET|WL_TIMEOUT, timeout);
759760
ResetLatch(&MyProc->procLatch);
760761
MtmLock(LW_SHARED);
761762
}
762-
if (!ts->votingCompleted) {
763+
if (!ts->votingCompleted) {
763764
ts->status = TRANSACTION_STATUS_ABORTED;
764-
elog(WARNING, "Transaction is aborted because of %d msec timeout expiration, prepare time %d msec", (int)timeout, (int)((ts->csn - x->snapshot)/1000));
765+
elog(WARNING, "Transaction is aborted because of %d msec timeout expiration, prepare time %d msec", (int)timeout, (int)USEC_TO_MSEC(ts->csn - x->snapshot));
766+
} else if (nConfigChanges != Mtm->nConfigChanges) {
767+
ts->status = TRANSACTION_STATUS_ABORTED;
768+
elog(WARNING, "Transaction is aborted because cluster configuration is changed during commit");
765769
}
766770
x->status = ts->status;
767771
MTM_LOG3("%d: Result of vote: %d", MyProcPid, ts->status);
@@ -1089,6 +1093,7 @@ bool MtmRecoveryCaughtUp(int nodeId, XLogRecPtr slotLSN)
10891093
BIT_CLEAR(Mtm->disabledNodeMask, nodeId-1);
10901094
Mtm->nodes[nodeId-1].lastStatusChangeTime = MtmGetSystemTime();
10911095
Mtm->nLiveNodes += 1;
1096+
Mtm->nConfigChanges += 1;
10921097
caughtUp = true;
10931098
} else if (!BIT_CHECK(Mtm->nodeLockerMask, nodeId-1)
10941099
&& slotLSN + MtmMinRecoveryLag > walLSN)
@@ -1263,6 +1268,7 @@ bool MtmRefreshClusterStatus(bool nowait)
12631268

12641269
void MtmCheckQuorum(void)
12651270
{
1271+
Mtm->nConfigChanges += 1;
12661272
if (Mtm->nLiveNodes < Mtm->nAllNodes/2+1) {
12671273
if (Mtm->status == MTM_ONLINE) { /* out of quorum */
12681274
elog(WARNING, "Node is in minority: disabled mask %lx", (long) Mtm->disabledNodeMask);
@@ -1460,6 +1466,7 @@ static void MtmInitialize()
14601466
Mtm->nReceivers = 0;
14611467
Mtm->timeShift = 0;
14621468
Mtm->transCount = 0;
1469+
Mtm->nConfigChanges = 0;
14631470
Mtm->localTablesHashLoaded = false;
14641471
for (i = 0; i < MtmNodes; i++) {
14651472
Mtm->nodes[i].oldestSnapshot = 0;

contrib/mmts/multimaster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ typedef struct
169169
int nReceivers; /* Number of initialized logical receivers (used to determine moment when Mtm intialization is completed */
170170
int nLockers; /* Number of lockers */
171171
int nActiveTransactions; /* Nunmber of active 2PC transactions */
172-
long timeShift; /* Local time correction */
172+
int nConfigChanges; /* Number of cluster configuration changes */
173+
int64 timeShift; /* Local time correction */
173174
csn_t csn; /* Last obtained CSN: used to provide unique acending CSNs based on system time */
174175
MtmTransState* votingTransactions; /* L1-list of replicated transactions sendings notifications to coordinator.
175176
This list is used to pass information to mtm-sender BGW */

contrib/mmts/tests/dtmacid.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ void* reader(void* arg)
144144
}
145145
}
146146
}
147-
t.transactions += 2;
148147
t.selects += 2;
149148
txn1.commit();
150149
txn2.commit();

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