Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0af6e5

Browse files
knizhnikkelvich
authored andcommitted
Fix syspend node lock
1 parentbcde377 commita0af6e5

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

‎multimaster.c

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static int MtmLockCount;
255255
staticboolMtmMajorNode;
256256
staticboolMtmBreakConnection;
257257
staticboolMtmSuspended;
258+
staticboolMtmInsideTransaction;
258259

259260
staticExecutorStart_hook_typePreviousExecutorStartHook;
260261
staticExecutorFinish_hook_typePreviousExecutorFinishHook;
@@ -278,6 +279,15 @@ static bool MtmAtExitHookRegistered = false;
278279
*/
279280
voidMtmReleaseLocks(void)
280281
{
282+
MtmResetTransaction();
283+
if (MtmInsideTransaction)
284+
{
285+
MtmLock(LW_EXCLUSIVE);
286+
Assert(Mtm->nRunningTransactions>0);
287+
Mtm->nRunningTransactions-=1;
288+
MtmInsideTransaction= false;
289+
MtmUnlock();
290+
}
281291
if (MtmSuspended) {
282292
MtmResumeNode();
283293
}
@@ -287,6 +297,7 @@ void MtmReleaseLocks(void)
287297
Mtm->lastLockHolder=0;
288298
LWLockRelease((LWLockId)&Mtm->locks[MTM_STATE_LOCK_ID]);
289299
}
300+
290301
}
291302

292303
/*
@@ -870,14 +881,20 @@ MtmBeginTransaction(MtmCurrentTrans* x)
870881
&&strcmp(application_name,MULTIMASTER_ADMIN)!=0)
871882
{
872883
MtmCheckClusterLock();
873-
}
884+
}
885+
MtmInsideTransaction= true;
886+
Mtm->nRunningTransactions+=1;
887+
874888
x->snapshot=MtmAssignCSN();
889+
MTM_LOG1("Start transaction %lld with snapshot %lld", (long64)x->xid,x->snapshot);
875890

876891
MtmUnlock();
877892

878893
MTM_LOG3("%d: MtmLocalTransaction: %s transaction %u uses local snapshot %llu",
879894
MyProcPid,x->isDistributed ?"distributed" :"local",x->xid,x->snapshot);
880-
}
895+
}else {
896+
Assert(MtmInsideTransaction);
897+
}
881898
}
882899

883900

@@ -1328,15 +1345,20 @@ MtmLogAbortLogicalMessage(int nodeId, char const* gid)
13281345
staticvoid
13291346
MtmEndTransaction(MtmCurrentTrans*x,boolcommit)
13301347
{
1331-
MTM_LOG2("%d: End transaction %d, prepared=%d, replicated=%d, distributed=%d, 2pc=%d, gid=%s -> %s",
1332-
MyProcPid,x->xid,x->isPrepared,x->isReplicated,x->isDistributed,x->isTwoPhase,x->gid,commit ?"commit" :"abort");
1333-
if (MtmSuspended) {
1334-
MtmResumeNode();
1335-
}
1348+
MTM_LOG3("%d: End transaction %lld, prepared=%d, replicated=%d, distributed=%d, 2pc=%d, gid=%s -> %s, LSN %lld",
1349+
MyProcPid, (long64)x->xid,x->isPrepared,x->isReplicated,x->isDistributed,x->isTwoPhase,x->gid,commit ?"commit" :"abort", (long64)GetXLogInsertRecPtr());
13361350
commit &= (x->status!=TRANSACTION_STATUS_ABORTED);
1351+
1352+
MtmLock(LW_EXCLUSIVE);
1353+
1354+
if (MtmInsideTransaction) {
1355+
Assert(Mtm->nRunningTransactions>0);
1356+
Mtm->nRunningTransactions-=1;
1357+
MtmInsideTransaction= false;
1358+
}
1359+
13371360
if (x->isDistributed&& (x->isPrepared||x->isReplicated)&& !x->isTwoPhase) {
13381361
MtmTransState*ts=NULL;
1339-
MtmLock(LW_EXCLUSIVE);
13401362
if (x->isPrepared) {
13411363
ts= (MtmTransState*)hash_search(MtmXid2State,&x->xid,HASH_FIND,NULL);
13421364
Assert(ts!=NULL);
@@ -1419,12 +1441,16 @@ MtmEndTransaction(MtmCurrentTrans* x, bool commit)
14191441
#endif
14201442
}
14211443
Assert(!x->isActive);
1422-
MtmUnlock();
14231444
}
1445+
MtmUnlock();
1446+
14241447
MtmResetTransaction();
14251448
if (!MyReplicationSlot) {
14261449
MtmCheckSlots();
14271450
}
1451+
if (MtmSuspended) {
1452+
MtmResumeNode();
1453+
}
14281454
}
14291455

14301456
/*
@@ -2059,22 +2085,24 @@ static void
20592085
MtmSuspendNode(void)
20602086
{
20612087
timestamp_tdelay=MIN_WAIT_TIMEOUT;
2062-
boolinsideTransaction=MtmTx.isActive;
20632088
Assert(!MtmSuspended);
20642089
MtmLock(LW_EXCLUSIVE);
20652090
if (Mtm->exclusiveLock) {
20662091
elog(ERROR,"There is already pending exclusive lock");
20672092
}
20682093
Mtm->exclusiveLock= true;
20692094
MtmSuspended= true;
2070-
while (Mtm->nActiveTransactions!=insideTransaction) {
2095+
MTM_LOG2("Transaction %lld tries to suspend node at %lld insideTransaction=%d, active transactions=%lld",
2096+
(long64)MtmTx.xid,MtmGetCurrentTime(),insideTransaction, (long64)Mtm->nRunningTransactions);
2097+
while (Mtm->nRunningTransactions!=1) {/* I am one */
20712098
MtmUnlock();
20722099
MtmSleep(delay);
20732100
if (delay*2 <=MAX_WAIT_TIMEOUT) {
20742101
delay *=2;
20752102
}
20762103
MtmLock(LW_EXCLUSIVE);
20772104
}
2105+
MTM_LOG2("Transaction %lld suspended node at %lld, LSN %lld, active transactions=%lld", (long64)MtmTx.xid,MtmGetCurrentTime(), (long64)GetXLogInsertRecPtr(), (long64)Mtm->nRunningTransactions);
20782106
MtmUnlock();
20792107
}
20802108

@@ -2085,6 +2113,7 @@ static void
20852113
MtmResumeNode(void)
20862114
{
20872115
MtmLock(LW_EXCLUSIVE);
2116+
MTM_LOG2("Transaction %lld resume node at %lld status %s LSN %lld", (long64)MtmTx.xid,MtmGetCurrentTime(),MtmTxnStatusMnem[MtmTx.status], (long64)GetXLogInsertRecPtr());
20882117
Mtm->exclusiveLock= false;
20892118
MtmSuspended= false;
20902119
MtmUnlock();
@@ -2527,6 +2556,7 @@ static void MtmInitialize()
25272556
Mtm->nLockers=0;
25282557
Mtm->exclusiveLock= false;
25292558
Mtm->nActiveTransactions=0;
2559+
Mtm->nRunningTransactions=0;
25302560
Mtm->votingTransactions=NULL;
25312561
Mtm->transListHead=NULL;
25322562
Mtm->transListTail=&Mtm->transListHead;
@@ -3369,7 +3399,7 @@ void MtmFinishPreparedTransaction(MtmTransState* ts, bool commit)
33693399
MtmTx.isActive= true;
33703400
FinishPreparedTransaction(ts->gid,commit);
33713401
if (commit) {
3372-
MTM_LOG2("Distributed transaction %s is committed",ts->gid);
3402+
MTM_LOG2("Distributed transaction %s(%lld)is committed at %lld with LSN=%lld",ts->gid, (long64)ts->xid,MtmGetCurrentTime(), (long64)GetXLogInsertRecPtr());
33733403
}
33743404
if (!insideTransaction) {
33753405
CommitTransactionCommand();
@@ -4556,7 +4586,7 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
45564586
MTM_ELOG(ERROR,"Transaction %s (%llu) is aborted by DTM",x->gid, (long64)x->xid);
45574587
}else {
45584588
FinishPreparedTransaction(x->gid, true);
4559-
MTM_LOG2("Distributed transaction %s is committed",x->gid);
4589+
MTM_LOG2("Distributed transaction %s(%lld)is committed at %lld with LSN=%lld",x->gid, (long64)x->xid,MtmGetCurrentTime(), (long64)GetXLogInsertRecPtr());
45604590
}
45614591
}
45624592
}

‎multimaster.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ typedef struct
295295
intnSenders;/* Number of started WAL senders (used to determine moment when recovery) */
296296
intnLockers;/* Number of lockers */
297297
intnActiveTransactions;/* Number of active 2PC transactions */
298+
intnRunningTransactions;/* Number of all running transactions */
298299
intnConfigChanges;/* Number of cluster configuration changes */
299300
intrecoveryCount;/* Number of completed recoveries */
300301
intdonorNodeId;/* Cluster node from which this node was populated */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp