@@ -369,13 +369,13 @@ static int MtmConnectSocket(char const* host, int port, int max_attempts)
369369
370370static void MtmOpenConnections ()
371371{
372- int nNodes = MtmNodes ;
372+ int nNodes = MtmMaxNodes ;
373373int i ;
374374
375375sockets = (int * )palloc (sizeof (int )* nNodes );
376376
377377for (i = 0 ;i < nNodes ;i ++ ) {
378- if (i + 1 != MtmNodeId ) {
378+ if (i + 1 != MtmNodeId && i < Mtm -> nAllNodes ) {
379379sockets [i ]= MtmConnectSocket (Mtm -> nodes [i ].con .hostName ,MtmArbiterPort + i + 1 ,MtmConnectAttempts );
380380if (sockets [i ]< 0 ) {
381381MtmOnNodeDisconnect (i + 1 );
@@ -384,8 +384,8 @@ static void MtmOpenConnections()
384384sockets [i ]= -1 ;
385385}
386386}
387- if (Mtm -> nNodes < MtmNodes /2 + 1 ) {/* no quorum */
388- elog (WARNING ,"Node is out of quorum: only %d nodesfrom %d areaccssible " ,Mtm -> nNodes , MtmNodes );
387+ if (Mtm -> nLiveNodes < Mtm -> nAllNodes /2 + 1 ) {/* no quorum */
388+ elog (WARNING ,"Node is out of quorum: only %d nodesof %d areaccessible " ,Mtm -> nLiveNodes , Mtm -> nAllNodes );
389389MtmSwitchClusterMode (MTM_IN_MINORITY );
390390}else if (Mtm -> status == MTM_INITIALIZATION ) {
391391MtmSwitchClusterMode (MTM_CONNECTED );
@@ -444,7 +444,7 @@ static void MtmAcceptOneConnection()
444444elog (WARNING ,"Arbiter get unexpected handshake message %d" ,req .hdr .code );
445445close (fd );
446446}else {
447- Assert (req .hdr .node > 0 && req .hdr .node <=MtmNodes && req .hdr .node != MtmNodeId );
447+ Assert (req .hdr .node > 0 && req .hdr .node <=Mtm -> nAllNodes && req .hdr .node != MtmNodeId );
448448resp .code = MSG_STATUS ;
449449resp .disabledNodeMask = Mtm -> disabledNodeMask ;
450450resp .dxid = HANDSHAKE_MAGIC ;
@@ -472,9 +472,10 @@ static void MtmAcceptIncomingConnections()
472472struct sockaddr_in sock_inet ;
473473int on = 1 ;
474474int i ;
475+ int nNodes = MtmMaxNodes ;
475476
476- sockets = (int * )palloc (sizeof (int )* MtmNodes );
477- for (i = 0 ;i < MtmNodes ;i ++ ) {
477+ sockets = (int * )palloc (sizeof (int )* nNodes );
478+ for (i = 0 ;i < nNodes ;i ++ ) {
478479sockets [i ]= -1 ;
479480}
480481sock_inet .sin_family = AF_INET ;
@@ -490,7 +491,7 @@ static void MtmAcceptIncomingConnections()
490491if (bind (gateway , (struct sockaddr * )& sock_inet ,sizeof (sock_inet ))< 0 ) {
491492elog (ERROR ,"Arbiter failed to bind socket: %d" ,errno );
492493}
493- if (listen (gateway ,MtmNodes )< 0 ) {
494+ if (listen (gateway ,nNodes )< 0 ) {
494495elog (ERROR ,"Arbiter failed to listen socket: %d" ,errno );
495496}
496497
@@ -527,22 +528,22 @@ static void MtmBroadcastMessage(MtmBuffer* txBuffer, MtmTransState* ts)
527528{
528529int i ;
529530int n = 1 ;
530- for (i = 0 ;i < MtmNodes ;i ++ )
531+ for (i = 0 ;i < Mtm -> nAllNodes ;i ++ )
531532{
532533if (!BIT_CHECK (Mtm -> disabledNodeMask ,i )&& TransactionIdIsValid (ts -> xids [i ])) {
533534Assert (i + 1 != MtmNodeId );
534535MtmAppendBuffer (txBuffer ,ts -> xids [i ],i ,ts );
535536n += 1 ;
536537}
537538}
538- Assert (n == Mtm -> nNodes );
539+ Assert (n == Mtm -> nLiveNodes );
539540}
540541
541542
542543static void MtmTransSender (Datum arg )
543544{
544545sigset_t sset ;
545- int nNodes = MtmNodes ;
546+ int nNodes = MtmMaxNodes ;
546547int i ;
547548MtmBuffer * txBuffer = (MtmBuffer * )palloc (sizeof (MtmBuffer )* nNodes );
548549
@@ -580,7 +581,7 @@ static void MtmTransSender(Datum arg)
580581
581582MtmUnlock ();
582583
583- for (i = 0 ;i < nNodes ;i ++ ) {
584+ for (i = 0 ;i < Mtm -> nAllNodes ;i ++ ) {
584585if (txBuffer [i ].used != 0 ) {
585586MtmSendToNode (i ,txBuffer [i ].data ,txBuffer [i ].used * sizeof (MtmArbiterMessage ));
586587txBuffer [i ].used = 0 ;
@@ -593,7 +594,7 @@ static void MtmTransSender(Datum arg)
593594#if !USE_EPOLL
594595static bool MtmRecovery ()
595596{
596- int nNodes = MtmNodes ;
597+ int nNodes = Mtm -> nAllNodes ;
597598bool recovered = false;
598599int i ;
599600
@@ -618,7 +619,7 @@ static bool MtmRecovery()
618619static void MtmTransReceiver (Datum arg )
619620{
620621sigset_t sset ;
621- int nNodes = MtmNodes ;
622+ int nNodes = MtmMaxNodes ;
622623int nResponses ;
623624int i ,j ,n ,rc ;
624625MtmBuffer * rxBuffer = (MtmBuffer * )palloc (sizeof (MtmBuffer )* nNodes );
@@ -708,7 +709,7 @@ static void MtmTransReceiver(Datum arg)
708709if (MtmIsCoordinator (ts )) {
709710switch (msg -> code ) {
710711case MSG_READY :
711- Assert (ts -> nVotes < Mtm -> nNodes );
712+ Assert (ts -> nVotes < Mtm -> nLiveNodes );
712713Mtm -> nodes [msg -> node - 1 ].transDelay += MtmGetCurrentTime ()- ts -> csn ;
713714ts -> xids [msg -> node - 1 ]= msg -> sxid ;
714715
@@ -720,7 +721,7 @@ static void MtmTransReceiver(Datum arg)
720721MtmAbortTransaction (ts );
721722}
722723
723- if (++ ts -> nVotes == Mtm -> nNodes ) {
724+ if (++ ts -> nVotes == Mtm -> nLiveNodes ) {
724725/* All nodes are finished their transactions */
725726if (ts -> status == TRANSACTION_STATUS_ABORTED ) {
726727MtmWakeUpBackend (ts );
@@ -736,23 +737,23 @@ static void MtmTransReceiver(Datum arg)
736737}
737738break ;
738739case MSG_ABORTED :
739- Assert (ts -> nVotes < Mtm -> nNodes );
740+ Assert (ts -> nVotes < Mtm -> nLiveNodes );
740741if (ts -> status != TRANSACTION_STATUS_ABORTED ) {
741742Assert (ts -> status == TRANSACTION_STATUS_IN_PROGRESS );
742743MtmAbortTransaction (ts );
743744}
744- if (++ ts -> nVotes == Mtm -> nNodes ) {
745+ if (++ ts -> nVotes == Mtm -> nLiveNodes ) {
745746MtmWakeUpBackend (ts );
746747}
747748break ;
748749case MSG_PREPARED :
749750Assert (ts -> status == TRANSACTION_STATUS_IN_PROGRESS );
750- Assert (ts -> nVotes < Mtm -> nNodes );
751+ Assert (ts -> nVotes < Mtm -> nLiveNodes );
751752if (msg -> csn > ts -> csn ) {
752753ts -> csn = msg -> csn ;
753754MtmSyncClock (ts -> csn );
754755}
755- if (++ ts -> nVotes == Mtm -> nNodes ) {
756+ if (++ ts -> nVotes == Mtm -> nLiveNodes ) {
756757ts -> csn = MtmAssignCSN ();
757758ts -> status = TRANSACTION_STATUS_UNKNOWN ;
758759MtmWakeUpBackend (ts );