@@ -295,7 +295,7 @@ static void DtmUpdateRecentXmin(Snapshot snapshot)
295295 */
296296static TransactionId DtmGetNextXid ()
297297{
298- TransactionId xid ;
298+ TransactionId xid = InvalidTransactionId ;
299299 LWLockAcquire (dtm -> xidLock , LW_EXCLUSIVE );
300300 if (TransactionIdIsValid (DtmNextXid ))
301301 {
@@ -321,7 +321,12 @@ static TransactionId DtmGetNextXid()
321321 if (dtm -> nReservedXids == 0 )
322322 {
323323 dtm -> nReservedXids = DtmGlobalReserve (ShmemVariableCache -> nextXid , DtmLocalXidReserve , & dtm -> nextXid );
324- Assert (dtm -> nReservedXids > 0 );
324+ if (dtm -> nReservedXids < 1 )
325+ {
326+ elog (WARNING , "failed to reserve a local range of xids on arbiter" );
327+ goto end ;
328+ }
329+
325330 Assert (TransactionIdFollowsOrEquals (dtm -> nextXid , ShmemVariableCache -> nextXid ));
326331
327332 /* Advance ShmemVariableCache->nextXid formward until new Xid */
@@ -339,6 +344,7 @@ static TransactionId DtmGetNextXid()
339344 dtm -> nReservedXids -= 1 ;
340345 XTM_INFO ("Obtain new local XID %d\n" , xid );
341346 }
347+ end :
342348 LWLockRelease (dtm -> xidLock );
343349 return xid ;
344350}
@@ -387,6 +393,8 @@ DtmGetNewTransactionId(bool isSubXact)
387393
388394 LWLockAcquire (XidGenLock , LW_EXCLUSIVE );
389395 xid = DtmGetNextXid ();
396+ if (!TransactionIdIsValid (xid ))
397+ elog (ERROR , "failed to get next xid from XTM" );
390398
391399 /*----------
392400 * Check to see if it's safe to assign another XID. This protects against
@@ -620,7 +628,11 @@ static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, Transaction
620628 if (status == TRANSACTION_STATUS_ABORTED )
621629 {
622630 PgTransactionIdSetTreeStatus (xid , nsubxids , subxids , status , lsn );
623- DtmGlobalSetTransStatus (xid , status , false);
631+ if (DtmGlobalSetTransStatus (xid , status , false) == -1 )
632+ {
633+ elog (WARNING , "failed to set 'aborted' transaction status on arbiter" );
634+ return ; // FIXME: return bool
635+ }
624636 XTM_INFO ("Abort transaction %d\n" , xid );
625637 return ;
626638 }
@@ -631,7 +643,11 @@ static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, Transaction
631643 LWLockAcquire (dtm -> hashLock , LW_EXCLUSIVE );
632644 hash_search (xid_in_doubt , & DtmNextXid , HASH_ENTER , NULL );
633645 LWLockRelease (dtm -> hashLock );
634- DtmGlobalSetTransStatus (xid , status , true);
646+ if (DtmGlobalSetTransStatus (xid , status , true) == -1 )
647+ {
648+ elog (WARNING , "failed to set 'committed' transaction status on arbiter" );
649+ return ; // FIXME: return bool
650+ }
635651 XTM_INFO ("Commit transaction %d\n" , xid );
636652 }
637653 }
@@ -648,6 +664,7 @@ static void DtmSetTransactionStatus(TransactionId xid, int nsubxids, Transaction
648664 status = gs ;
649665 }
650666 PgTransactionIdSetTreeStatus (xid , nsubxids , subxids , status , lsn );
667+ // FIXME: return bool
651668}
652669
653670static uint32 dtm_xid_hash_fn (const void * key , Size keysize )
0 commit comments