Skip to content

Commit ae181af

Browse files
committed
CLOUDSTACK-4636: In a scaled up setup all Vm's in a cluster were stopped and/or started after management server restart
Issue happens as there are more than one thread processing connect for a host simultaneously. The VM full sync. is not designed to work in this scenario and as a result user VMs may get stopped incorrectly. Direct agent scan task runs at regular intervals (direct.agent.scan.interval defaulted to 90 secs) and identifies hosts that needs to be processed for connect. In a normal scenario hosts mostly get connected within that interval and there are no issues. But if due to some reason the connect process takes more time and is not completed by the time next agent scan runs. In this case, based on the db. state same hosts may get picked up again. And then there will be situations where more than one thread is processing connect for the same host. The fix is to check if there is a thread already processing connect for a host and in this case all subsequent threads for that host will simply bail out. Also there may be a scenario where one thread already completed processing connect but another thread already got scheduled before that and will again repeat the same. This is also prevented by putting appropriate checks.
1 parent 28af817 commit ae181af

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

‎engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,22 @@ public void run() {
10371037
s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id);
10381038
}
10391039

1040-
tapLoadingAgents(id, TapAgentsAction.Add);
1041-
_resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
1042-
tapLoadingAgents(id, TapAgentsAction.Del);
1040+
if (tapLoadingAgents(id, TapAgentsAction.Add)) {
1041+
try {
1042+
AgentAttache agentattache = findAttache(id);
1043+
if (agentattache == null) {
1044+
s_logger.debug("Creating agent for host " + id);
1045+
_resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
1046+
s_logger.debug("Completed creating agent for host " + id);
1047+
} else {
1048+
s_logger.debug("Agent already created in another thread for host " + id + ", ignore this");
1049+
}
1050+
} finally {
1051+
tapLoadingAgents(id, TapAgentsAction.Del);
1052+
}
1053+
} else {
1054+
s_logger.debug("Agent creation already getting processed in another thread for host " + id + ", ignore this");
1055+
}
10431056
} catch (Exception e) {
10441057
s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
10451058
} finally {
@@ -1290,7 +1303,10 @@ protected AgentManagerImpl() {
12901303
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
12911304
synchronized (_loadingAgents) {
12921305
if (action == TapAgentsAction.Add) {
1293-
_loadingAgents.add(hostId);
1306+
if (_loadingAgents.contains(hostId))
1307+
return false;
1308+
else
1309+
_loadingAgents.add(hostId);
12941310
} else if (action == TapAgentsAction.Del) {
12951311
_loadingAgents.remove(hostId);
12961312
} else if (action == TapAgentsAction.Contains) {

0 commit comments

Comments
 (0)