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 ,
@@ -329,16 +326,16 @@ static void
329326DtmAdjustOldestXid ()
330327{
331328 DtmTransStatus * ts ,
332- * prev = NULL ;
329+ * prev = NULL ;
330+ timestamp_t cutoff_time ;
331+ TransactionId oldest_xid = InvalidTransactionId ;
332+ int total = 0 ,
333+ deleted = 0 ;
333334
334- timestamp_t cutoff_time = dtm_get_current_time () - DtmVacuumDelay * USEC ;
335- int total = 0 , deleted = 0 ;
335+ cutoff_time = dtm_get_current_time () - DtmVacuumDelay * USEC ;
336336
337337 SpinLockAcquire (& local -> lock );
338338
339- for (ts = local -> trans_list_head ; ts != NULL ; ts = ts -> next )
340- total ++ ;
341-
342339 for (ts = local -> trans_list_head ; ts != NULL && ts -> cid < cutoff_time ; prev = ts , ts = ts -> next )
343340 {
344341 if (prev != NULL )
@@ -351,53 +348,24 @@ DtmAdjustOldestXid()
351348 if (prev != NULL )
352349 local -> trans_list_head = prev ;
353350
354- if (ts != NULL )
355- local -> oldest_xid = ts -> xid ;
356- else
357- local -> oldest_xid = InvalidTransactionId ;
351+ if (local -> trans_list_head )
352+ oldest_xid = local -> trans_list_head -> xid ;
358353
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);
362- }
363-
364- Snapshot
365- DtmGetSnapshot (Snapshot snapshot )
366- {
367- snapshot = PgGetSnapshotData (snapshot );
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 ;
354+ for (ts = local -> trans_list_head ; ts != NULL ; ts = ts -> next )
355+ {
356+ if (TransactionIdPrecedes (ts -> xid , oldest_xid ))
357+ oldest_xid = ts -> xid ;
358+ total ++ ;
359+ }
378360
379361 SpinLockRelease (& local -> lock );
380- return snapshot ;
381- }
382-
383- TransactionId
384- DtmGetOldestXmin (Relation rel , int flags )
385- {
386- TransactionId xmin = PgGetOldestXmin (rel , flags );
387362
388- // xmin = DtmAdjustOldestXid(xmin );
363+ ProcArraySetGlobalSnapshotXmin ( oldest_xid );
389364
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-
398- return xmin ;
365+ // elog(LOG, "DtmAdjustOldestXid total=%d, deleted=%d, xid=%d, prev=%p, ts=%p", total, deleted, oldest_xid, prev, ts);
399366}
400367
368+
401369/*
402370 * Check tuple bisibility based on CSN of current transaction.
403371 * If there is no niformation about transaction with this XID, then use standard PostgreSQL visibility rules.
@@ -487,7 +455,6 @@ DtmInitialize()
487455 if (!found )
488456 {
489457 local -> time_shift = 0 ;
490- local -> oldest_xid = FirstNormalTransactionId ;
491458 local -> cid = dtm_get_current_time ();
492459 local -> trans_list_head = NULL ;
493460 local -> trans_list_tail = & local -> trans_list_head ;
0 commit comments