@@ -72,8 +72,8 @@ typedef struct
72
72
} DtmTransId ;
73
73
74
74
75
- #define DTM_TRACE (x )
76
- // #define DTM_TRACE(x) fprintf x
75
+ // #define DTM_TRACE(x)
76
+ #define DTM_TRACE (x ) fprintf x
77
77
78
78
static shmem_startup_hook_type prev_shmem_startup_hook ;
79
79
static HTAB * xid2status ;
@@ -602,10 +602,10 @@ void DtmInitialize()
602
602
603
603
void DtmLocalBegin (DtmCurrentTrans * x )
604
604
{
605
- if (x -> xid == InvalidTransactionId ) {
605
+ if (! TransactionIdIsValid ( x -> xid ) ) {
606
606
SpinLockAcquire (& local -> lock );
607
607
x -> xid = GetCurrentTransactionId ();
608
- Assert (x -> xid != InvalidTransactionId );
608
+ Assert (TransactionIdIsValid ( x -> xid ) );
609
609
x -> cid = INVALID_CID ;
610
610
x -> is_global = false;
611
611
x -> is_prepared = false;
@@ -648,7 +648,7 @@ cid_t DtmLocalAccess(DtmCurrentTrans* x, GlobalTransactionId gtid, cid_t global_
648
648
}
649
649
SpinLockRelease (& local -> lock );
650
650
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 );
652
652
}
653
653
return global_cid ;
654
654
}
@@ -662,7 +662,7 @@ void DtmLocalBeginPrepare(GlobalTransactionId gtid)
662
662
663
663
id = (DtmTransId * )hash_search (gtid2xid , gtid , HASH_FIND , NULL );
664
664
Assert (id != NULL );
665
-
665
+ Assert ( TransactionIdIsValid ( id -> xid ));
666
666
ts = (DtmTransStatus * )hash_search (xid2status , & id -> xid , HASH_ENTER , NULL );
667
667
ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
668
668
ts -> cid = dtm_get_cid ();
@@ -743,9 +743,11 @@ void DtmLocalCommitPrepared(DtmCurrentTrans* x, GlobalTransactionId gtid)
743
743
void DtmLocalCommit (DtmCurrentTrans * x )
744
744
{
745
745
SpinLockAcquire (& local -> lock );
746
+ if (TransactionIdIsValid (x -> xid ))
746
747
{
747
748
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 );
749
751
ts -> status = TRANSACTION_STATUS_COMMITTED ;
750
752
if (x -> is_prepared ) {
751
753
int i ;
@@ -795,7 +797,9 @@ void DtmLocalAbort(DtmCurrentTrans* x)
795
797
SpinLockAcquire (& local -> lock );
796
798
{
797
799
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 );
799
803
if (x -> is_prepared ) {
800
804
Assert (found );
801
805
Assert (x -> is_global );
@@ -865,7 +869,9 @@ static void DtmAddSubtransactions(DtmTransStatus* ts, TransactionId* subxids, in
865
869
int i ;
866
870
for (i = 0 ; i < nSubxids ; i ++ ) {
867
871
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 );
869
875
Assert (!found );
870
876
sts -> status = ts -> status ;
871
877
sts -> cid = ts -> cid ;
0 commit comments