Skip to content

Commit bf168d6

Browse files
knizhnikkelvich
authored andcommitted
Abort transaction ni case of cluster configuration change
1 parent 2af3235 commit bf168d6

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

multimaster.c

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

279279
while (nanosleep(&ts, &rem) < 0) {
280280
Assert(errno == EINTR);
@@ -751,16 +751,20 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
751751
} else {
752752
time_t timeout = Max(Mtm2PCMinTimeout, (ts->csn - ts->snapshot)*Mtm2PCPrepareRatio/100000); /* usec->msec and percents */
753753
int result = 0;
754+
int nConfigChanges = Mtm->nConfigChanges;
754755
/* wait votes from all nodes */
755756
while (!ts->votingCompleted && !(result & WL_TIMEOUT)) {
756757
MtmUnlock();
757758
result = WaitLatch(&MyProc->procLatch, WL_LATCH_SET|WL_TIMEOUT, timeout);
758759
ResetLatch(&MyProc->procLatch);
759760
MtmLock(LW_SHARED);
760761
}
761-
if (!ts->votingCompleted) {
762+
if (!ts->votingCompleted) {
762763
ts->status = TRANSACTION_STATUS_ABORTED;
763-
elog(WARNING, "Transaction is aborted because of %d msec timeout expiration, prepare time %d msec", (int)timeout, (int)((ts->csn - x->snapshot)/1000));
764+
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));
765+
} else if (nConfigChanges != Mtm->nConfigChanges) {
766+
ts->status = TRANSACTION_STATUS_ABORTED;
767+
elog(WARNING, "Transaction is aborted because cluster configuration is changed during commit");
764768
}
765769
x->status = ts->status;
766770
MTM_LOG3("%d: Result of vote: %d", MyProcPid, ts->status);
@@ -1088,6 +1092,7 @@ bool MtmRecoveryCaughtUp(int nodeId, XLogRecPtr slotLSN)
10881092
BIT_CLEAR(Mtm->disabledNodeMask, nodeId-1);
10891093
Mtm->nodes[nodeId-1].lastStatusChangeTime = MtmGetSystemTime();
10901094
Mtm->nLiveNodes += 1;
1095+
Mtm->nConfigChanges += 1;
10911096
caughtUp = true;
10921097
} else if (!BIT_CHECK(Mtm->nodeLockerMask, nodeId-1)
10931098
&& slotLSN + MtmMinRecoveryLag > walLSN)
@@ -1262,6 +1267,7 @@ bool MtmRefreshClusterStatus(bool nowait)
12621267

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

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 */

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