Skip to content

Commit 9984931

Browse files
committed
Fix bug in DtmAdjustOldestXid
1 parent c864a2a commit 9984931

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

contrib/pg_tsdtm/pg_dtm.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ typedef struct
6363
} DtmTransId;
6464

6565

66-
//#define DTM_TRACE(x)
67-
#define DTM_TRACE(x) fprintf x
66+
#define DTM_TRACE(x)
67+
//#define DTM_TRACE(x) fprintf x
6868

6969
static shmem_startup_hook_type prev_shmem_startup_hook;
7070
static HTAB* xid2status;
@@ -290,7 +290,7 @@ dtm_extend(PG_FUNCTION_ARGS)
290290
{
291291
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
292292
cid_t cid = DtmLocalExtend(&dtm_tx, gtid);
293-
DTM_TRACE((stderr, "Backend %d extends transaction %u(%s) to global with cid=%llu\n", getpid(), dtm_tx.xid, gtid, cid));
293+
DTM_TRACE((stderr, "Backend %d extends transaction %u(%s) to global with cid=%lu\n", getpid(), dtm_tx.xid, gtid, cid));
294294
PG_RETURN_INT64(cid);
295295
}
296296

@@ -299,7 +299,7 @@ dtm_access(PG_FUNCTION_ARGS)
299299
{
300300
cid_t cid = PG_GETARG_INT64(0);
301301
GlobalTransactionId gtid = PG_GETARG_CSTRING(1);
302-
DTM_TRACE((stderr, "Backend %d joins transaction %u(%s) with cid=%llu\n", getpid(), dtm_tx.xid, gtid, cid));
302+
DTM_TRACE((stderr, "Backend %d joins transaction %u(%s) with cid=%lu\n", getpid(), dtm_tx.xid, gtid, cid));
303303
cid = DtmLocalAccess(&dtm_tx, gtid, cid);
304304
PG_RETURN_INT64(cid);
305305
}
@@ -320,7 +320,7 @@ dtm_prepare(PG_FUNCTION_ARGS)
320320
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
321321
cid_t cid = PG_GETARG_INT64(1);
322322
cid = DtmLocalPrepare(gtid, cid);
323-
DTM_TRACE((stderr, "Backend %d prepares transaction %s with cid=%llu\n", getpid(), gtid, cid));
323+
DTM_TRACE((stderr, "Backend %d prepares transaction %s with cid=%lu\n", getpid(), gtid, cid));
324324
PG_RETURN_INT64(cid);
325325
}
326326

@@ -329,7 +329,7 @@ dtm_end_prepare(PG_FUNCTION_ARGS)
329329
{
330330
GlobalTransactionId gtid = PG_GETARG_CSTRING(0);
331331
cid_t cid = PG_GETARG_INT64(1);
332-
DTM_TRACE((stderr, "Backend %d ends prepare of transactions %s with cid=%llu\n", getpid(), gtid, cid));
332+
DTM_TRACE((stderr, "Backend %d ends prepare of transactions %s with cid=%lu\n", getpid(), gtid, cid));
333333
DtmLocalEndPrepare(gtid, cid);
334334
PG_RETURN_VOID();
335335
}
@@ -377,7 +377,8 @@ static TransactionId DtmAdjustOldestXid(TransactionId xid)
377377
ts = (DtmTransStatus*)hash_search(xid2status, &xid, HASH_FIND, NULL);
378378
if (ts == NULL || ts->cid + DtmVacuumDelay*USEC > dtm_get_current_time()) {
379379
xid = DtmOldestXid;
380-
} else if (ts->cid > DtmOldestCid) {
380+
} else /*if (ts->cid > DtmOldestCid)*/ {
381+
DTM_TRACE(("Set new oldest xid=%u csn=%lu now=%lu\n", xid, ts->cid, dtm_get_current_time()));
381382
DtmOldestXid = xid;
382383
DtmOldestCid = ts->cid;
383384
}
@@ -421,7 +422,7 @@ bool DtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
421422
}
422423
if (ts->status == TRANSACTION_STATUS_IN_PROGRESS)
423424
{
424-
DTM_TRACE((stderr, "%d: wait for in-doubt transaction %u in snapshot %llu\n", getpid(), xid, dtm_tx.snapshot));
425+
DTM_TRACE((stderr, "%d: wait for in-doubt transaction %u in snapshot %lu\n", getpid(), xid, dtm_tx.snapshot));
425426
SpinLockRelease(&local->lock);
426427
dtm_sleep(delay);
427428
if (delay*2 <= MAX_WAIT_TIMEOUT) {
@@ -440,7 +441,7 @@ bool DtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
440441
}
441442
else
442443
{
443-
DTM_TRACE((stderr, "%d: visibility check is skept for transaction %u in snapshot %llu\n", getpid(), xid, dtm_tx.snapshot));
444+
DTM_TRACE((stderr, "%d: visibility check is skept for transaction %u in snapshot %lu\n", getpid(), xid, dtm_tx.snapshot));
444445
break;
445446
}
446447
}
@@ -498,7 +499,7 @@ void DtmLocalBegin(DtmTransState* x)
498499
x->is_prepared = false;
499500
x->snapshot = dtm_get_cid();
500501
SpinLockRelease(&local->lock);
501-
DTM_TRACE((stderr, "DtmLocalBegin: transaction %u uses local snapshot %llu\n", x->xid, x->snapshot));
502+
DTM_TRACE((stderr, "DtmLocalBegin: transaction %u uses local snapshot %lu\n", x->xid, x->snapshot));
502503
}
503504
}
504505

@@ -581,7 +582,7 @@ void DtmLocalEndPrepare(GlobalTransactionId gtid, cid_t cid)
581582

582583
dtm_sync(cid);
583584

584-
DTM_TRACE((stderr, "Prepare transaction %u(%s) with CSN %llu\n", id->xid, gtid, cid));
585+
DTM_TRACE((stderr, "Prepare transaction %u(%s) with CSN %lu\n", id->xid, gtid, cid));
585586
}
586587
SpinLockRelease(&local->lock);
587588
}
@@ -618,7 +619,7 @@ void DtmLocalCommit(DtmTransState* x)
618619
}
619620
x->cid = ts->cid;
620621
ts->status = TRANSACTION_STATUS_COMMITTED;
621-
DTM_TRACE((stderr, "Local transaction %u is committed at %llu\n", x->xid, x->cid));
622+
DTM_TRACE((stderr, "Local transaction %u is committed at %lu\n", x->xid, x->cid));
622623
}
623624
SpinLockRelease(&local->lock);
624625
}
@@ -656,7 +657,7 @@ void DtmLocalAbort(DtmTransState* x)
656657
}
657658
x->cid = ts->cid;
658659
ts->status = TRANSACTION_STATUS_ABORTED;
659-
DTM_TRACE((stderr, "Local transaction %u is aborted at %llu\n", x->xid, x->cid));
660+
DTM_TRACE((stderr, "Local transaction %u is aborted at %lu\n", x->xid, x->cid));
660661
}
661662
SpinLockRelease(&local->lock);
662663
}

contrib/pg_tsdtm/pg_dtm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define DTM_BACKEND_H
33

44
typedef int nodeid_t;
5-
typedef unsigned long long cid_t;
5+
typedef uint64 cid_t;
66

77
typedef struct {
88
TransactionId xid;

contrib/pg_tsdtm/tests/transfers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
const (
12-
TRANSFER_CONNECTIONS = 2
12+
TRANSFER_CONNECTIONS = 8
1313
INIT_AMOUNT = 10000
1414
N_ITERATIONS = 10000
1515
N_ACCOUNTS = 2//100000

0 commit comments

Comments
 (0)