Skip to content

Commit ab60e9e

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 e607998 commit ab60e9e

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,10 @@ protected AgentManagerImpl() {
13761376
public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
13771377
synchronized (_loadingAgents) {
13781378
if (action == TapAgentsAction.Add) {
1379-
_loadingAgents.add(hostId);
1379+
if (_loadingAgents.contains(hostId))
1380+
return false;
1381+
else
1382+
_loadingAgents.add(hostId);
13801383
} else if (action == TapAgentsAction.Del) {
13811384
_loadingAgents.remove(hostId);
13821385
} else if (action == TapAgentsAction.Contains) {

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,9 +1920,23 @@ private Host createHostAndAgentDeferred(ServerResource resource, Map<String, Str
19201920
@Override
19211921
public Host createHostAndAgent(Long hostId, ServerResource resource, Map<String, String> details, boolean old, List<String> hostTags,
19221922
boolean forRebalance) {
1923-
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Add);
1924-
Host host = createHostAndAgent(resource, details, old, hostTags, forRebalance);
1925-
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Del);
1923+
Host host = null;
1924+
if (_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Add)) {
1925+
try {
1926+
AgentAttache agentattache = _agentMgr.findAttache(hostId);
1927+
if (agentattache == null) {
1928+
s_logger.debug("Creating agent for host " + hostId);
1929+
host = createHostAndAgent(resource, details, old, hostTags, forRebalance);
1930+
s_logger.debug("Completed creating agent for host " + hostId);
1931+
} else {
1932+
s_logger.debug("Agent already created in another thread for host " + hostId + ", ignore this");
1933+
}
1934+
} finally {
1935+
_agentMgr.tapLoadingAgents(hostId, TapAgentsAction.Del);
1936+
}
1937+
} else {
1938+
s_logger.debug("Agent creation already getting processed in another thread for host " + hostId + ", ignore this");
1939+
}
19261940
return host;
19271941
}
19281942

0 commit comments

Comments
 (0)