Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb79402a

Browse files
committed
WIP revork DtmAdjustOldestXid; it is okay to ignore slot_xmin, but we should wait for long-lived tx
1 parente14e2f9 commitb79402a

File tree

1 file changed

+57
-31
lines changed

1 file changed

+57
-31
lines changed

‎src/backend/access/transam/global_snapshot.c

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ static HTAB *xid2status;
8989
staticHTAB*gtid2xid;
9090
staticDtmNodeState*local;
9191
staticuint64totalSleepInterrupts;
92-
staticintDtmVacuumDelay=10;
92+
staticintDtmVacuumDelay=2;/* sec */
9393
staticboolDtmRecordCommits=0;
9494

9595
DtmCurrentTransdtm_tx;// XXXX: make static
9696

9797
staticSnapshotDtmGetSnapshot(Snapshotsnapshot);
9898
staticTransactionIdDtmGetOldestXmin(Relationrel,intflags);
9999
staticboolDtmXidInMVCCSnapshot(TransactionIdxid,Snapshotsnapshot);
100-
staticTransactionIdDtmAdjustOldestXid(TransactionIdxid);
100+
staticvoidDtmAdjustOldestXid(void);
101101
staticboolDtmDetectGlobalDeadLock(PGPROC*proc);
102102
staticvoidDtmAddSubtransactions(DtmTransStatus*ts,TransactionId*subxids,intnSubxids);
103103
staticcharconst*DtmGetName(void);
@@ -325,47 +325,58 @@ DtmTransactionListInsertAfter(DtmTransStatus * after, DtmTransStatus * ts)
325325
* is older than it more than DtmVacuumDelay.
326326
* If no such XID can be located, then return previously observed oldest XID
327327
*/
328-
staticTransactionId
329-
DtmAdjustOldestXid(TransactionIdxid)
328+
staticvoid
329+
DtmAdjustOldestXid()
330330
{
331-
if (TransactionIdIsValid(xid))
332-
{
333-
DtmTransStatus*ts,
334-
*prev=NULL;
335-
timestamp_tnow=dtm_get_current_time();
336-
timestamp_tcutoff_time=now-DtmVacuumDelay*USEC;
331+
DtmTransStatus*ts,
332+
*prev=NULL;
337333

338-
SpinLockAcquire(&local->lock);
339-
ts= (DtmTransStatus*)hash_search(xid2status,&xid,HASH_FIND,NULL);
340-
if (ts!=NULL)
341-
{
342-
cutoff_time=ts->cid-DtmVacuumDelay*USEC;
334+
timestamp_tcutoff_time=dtm_get_current_time()-DtmVacuumDelay*USEC;
335+
inttotal=0,deleted=0;
343336

344-
for (ts=local->trans_list_head;ts!=NULL&&ts->cid<cutoff_time;prev=ts,ts=ts->next)
345-
{
346-
if (prev!=NULL)
347-
hash_search(xid2status,&prev->xid,HASH_REMOVE,NULL);
348-
}
349-
}
337+
SpinLockAcquire(&local->lock);
338+
339+
for (ts=local->trans_list_head;ts!=NULL;ts=ts->next)
340+
total++;
341+
342+
for (ts=local->trans_list_head;ts!=NULL&&ts->cid<cutoff_time;prev=ts,ts=ts->next)
343+
{
350344
if (prev!=NULL)
351345
{
352-
local->trans_list_head=prev;
353-
local->oldest_xid=xid=prev->xid;
346+
hash_search(xid2status,&prev->xid,HASH_REMOVE,NULL);
347+
deleted++;
354348
}
355-
else
356-
{
357-
xid=local->oldest_xid;
358-
}
359-
SpinLockRelease(&local->lock);
360349
}
361-
returnxid;
350+
351+
if (prev!=NULL)
352+
local->trans_list_head=prev;
353+
354+
if (ts!=NULL)
355+
local->oldest_xid=ts->xid;
356+
else
357+
local->oldest_xid=InvalidTransactionId;
358+
359+
SpinLockRelease(&local->lock);
360+
361+
// elog(LOG, "DtmAdjustOldestXid total=%d, deleted=%d, xid=%d, prev=%p, ts=%p", total, deleted, local->oldest_xid, prev, ts);
362362
}
363363

364364
Snapshot
365365
DtmGetSnapshot(Snapshotsnapshot)
366366
{
367367
snapshot=PgGetSnapshotData(snapshot);
368-
RecentGlobalDataXmin=RecentGlobalXmin=DtmAdjustOldestXid(RecentGlobalDataXmin);
368+
// RecentGlobalDataXmin = RecentGlobalXmin = DtmAdjustOldestXid(RecentGlobalDataXmin);
369+
SpinLockAcquire(&local->lock);
370+
371+
if (TransactionIdIsValid(local->oldest_xid)&&
372+
TransactionIdPrecedes(local->oldest_xid,RecentGlobalXmin))
373+
RecentGlobalXmin=local->oldest_xid;
374+
375+
if (TransactionIdIsValid(local->oldest_xid)&&
376+
TransactionIdPrecedes(local->oldest_xid,RecentGlobalDataXmin))
377+
RecentGlobalDataXmin=local->oldest_xid;
378+
379+
SpinLockRelease(&local->lock);
369380
returnsnapshot;
370381
}
371382

@@ -374,7 +385,16 @@ DtmGetOldestXmin(Relation rel, int flags)
374385
{
375386
TransactionIdxmin=PgGetOldestXmin(rel,flags);
376387

377-
xmin=DtmAdjustOldestXid(xmin);
388+
// xmin = DtmAdjustOldestXid(xmin);
389+
390+
SpinLockAcquire(&local->lock);
391+
392+
if (TransactionIdIsValid(local->oldest_xid)&&
393+
TransactionIdPrecedes(local->oldest_xid,xmin))
394+
xmin=local->oldest_xid;
395+
396+
SpinLockRelease(&local->lock);
397+
378398
returnxmin;
379399
}
380400

@@ -670,6 +690,9 @@ DtmLocalCommitPrepared(DtmCurrentTrans * x)
670690
DTM_TRACE((stderr,"Global transaction %u(%s) is precommitted\n",x->xid,gtid));
671691
}
672692
SpinLockRelease(&local->lock);
693+
694+
DtmAdjustOldestXid();
695+
// elog(LOG, "DtmLocalCommitPrepared %d", x->xid);
673696
}
674697

675698
/*
@@ -717,6 +740,9 @@ DtmLocalCommit(DtmCurrentTrans * x)
717740
DTM_TRACE((stderr,"Local transaction %u is committed at %lu\n",x->xid,x->cid));
718741
}
719742
SpinLockRelease(&local->lock);
743+
744+
DtmAdjustOldestXid();
745+
// elog(LOG, "DtmLocalCommit %d", x->xid);
720746
}
721747

722748
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp