Skip to content

Commit 2485a59

Browse files
committed
Yet another not working version of XTM
1 parent 702af19 commit 2485a59

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

contrib/pg_xtm/pg_dtm.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
#include "libdtm.h"
3535

36+
#define MIN_DELAY 10000
37+
#define MAX_DELAY 100000
38+
3639
void _PG_init(void);
3740
void _PG_fini(void);
3841

@@ -121,30 +124,41 @@ static Snapshot DtmGetSnapshot(Snapshot snapshot)
121124
return snapshot;
122125
}
123126

124-
#if 0
125127
static bool IsInDtmSnapshot(TransactionId xid)
126128
{
127129
return DtmHasSnapshot
128130
&& (/*xid > DtmSnapshot.xmax
129131
|| */bsearch(&xid, DtmSnapshot.xip, DtmSnapshot.xcnt, sizeof(TransactionId), xidComparator) != NULL);
130132
}
131-
#endif
132133

133134
static bool DtmTransactionIsInProgress(TransactionId xid)
134135
{
135-
return /*IsInDtmSnapshot(xid) || */ TransactionIdIsRunning(xid);
136+
#if 0
137+
if (IsInDtmSnapshot(xid)) {
138+
unsigned delay = MIN_DELAY;
139+
XLogRecPtr lsn;
140+
while (CLOGTransactionIdGetStatus(xid, &lsn) == TRANSACTION_STATUS_IN_PROGRESS) {
141+
pg_usleep(delay);
142+
if (delay < MAX_DELAY) {
143+
delay *= 2;
144+
}
145+
}
146+
return false;
147+
}
148+
#endif
149+
return TransactionIdIsRunning(xid) && !IsInDtmSnapshot(xid);
136150
}
137151

138152
static XidStatus DtmGetGloabalTransStatus(TransactionId xid)
139153
{
140-
unsigned delay = 1000;
154+
unsigned delay = MIN_DELAY;
141155
while (true) {
142156
XidStatus status;
143157
DtmEnsureConnection();
144158
status = DtmGlobalGetTransStatus(DtmConn, DtmNodeId, xid);
145159
if (status == TRANSACTION_STATUS_IN_PROGRESS) {
146160
pg_usleep(delay);
147-
if (delay < 100000) {
161+
if (delay < MAX_DELAY) {
148162
delay *= 2;
149163
}
150164
} else {
@@ -155,16 +169,17 @@ static XidStatus DtmGetGloabalTransStatus(TransactionId xid)
155169

156170
static XidStatus DtmGetTransactionStatus(TransactionId xid, XLogRecPtr *lsn)
157171
{
158-
XidStatus status = CLOGTransactionIdGetStatus(xid, lsn);
159-
#if 0
160-
if (status == TRANSACTION_STATUS_IN_PROGRESS) {
161-
status = DtmGetGloabalTransStatus(xid);
162-
if (status == TRANSACTION_STATUS_UNKNOWN) {
163-
status = TRANSACTION_STATUS_IN_PROGRESS;
172+
if (IsInDtmSnapshot(xid)) {
173+
unsigned delay = MIN_DELAY;
174+
XLogRecPtr lsn;
175+
while (CLOGTransactionIdGetStatus(xid, &lsn) == TRANSACTION_STATUS_IN_PROGRESS) {
176+
pg_usleep(delay);
177+
if (delay < MAX_DELAY) {
178+
delay *= 2;
179+
}
164180
}
165181
}
166-
#endif
167-
return status;
182+
return CLOGTransactionIdGetStatus(xid, lsn);
168183
}
169184

170185

src/backend/access/heap/heapam.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,8 +3399,6 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
33993399
TransactionId update_xact;
34003400
int remain;
34013401

3402-
*(int*)0 = 0;
3403-
34043402
if (DoesMultiXactIdConflict((MultiXactId) xwait, infomask,
34053403
*lockmode))
34063404
{
@@ -3632,6 +3630,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
36323630
newtup->t_data->t_infomask2 |= infomask2_new_tuple;
36333631
HeapTupleHeaderSetXmax(newtup->t_data, xmax_new_tuple);
36343632

3633+
#if 0
36353634
{
36363635
char buf[256];
36373636
sprintf(buf, "backend-%d.trace", getpid());
@@ -3649,6 +3648,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
36493648
fclose(f);
36503649
}
36513650
Assert(xmax_new_tuple != xid || (newtup->t_data->t_infomask & HEAP_XMAX_LOCK_ONLY) != 0);
3651+
#endif
36523652

36533653
/*
36543654
* Replace cid with a combo cid if necessary. Note that we already put

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