@@ -453,7 +453,7 @@ static void DtmPrepareTransaction(DtmCurrentTrans* x)
453453ts -> status = TRANSACTION_STATUS_UNKNOWN ;
454454ts -> csn = dtm_get_csn ();
455455ts -> procno = MyProc -> pgprocno ;
456- ts -> nVotes = 1 ;/*I voted myself */
456+ ts -> nVotes = 1 ;/*My own voice */
457457for (i = 0 ;i < MMNodes ;i ++ ) {
458458ts -> xids [i ]= InvalidTransactionId ;
459459}
@@ -479,7 +479,8 @@ static XidStatus
479479DtmCommitTransaction (TransactionId xid ,int nsubxids ,TransactionId * subxids )
480480{
481481DtmTransState * ts ;
482- csn_t csn ;
482+ csn_t localCSN ;
483+ csn_t globalCSN ;
483484int i ;
484485XidStatus status ;
485486
@@ -489,44 +490,45 @@ DtmCommitTransaction(TransactionId xid, int nsubxids, TransactionId *subxids)
489490
490491/* now transaction is in doubt state */
491492ts -> status = TRANSACTION_STATUS_IN_PROGRESS ;
492- csn = dtm_get_csn ();
493- if (csn > ts -> csn ) {
494- ts -> csn = csn ;
495- }
493+ localCSN = dtm_get_csn ();
494+ ts -> csn = localCSN ;
496495DtmTransactionListAppend (ts );
497496DtmAddSubtransactions (ts ,subxids ,nsubxids );
498497
499498MMVoteForTransaction (ts );/* wait until transaction at all nodes are prepared */
500- csn = ts -> csn ;
501- if (csn != INVALID_CSN ) {
502- dtm_sync (csn );
499+ globalCSN = ts -> csn ;
500+ Assert (globalCSN >=localCSN );
501+
502+ if (globalCSN != INVALID_CSN ) {
503+ dtm_sync (globalCSN );
503504status = TRANSACTION_STATUS_COMMITTED ;
504505}else {
506+ ts -> csn = globalCSN = localCSN ;
505507status = TRANSACTION_STATUS_ABORTED ;
506508}
507509ts -> status = status ;
508510for (i = 0 ;i < nsubxids ;i ++ ) {
509511ts = ts -> next ;
510512ts -> status = status ;
511- ts -> csn = csn ;
513+ ts -> csn = globalCSN ;
512514}
513515LWLockRelease (dtm -> hashLock );
514516return status ;
515517}
516518
517519static void
518- DtmAbortTransaction (TransactionId xid ,int nsubxids ,TransactionId * subxids )
520+ DtmFinishTransaction (TransactionId xid ,int nsubxids ,TransactionId * subxids , XidStatus status )
519521{
520522int i ;
521523DtmTransState * ts ;
522524
523525LWLockAcquire (dtm -> hashLock ,LW_EXCLUSIVE );
524526ts = hash_search (xid2state ,& xid ,HASH_FIND ,NULL );
525527Assert (ts != NULL );/* should be created by DtmPrepareTransaction */
526- ts -> status = TRANSACTION_STATUS_ABORTED ;
528+ ts -> status = status ;
527529for (i = 0 ;i < nsubxids ;i ++ ) {
528530ts = ts -> next ;
529- ts -> status = TRANSACTION_STATUS_ABORTED ;
531+ ts -> status = status ;
530532}
531533LWLockRelease (dtm -> hashLock );
532534}
@@ -539,9 +541,10 @@ DtmSetTransactionStatus(TransactionId xid, int nsubxids, TransactionId *subxids,
539541DTM_INFO ("%d: DtmSetTransactionStatus %u = %u\n" ,getpid (),xid ,status );
540542if (dtmTx .isDistributed )
541543{
544+ Assert (xid == dtmTx .xid );
542545if (status == TRANSACTION_STATUS_ABORTED || !dtmTx .containsDML )
543546{
544- DtmAbortTransaction (xid ,nsubxids ,subxids );
547+ DtmFinishTransaction (xid ,nsubxids ,subxids , status );
545548DTM_INFO ("Abort transaction %d\n" ,xid );
546549}
547550else
@@ -990,12 +993,18 @@ MMPoolConstructor(void)
990993static void
991994SendCommitMessage (DtmTransState * ts )
992995{
996+ DtmTransState * votingList ;
997+
993998SpinLockAcquire (& dtm -> votingSpinlock );
994- ts -> nextVoting = dtm -> votingTransactions ;
999+ votingList = dtm -> votingTransactions ;
1000+ ts -> nextVoting = votingList ;
9951001dtm -> votingTransactions = ts ;
9961002SpinLockRelease (& dtm -> votingSpinlock );
9971003
998- PGSemaphoreUnlock (& dtm -> votingSemaphore );
1004+ if (votingList == NULL ) {
1005+ /* singal semaphreo only once for the whole list */
1006+ PGSemaphoreUnlock (& dtm -> votingSemaphore );
1007+ }
9991008}
10001009
10011010static void
@@ -1011,7 +1020,7 @@ MMVoteForTransaction(DtmTransState* ts)
10111020/* ... and then send notifications to replicas */
10121021SendCommitMessage (ts );
10131022}else {
1014- /* I am replica: first notifymaster ... */
1023+ /* I am replica: first notifycoordinator ... */
10151024ts -> nVotes = dtm -> nNodes - 1 ;/* I just need one confirmation from coordinator */
10161025SendCommitMessage (ts );
10171026/* ... and wait response from it */