Skip to content

Commit 1b8271e

Browse files
committed
Add delays to DTX
1 parent 99a60ea commit 1b8271e

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

contrib/pg_xtm/pg_dtm.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ static Snapshot DtmGetSnapshot(Snapshot snapshot)
8080
static XidStatus DtmGetTransactionStatus(TransactionId xid, XLogRecPtr *lsn)
8181
{
8282
XidStatus status = CLOGTransactionIdGetStatus(xid, lsn);
83-
if (status == TRANSACTION_STATUS_IN_PROGRESS && DtmHasSnapshot) {
84-
DtmEnsureConnection();
85-
status = DtmGlobalGetTransStatus(DtmConn, DtmNodeId, xid);
86-
if (status != TRANSACTION_STATUS_IN_PROGRESS) {
87-
CLOGTransactionIdSetTreeStatus(xid, 0, NULL, status, InvalidXLogRecPtr);
83+
if (status == TRANSACTION_STATUS_IN_PROGRESS && DtmHasSnapshot && !TransactionIdIsInProgress(xid)) {
84+
unsigned delay = 1000;
85+
while (true) {
86+
DtmEnsureConnection();
87+
status = DtmGlobalGetTransStatus(DtmConn, DtmNodeId, xid);
88+
if (status == TRANSACTION_STATUS_IN_PROGRESS) {
89+
pg_usleep(delay);
90+
if (delay < 100000) {
91+
delay *= 2;
92+
}
93+
} else {
94+
break;
95+
}
8896
}
97+
CLOGTransactionIdSetTreeStatus(xid, 0, NULL, status, InvalidXLogRecPtr);
8998
}
9099
return status;
91100
}

src/backend/utils/time/tqual.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ HeapTupleSatisfiesSelf(HeapTuple htup, Snapshot snapshot, Buffer buffer)
318318
if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))
319319
{
320320
/* it must have aborted or crashed */
321+
#if 1
321322
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
322323
InvalidTransactionId);
324+
#endif
323325
return true;
324326
}
325327

@@ -695,8 +697,10 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
695697
if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))
696698
{
697699
/* it must have aborted or crashed */
700+
#if 1
698701
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
699702
InvalidTransactionId);
703+
#endif
700704
return HeapTupleMayBeUpdated;
701705
}
702706

@@ -738,7 +742,7 @@ HeapTupleSatisfiesUpdate(HeapTuple htup, CommandId curcid,
738742
* token is also returned in snapshot->speculativeToken.
739743
*/
740744
bool
741-
HeapTupleSatisfiesDirtyVerbose(HeapTuple htup, Snapshot snapshot,
745+
HeapTupleSatisfiesDirty(HeapTuple htup, Snapshot snapshot,
742746
Buffer buffer)
743747
{
744748
HeapTupleHeader tuple = htup->t_data;
@@ -915,8 +919,10 @@ HeapTupleSatisfiesDirtyVerbose(HeapTuple htup, Snapshot snapshot,
915919
if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))
916920
{
917921
/* it must have aborted or crashed */
922+
#if 1
918923
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
919924
InvalidTransactionId);
925+
#endif
920926
return true;
921927
}
922928

@@ -1125,8 +1131,10 @@ HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
11251131
if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))
11261132
{
11271133
/* it must have aborted or crashed */
1134+
#if 1
11281135
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
11291136
InvalidTransactionId);
1137+
#endif
11301138
return true;
11311139
}
11321140

@@ -1296,8 +1304,10 @@ HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin,
12961304
{
12971305
if (TransactionIdIsInProgress(HeapTupleHeaderGetRawXmax(tuple)))
12981306
return HEAPTUPLE_LIVE;
1307+
#if 1
12991308
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
13001309
InvalidTransactionId);
1310+
#endif
13011311
}
13021312
}
13031313

@@ -1354,7 +1364,9 @@ HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin,
13541364
* Not in Progress, Not Committed, so either Aborted or crashed.
13551365
* Remove the Xmax.
13561366
*/
1367+
#if 1
13571368
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID, InvalidTransactionId);
1369+
#endif
13581370
return HEAPTUPLE_LIVE;
13591371
}
13601372

@@ -1370,8 +1382,10 @@ HeapTupleSatisfiesVacuum(HeapTuple htup, TransactionId OldestXmin,
13701382
/*
13711383
* Not in Progress, Not Committed, so either Aborted or crashed
13721384
*/
1385+
#if 1
13731386
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
13741387
InvalidTransactionId);
1388+
#endif
13751389
return HEAPTUPLE_LIVE;
13761390
}
13771391

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