Skip to content

Commit 10f7b9e

Browse files
knizhnikkelvich
authored andcommitted
Fix problem with suspended transaction
1 parent 7b14ccc commit 10f7b9e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

multimaster.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ void MtmLock(LWLockMode mode)
319319
timestamp_t start, stop;
320320
start = MtmGetSystemTime();
321321
#endif
322+
if (MyProc == NULL) { /* Can not wait if have no PGPROC. It can happen at process exit. TODO: without lock we can get race condition and corrupt Mtm state */
323+
return;
324+
}
322325
LWLockAcquire((LWLockId)&Mtm->locks[MTM_STATE_LOCK_ID], mode);
323326
#if DEBUG_LEVEL > 1
324327
stop = MtmGetSystemTime();
@@ -340,6 +343,9 @@ void MtmUnlock(void)
340343
Assert(Mtm->lastLockHolder == MyProcPid);
341344
return;
342345
}
346+
if (MyProc == NULL) { /* If we have no PGPROC, then lock was not obtained. */
347+
return;
348+
}
343349
Mtm->lastLockHolder = 0;
344350
LWLockRelease((LWLockId)&Mtm->locks[MTM_STATE_LOCK_ID]);
345351
}
@@ -4584,10 +4590,10 @@ static bool MtmTwoPhaseCommit(MtmCurrentTrans* x)
45844590
MTM_ELOG(WARNING, "Failed to prepare transaction %s (%llu)", x->gid, (long64)x->xid);
45854591
} else {
45864592
CommitTransactionCommand();
4593+
StartTransactionCommand();
45874594
if (x->isSuspended) {
45884595
MTM_ELOG(WARNING, "Transaction %s (%llu) is left in prepared state because coordinator node is not online", x->gid, (long64)x->xid);
45894596
} else {
4590-
StartTransactionCommand();
45914597
Assert(x->isActive);
45924598
if (x->status == TRANSACTION_STATUS_ABORTED) {
45934599
FinishPreparedTransaction(x->gid, false);

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