Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9c31d02

Browse files
knizhnikkelvich
authored andcommitted
Avoid infinite loop in visibility check
1 parent 2afd9cc commit 9c31d02

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

multimaster.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef enum
9797
#define MTM_MAP_SIZE 1003
9898
#define MIN_WAIT_TIMEOUT 1000
9999
#define MAX_WAIT_TIMEOUT 100000
100+
#define MAX_WAIT_LOOPS 100
100101
#define STATUS_POLL_DELAY USECS_PER_SEC
101102

102103
void _PG_init(void);
@@ -424,8 +425,9 @@ bool MtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
424425
static timestamp_t maxSleepTime;
425426
#endif
426427
timestamp_t delay = MIN_WAIT_TIMEOUT;
428+
int i;
427429
Assert(xid != InvalidTransactionId);
428-
430+
429431
if (!MtmUseDtm) {
430432
return PgXidInMVCCSnapshot(xid, snapshot);
431433
}
@@ -436,7 +438,8 @@ bool MtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
436438
firstReportTime = MtmGetCurrentTime();
437439
}
438440
#endif
439-
while (true)
441+
442+
for (i = 0; i < MAX_WAIT_LOOPS; i++)
440443
{
441444
MtmTransState* ts = (MtmTransState*)hash_search(MtmXid2State, &xid, HASH_FIND, NULL);
442445
if (ts != NULL && ts->status != TRANSACTION_STATUS_IN_PROGRESS)
@@ -489,11 +492,13 @@ bool MtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
489492
else
490493
{
491494
MTM_LOG4("%d: visibility check is skept for transaction %u in snapshot %lu", MyProcPid, xid, MtmTx.snapshot);
492-
break;
495+
MtmUnlock();
496+
return PgXidInMVCCSnapshot(xid, snapshot);
493497
}
494498
}
495499
MtmUnlock();
496-
return PgXidInMVCCSnapshot(xid, snapshot);
500+
elog(ERROR, "Failed to get status of XID %d", xid);
501+
return true;
497502
}
498503

499504

@@ -1205,7 +1210,7 @@ static void MtmEnableNode(int nodeId)
12051210

12061211
void MtmRecoveryCompleted(void)
12071212
{
1208-
MTM_LOG1("Recovery of node %d is completed, disabled mask=%lx, reconnect mask=%ld, live nodes=%d",
1213+
MTM_LOG1("Recovery of node %d is completed, disabled mask=%lx, reconnect mask=%lx, live nodes=%d",
12091214
MtmNodeId, Mtm->disabledNodeMask, Mtm->reconnectMask, Mtm->nLiveNodes);
12101215
MtmLock(LW_EXCLUSIVE);
12111216
Mtm->recoverySlot = 0;

0 commit comments

Comments
 (0)