mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
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.
This commit is contained in:
parent
28af817fcc
commit
ae181afb00
@ -1037,9 +1037,22 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id);
|
||||
}
|
||||
|
||||
tapLoadingAgents(id, TapAgentsAction.Add);
|
||||
_resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
|
||||
tapLoadingAgents(id, TapAgentsAction.Del);
|
||||
if (tapLoadingAgents(id, TapAgentsAction.Add)) {
|
||||
try {
|
||||
AgentAttache agentattache = findAttache(id);
|
||||
if (agentattache == null) {
|
||||
s_logger.debug("Creating agent for host " + id);
|
||||
_resourceMgr.createHostAndAgent(id, resource, details, false, null, false);
|
||||
s_logger.debug("Completed creating agent for host " + id);
|
||||
} else {
|
||||
s_logger.debug("Agent already created in another thread for host " + id + ", ignore this");
|
||||
}
|
||||
} finally {
|
||||
tapLoadingAgents(id, TapAgentsAction.Del);
|
||||
}
|
||||
} else {
|
||||
s_logger.debug("Agent creation already getting processed in another thread for host " + id + ", ignore this");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e);
|
||||
} finally {
|
||||
@ -1290,7 +1303,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
||||
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
|
||||
synchronized (_loadingAgents) {
|
||||
if (action == TapAgentsAction.Add) {
|
||||
_loadingAgents.add(hostId);
|
||||
if (_loadingAgents.contains(hostId))
|
||||
return false;
|
||||
else
|
||||
_loadingAgents.add(hostId);
|
||||
} else if (action == TapAgentsAction.Del) {
|
||||
_loadingAgents.remove(hostId);
|
||||
} else if (action == TapAgentsAction.Contains) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user