@@ -72,8 +72,8 @@ typedef struct
7272} DtmTransId ;
7373
7474
75- #define DTM_TRACE (x )
76- // #define DTM_TRACE(x) fprintf x
75+ // #define DTM_TRACE(x)
76+ #define DTM_TRACE (x ) fprintf x
7777
7878static shmem_startup_hook_type prev_shmem_startup_hook ;
7979static HTAB * xid2status ;
@@ -602,10 +602,10 @@ void DtmInitialize()
602602
603603void DtmLocalBegin (DtmCurrentTrans * x )
604604{
605- if (x -> xid == InvalidTransactionId ) {
605+ if (! TransactionIdIsValid ( x -> xid ) ) {
606606 SpinLockAcquire (& local -> lock );
607607 x -> xid = GetCurrentTransactionId ();
608- Assert (x -> xid != InvalidTransactionId );
608+ Assert (TransactionIdIsValid ( x -> xid ) );
609609 x -> cid = INVALID_CID ;
610610 x -> is_global = false;
611611 x -> is_prepared = false;
@@ -648,7 +648,7 @@ cid_t DtmLocalAccess(DtmCurrentTrans* x, GlobalTransactionId gtid, cid_t global_
648648 }
649649 SpinLockRelease (& local -> lock );
650650 if (global_cid < local_cid - DtmVacuumDelay * USEC ) {
651- elog (ERROR , "Too old snapshot" );
651+ elog (ERROR , "Too old snapshot: requested %ld, current %ld" , global_cid , local_cid );
652652 }
653653 return global_cid ;
654654}
@@ -662,7 +662,7 @@ void DtmLocalBeginPrepare(GlobalTransactionId gtid)
662662
663663 id = (DtmTransId * )hash_search (gtid2xid , gtid , HASH_FIND , NULL );
664664 Assert (id != NULL );
665-
665+ Assert ( TransactionIdIsValid ( id -> xid ));
666666 ts = (DtmTransStatus * )hash_search (xid2status , & id -> xid , HASH_ENTER , NULL );
667667 ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
668668 ts -> cid = dtm_get_cid ();
@@ -743,9 +743,11 @@ void DtmLocalCommitPrepared(DtmCurrentTrans* x, GlobalTransactionId gtid)
743743void DtmLocalCommit (DtmCurrentTrans * x )
744744{
745745 SpinLockAcquire (& local -> lock );
746+ if (TransactionIdIsValid (x -> xid ))
746747 {
747748 bool found ;
748- DtmTransStatus * ts = (DtmTransStatus * )hash_search (xid2status , & x -> xid , HASH_ENTER , & found );
749+ DtmTransStatus * ts ;
750+ ts = (DtmTransStatus * )hash_search (xid2status , & x -> xid , HASH_ENTER , & found );
749751 ts -> status = TRANSACTION_STATUS_COMMITTED ;
750752 if (x -> is_prepared ) {
751753 int i ;
@@ -795,7 +797,9 @@ void DtmLocalAbort(DtmCurrentTrans* x)
795797 SpinLockAcquire (& local -> lock );
796798 {
797799 bool found ;
798- DtmTransStatus * ts = (DtmTransStatus * )hash_search (xid2status , & x -> xid , HASH_ENTER , & found );
800+ DtmTransStatus * ts ;
801+ Assert (TransactionIdIsValid (x -> xid ));
802+ ts = (DtmTransStatus * )hash_search (xid2status , & x -> xid , HASH_ENTER , & found );
799803 if (x -> is_prepared ) {
800804 Assert (found );
801805 Assert (x -> is_global );
@@ -865,7 +869,9 @@ static void DtmAddSubtransactions(DtmTransStatus* ts, TransactionId* subxids, in
865869 int i ;
866870 for (i = 0 ; i < nSubxids ; i ++ ) {
867871 bool found ;
868- DtmTransStatus * sts = (DtmTransStatus * )hash_search (xid2status , & subxids [i ], HASH_ENTER , & found );
872+ DtmTransStatus * sts ;
873+ Assert (TransactionIdIsValid (subxids [i ]));
874+ sts = (DtmTransStatus * )hash_search (xid2status , & subxids [i ], HASH_ENTER , & found );
869875 Assert (!found );
870876 sts -> status = ts -> status ;
871877 sts -> cid = ts -> cid ;
0 commit comments