1616#include "storage/s_lock.h"
1717#include "storage/spin.h"
1818#include "storage/lmgr.h"
19+ #include "storage/procarray.h"
1920#include "storage/shmem.h"
2021#include "storage/ipc.h"
2122#include "access/xlogdefs.h"
@@ -60,8 +61,6 @@ typedef struct
6061{
6162 cid_t cid ; /* last assigned CSN; used to provide unique
6263 * ascending CSNs */
63- TransactionId oldest_xid ; /* XID of oldest transaction visible by any
64- * active transaction (local or global) */
6564 long time_shift ; /* correction to system time */
6665 volatile slock_t lock ; /* spinlock to protect access to hash table */
6766 DtmTransStatus * trans_list_head ; /* L1 list of finished transactions
@@ -94,8 +93,6 @@ static bool DtmRecordCommits = 0;
9493
9594DtmCurrentTrans dtm_tx ; // XXXX: make static
9695
97- static Snapshot DtmGetSnapshot (Snapshot snapshot );
98- static TransactionId DtmGetOldestXmin (Relation rel , int flags );
9996static bool DtmXidInMVCCSnapshot (TransactionId xid , Snapshot snapshot );
10097static void DtmAdjustOldestXid (void );
10198static bool DtmDetectGlobalDeadLock (PGPROC * proc );
@@ -109,9 +106,9 @@ static void DtmDeserializeTransactionState(void* ctx);
109106static TransactionManager DtmTM = {
110107 PgTransactionIdGetStatus ,
111108 PgTransactionIdSetTreeStatus ,
112- DtmGetSnapshot ,
109+ PgGetSnapshotData ,
113110 PgGetNewTransactionId ,
114- DtmGetOldestXmin ,
111+ PgGetOldestXmin ,
115112 PgTransactionIdIsInProgress ,
116113 PgGetGlobalTransactionId ,
117114 DtmXidInMVCCSnapshot ,
@@ -331,16 +328,16 @@ static void
331328DtmAdjustOldestXid ()
332329{
333330 DtmTransStatus * ts ,
334- * prev = NULL ;
331+ * prev = NULL ;
332+ timestamp_t cutoff_time ;
333+ TransactionId oldest_xid = InvalidTransactionId ;
334+ int total = 0 ,
335+ deleted = 0 ;
335336
336- timestamp_t cutoff_time = dtm_get_current_time () - DtmVacuumDelay * USEC ;
337- int total = 0 , deleted = 0 ;
337+ cutoff_time = dtm_get_current_time () - DtmVacuumDelay * USEC ;
338338
339339 SpinLockAcquire (& local -> lock );
340340
341- for (ts = local -> trans_list_head ; ts != NULL ; ts = ts -> next )
342- total ++ ;
343-
344341 for (ts = local -> trans_list_head ; ts != NULL && ts -> cid < cutoff_time ; prev = ts , ts = ts -> next )
345342 {
346343 if (prev != NULL )
@@ -353,53 +350,24 @@ DtmAdjustOldestXid()
353350 if (prev != NULL )
354351 local -> trans_list_head = prev ;
355352
356- if (ts != NULL )
357- local -> oldest_xid = ts -> xid ;
358- else
359- local -> oldest_xid = InvalidTransactionId ;
353+ if (local -> trans_list_head )
354+ oldest_xid = local -> trans_list_head -> xid ;
360355
361- SpinLockRelease (& local -> lock );
362-
363- // elog(LOG, "DtmAdjustOldestXid total=%d, deleted=%d, xid=%d, prev=%p, ts=%p", total, deleted, local->oldest_xid, prev, ts);
364- }
365-
366- Snapshot
367- DtmGetSnapshot (Snapshot snapshot )
368- {
369- snapshot = PgGetSnapshotData (snapshot );
370- // RecentGlobalDataXmin = RecentGlobalXmin = DtmAdjustOldestXid(RecentGlobalDataXmin);
371- SpinLockAcquire (& local -> lock );
372-
373- if (TransactionIdIsValid (local -> oldest_xid ) &&
374- TransactionIdPrecedes (local -> oldest_xid , RecentGlobalXmin ))
375- RecentGlobalXmin = local -> oldest_xid ;
376-
377- if (TransactionIdIsValid (local -> oldest_xid ) &&
378- TransactionIdPrecedes (local -> oldest_xid , RecentGlobalDataXmin ))
379- RecentGlobalDataXmin = local -> oldest_xid ;
356+ for (ts = local -> trans_list_head ; ts != NULL ; ts = ts -> next )
357+ {
358+ if (TransactionIdPrecedes (ts -> xid , oldest_xid ))
359+ oldest_xid = ts -> xid ;
360+ total ++ ;
361+ }
380362
381363 SpinLockRelease (& local -> lock );
382- return snapshot ;
383- }
384-
385- TransactionId
386- DtmGetOldestXmin (Relation rel , int flags )
387- {
388- TransactionId xmin = PgGetOldestXmin (rel , flags );
389364
390- // xmin = DtmAdjustOldestXid(xmin );
365+ ProcArraySetGlobalSnapshotXmin ( oldest_xid );
391366
392- SpinLockAcquire (& local -> lock );
393-
394- if (TransactionIdIsValid (local -> oldest_xid ) &&
395- TransactionIdPrecedes (local -> oldest_xid , xmin ))
396- xmin = local -> oldest_xid ;
397-
398- SpinLockRelease (& local -> lock );
399-
400- return xmin ;
367+ // elog(LOG, "DtmAdjustOldestXid total=%d, deleted=%d, xid=%d, prev=%p, ts=%p", total, deleted, oldest_xid, prev, ts);
401368}
402369
370+
403371/*
404372 * Check tuple bisibility based on CSN of current transaction.
405373 * If there is no niformation about transaction with this XID, then use standard PostgreSQL visibility rules.
@@ -489,7 +457,6 @@ DtmInitialize()
489457 if (!found )
490458 {
491459 local -> time_shift = 0 ;
492- local -> oldest_xid = FirstNormalTransactionId ;
493460 local -> cid = dtm_get_current_time ();
494461 local -> trans_list_head = NULL ;
495462 local -> trans_list_tail = & local -> trans_list_head ;
0 commit comments