@@ -1040,15 +1040,19 @@ protected Status getNextStatusOnDisconnection(Host host, final Status.Event even
10401040
10411041 protected boolean handleDisconnectWithoutInvestigation (final AgentAttache attache , final Status .Event event , final boolean transitState , final boolean removeAgent ) {
10421042 final long hostId = attache .getId ();
1043-
1043+ final HostVO host = _hostDao . findById ( hostId );
10441044 boolean result = false ;
10451045 GlobalLock joinLock = getHostJoinLock (hostId );
1046- if (joinLock .lock (60 )) {
1046+ try {
1047+ if (!joinLock .lock (60 )) {
1048+ logger .debug ("Unable to acquire lock on host {} to process agent disconnection" , host != null ? host : hostId );
1049+ return result ;
1050+ }
1051+
1052+ logger .debug ("Acquired lock on host {}, to process agent disconnection" , host != null ? host : hostId );
10471053 try {
1048- logger .info ("Host {} is disconnecting with event {}" ,
1049- attache , event );
1054+ logger .info ("Host {} is disconnecting with event {}" , attache , event );
10501055 Status nextStatus ;
1051- final HostVO host = _hostDao .findById (hostId );
10521056 if (host == null ) {
10531057 logger .warn ("Can't find host with {} ({})" , hostId , attache );
10541058 nextStatus = Status .Removed ;
@@ -1068,8 +1072,10 @@ protected boolean handleDisconnectWithoutInvestigation(final AgentAttache attach
10681072 joinLock .unlock ();
10691073 }
10701074 result = true ;
1075+ } finally {
1076+ joinLock .releaseRef ();
10711077 }
1072- joinLock . releaseRef ();
1078+
10731079 return result ;
10741080 }
10751081
@@ -1357,29 +1363,34 @@ private AgentAttache sendReadyAndGetAttache(HostVO host, ReadyCommand ready, Lin
13571363 ready .setArch (host .getArch ().getType ());
13581364 AgentAttache attache ;
13591365 GlobalLock joinLock = getHostJoinLock (host .getId ());
1360- if (joinLock .lock (60 )) {
1361- try {
1366+ try {
1367+ if (!joinLock .lock (60 )) {
1368+ throw new ConnectionException (true , String .format ("Unable to acquire lock on host %s, to process agent connection" , host ));
1369+ }
13621370
1363- if (!indirectAgentLB .compareManagementServerList (host .getId (), host .getDataCenterId (), agentMSHostList , lbAlgorithm )) {
1371+ logger .debug ("Acquired lock on host {}, to process agent connection" , host );
1372+ try {
1373+ if (!indirectAgentLB .compareManagementServerListAndLBAlorithm (host .getId (), host .getDataCenterId (), agentMSHostList , lbAlgorithm )) {
13641374 final List <String > newMSList = indirectAgentLB .getManagementServerList (host .getId (), host .getDataCenterId (), null );
13651375 ready .setMsHostList (newMSList );
1366- final List <String > avoidMsList = _mshostDao .listNonUpStateMsIPs ();
1367- ready .setAvoidMsHostList (avoidMsList );
1368- ready .setLbAlgorithm (indirectAgentLB .getLBAlgorithmName ());
1369- ready .setLbCheckInterval (indirectAgentLB .getLBPreferredHostCheckInterval (host .getClusterId ()));
1370- logger .debug ("Agent's management server host list is not up to date, sending list update: {}" , newMSList );
1376+ String newLBAlgorithm = indirectAgentLB .getLBAlgorithmName ();
1377+ ready .setLbAlgorithm (newLBAlgorithm );
1378+ logger .debug ("Agent's management server host list or lb algorithm is not up to date, sending list and algorithm update: {}, {}" , newMSList , newLBAlgorithm );
13711379 }
13721380
1381+ final List <String > avoidMsList = _mshostDao .listNonUpStateMsIPs ();
1382+ ready .setAvoidMsHostList (avoidMsList );
1383+ ready .setLbCheckInterval (indirectAgentLB .getLBPreferredHostCheckInterval (host .getClusterId ()));
1384+
13731385 attache = createAttacheForConnect (host , link );
13741386 attache = notifyMonitorsOfConnection (attache , startup , false );
13751387 } finally {
13761388 joinLock .unlock ();
13771389 }
1378- } else {
1379- throw new ConnectionException (true ,
1380- String .format ("Unable to acquire lock on host %s" , host ));
1390+ } finally {
1391+ joinLock .releaseRef ();
13811392 }
1382- joinLock . releaseRef ();
1393+
13831394 return attache ;
13841395 }
13851396
@@ -1821,11 +1832,11 @@ protected boolean isHostOwnerSwitched(final HostVO host) {
18211832 return false ;
18221833 }
18231834
1824- private void disconnectInternal (final long hostId , final Status .Event event , final boolean invstigate ) {
1835+ private void disconnectInternal (final long hostId , final Status .Event event , final boolean investigate ) {
18251836 final AgentAttache attache = findAttache (hostId );
18261837
18271838 if (attache != null ) {
1828- if (!invstigate ) {
1839+ if (!investigate ) {
18291840 disconnectWithoutInvestigation (attache , event );
18301841 } else {
18311842 disconnectWithInvestigation (attache , event );
0 commit comments