Skip to content

Commit 3a1937d

Browse files
committed
Fix calculation of cutoff interval
1 parent 663c650 commit 3a1937d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

contrib/pg_tsdtm/pg_dtm.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static cid_t dtm_sync(cid_t global_cid)
164164
dtm_sleep(global_cid - local_cid);
165165
#if TRACE_SLEEP_TIME
166166
totalSleepTime += dtm_get_current_time() - now;
167-
if (now > prevReportTime + USEC*10) {
167+
if (now > prevReportTime + USEC) {
168168
prevReportTime = now;
169169
if (firstReportTime == 0) {
170170
firstReportTime = now;
@@ -445,17 +445,20 @@ static TransactionId DtmAdjustOldestXid(TransactionId xid)
445445
{
446446
if (TransactionIdIsValid(xid)) {
447447
DtmTransStatus *ts, *prev = NULL;
448-
timestamp_t cutoff_time = dtm_get_current_time() - DtmVacuumDelay*USEC;
448+
timestamp_t now = dtm_get_current_time();
449+
timestamp_t cutoff_time = now - DtmVacuumDelay*USEC;
449450
SpinLockAcquire(&local->lock);
450451
ts = (DtmTransStatus*)hash_search(xid2status, &xid, HASH_FIND, NULL);
451452
if (ts != NULL) {
452453
cutoff_time = ts->cid - DtmVacuumDelay*USEC;
453-
}
454-
for (ts = local->trans_list_head; ts != NULL && ts->cid < cutoff_time; prev = ts, ts = ts->next) {
455-
if (prev != NULL) {
456-
hash_search(xid2status, &prev->xid, HASH_REMOVE, NULL);
457-
}
458-
}
454+
455+
for (ts = local->trans_list_head; ts != NULL && ts->cid < cutoff_time; prev = ts, ts = ts->next) {
456+
if (prev != NULL) {
457+
/* intf(stderr, "Remove xid %d from hash at %lu\n", prev->xid, now); */
458+
hash_search(xid2status, &prev->xid, HASH_REMOVE, NULL);
459+
}
460+
}
461+
}
459462
if (prev != NULL) {
460463
local->trans_list_head = prev;
461464
xid = prev->xid;
@@ -487,7 +490,7 @@ bool DtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
487490
static timestamp_t firstReportTime;
488491
static timestamp_t prevReportTime;
489492
static timestamp_t totalSleepTime;
490-
static timestamp_t maxSleepTime;
493+
static timestamp_t mnxSleepTime;
491494
#endif
492495
timestamp_t delay = MIN_WAIT_TIMEOUT;
493496
Assert(xid != InvalidTransactionId);

0 commit comments

Comments
 (0)