bug 11910: full sync will only stop unknown VMs on agent

This commit is contained in:
Abhinandan Prateek 2011-11-23 17:18:51 +05:30
parent fd0dc5281a
commit 09e3e2e2ff
4 changed files with 29 additions and 44 deletions

View File

@ -25,8 +25,9 @@ import com.cloud.vm.VirtualMachine.State;
public class ClusterSyncAnswer extends Answer {
private long _clusterId;
private HashMap<String, Pair<String, State>> _newStates;
private HashMap<String, Pair<String, State>> _allStates;
private int _type = -1; // 0 for full, 1 for delta
private boolean isExecuted=false; // this is to avoidf double execution first time, due to framework ???
private boolean isExecuted=false; // this is to avoid double execution first time, due to framework ???
public static final int FULL_SYNC=0;
@ -39,10 +40,19 @@ public class ClusterSyncAnswer extends Answer {
_type = -1;
}
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates, int type){
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates){
_clusterId = clusterId;
_newStates = newStates;
_type = type;
_type = DELTA_SYNC;
result = true;
}
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates, HashMap<String, Pair<String, State>> allStates){
_clusterId = clusterId;
_newStates = newStates;
_allStates = allStates;
_type = FULL_SYNC;
result = true;
}
@ -53,6 +63,10 @@ public class ClusterSyncAnswer extends Answer {
public HashMap<String, Pair<String, State>> getNewStates() {
return _newStates;
}
public HashMap<String, Pair<String, State>> getAllStates() {
return _allStates;
}
public boolean isFull(){
return _type==0;

View File

@ -6451,6 +6451,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
protected Answer execute(final ClusterSyncCommand cmd) {
Connection conn = getConnection();
//check if this is master
@ -6461,32 +6462,26 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
Host.Record hostr = poolr.master.getRecord(conn);
if (!_host.uuid.equals(hostr.uuid)) {
s_logger.debug("Not the master node so just return ok: " + _host.ip);
return new ClusterSyncAnswer(cmd.getClusterId());
}
} catch (Exception e) {
s_logger.warn("Check for master failed, failing the Cluster sync command");
return new ClusterSyncAnswer(cmd.getClusterId());
}
HashMap<String, Pair<String, State>> newStates;
int sync_type=-1;
HashMap<String, Pair<String, State>> newStates = deltaClusterSync(conn);
if (cmd.isRightStep()){
// do full sync
newStates=fullClusterSync(conn);
sync_type = ClusterSyncAnswer.FULL_SYNC;
HashMap<String, Pair<String, State>> allStates=fullClusterSync(conn);
cmd.incrStep();
return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates);
}
else {
// do delta sync
newStates = deltaClusterSync(conn);
if (newStates == null) {
s_logger.warn("Unable to get current status from sync");
}
sync_type = ClusterSyncAnswer.DELTA_SYNC;
cmd.incrStep();
return new ClusterSyncAnswer(cmd.getClusterId(), newStates);
}
cmd.incrStep();
return new ClusterSyncAnswer(cmd.getClusterId(), newStates, sync_type);
}
protected HashMap<String, Pair<String, State>> fullClusterSync(Connection conn) {
s_vms.clear(_cluster);
try {

View File

@ -148,7 +148,7 @@ public enum Config {
MigrateRetryInterval("Advanced", HighAvailabilityManager.class, Integer.class, "migrate.retry.interval", "120", "Time (in seconds) between migration retries", null),
PingInterval("Advanced", AgentManager.class, Integer.class, "ping.interval", "60", "Ping interval in seconds", null),
ClusterDeltaSyncInterval("Advanced", AgentManager.class, Integer.class, "sync.interval", "60", "Cluster Delta sync interval in seconds", null),
ClusterFullSyncSkipSteps("Advanced", AgentManager.class, Integer.class, "skip.steps", "30", "Cluster full sync skip steps count", null),
ClusterFullSyncSkipSteps("Advanced", AgentManager.class, Integer.class, "skip.steps", "60", "Cluster full sync skip steps count", null),
PingTimeout("Advanced", AgentManager.class, Float.class, "ping.timeout", "2.5", "Multiplier to ping.interval before announcing an agent has timed out", null),
Port("Advanced", AgentManager.class, Integer.class, "port", "8250", "Port to listen on for agent connection.", null),
RouterCpuMHz("Advanced", NetworkManager.class, Integer.class, "router.cpu.mhz", String.valueOf(VirtualNetworkApplianceManager.DEFAULT_ROUTER_CPU_MHZ), "Default CPU speed (MHz) for router VM.", null),

View File

@ -1641,34 +1641,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
public Commands fullSync(final long clusterId, Map<String, Pair<String, State>> newStates) {
Commands commands = new Commands(OnError.Continue);
Map<Long, AgentVmInfo> infos = convertToInfos(newStates);
long hId = 0;
final List<VMInstanceVO> vms = _vmDao.listByClusterId(clusterId);
for (VMInstanceVO vm : vms) {
AgentVmInfo info = infos.remove(vm.getId());
VMInstanceVO castedVm = null;
if (info == null) {
// the vm is not there on cluster, check the vm status in DB
if (vm.getState() == State.Starting && (DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime()) < 10*60*1000){
continue; // ignoring this VM as it is still settling
}
info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
castedVm = info.guru.findById(vm.getId());
hId = vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId();
} else {
castedVm = info.vm;
String host_guid = info.getHostUuid();
Host host = _hostDao.findByGuid(host_guid);
if (host == null) {
infos.put(vm.getId(), info);
continue;
}
hId = host.getId();
}
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(castedVm.getHypervisorType());
Command command = compareState(hId, castedVm, info, false, hvGuru.trackVmHostChange());
if (command != null) {
commands.addCommand(command);
}
infos.remove(vm.getId());
}
for (final AgentVmInfo left : infos.values()) {
s_logger.warn("Stopping a VM that we have no record of: " + left.name);
@ -1985,7 +1960,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
ClusterSyncAnswer hs = (ClusterSyncAnswer) answer;
if (hs.execute()){
if (hs.isFull()) {
fullSync(hs.getClusterId(), hs.getNewStates());
deltaSync(hs.getNewStates());
fullSync(hs.getClusterId(), hs.getAllStates());
} else if (hs.isDelta()) {
deltaSync(hs.getNewStates());
}