From a60d8cea862e416b2980e859740ab93809f4edeb Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Mon, 2 Jan 2012 13:40:33 +0530 Subject: [PATCH] bug 12530: moved the initial full sunc from the cron to host connect. --- .../cloud/agent/api/ClusterSyncAnswer.java | 9 ------ .../cloud/agent/api/ClusterSyncCommand.java | 28 ++++++++----------- .../agent/api/StartupRoutingCommand.java | 10 +++++++ .../xen/resource/CitrixResourceBase.java | 24 ++++++++++------ .../cloud/vm/VirtualMachineManagerImpl.java | 10 +++++-- 5 files changed, 44 insertions(+), 37 deletions(-) diff --git a/api/src/com/cloud/agent/api/ClusterSyncAnswer.java b/api/src/com/cloud/agent/api/ClusterSyncAnswer.java index ce36d350e68..5db7f4ea326 100644 --- a/api/src/com/cloud/agent/api/ClusterSyncAnswer.java +++ b/api/src/com/cloud/agent/api/ClusterSyncAnswer.java @@ -31,7 +31,6 @@ public class ClusterSyncAnswer extends Answer { public static final int FULL_SYNC=0; public static final int DELTA_SYNC=1; - public static final int INITIAL_FULL_SYNC=2; // this is here because a cron command answer is being sent twice // AgentAttache.processAnswers @@ -61,14 +60,6 @@ public class ClusterSyncAnswer extends Answer { result = true; } - public ClusterSyncAnswer(long clusterId, HashMap> newStates, HashMap> allStates, boolean init){ - _clusterId = clusterId; - _newStates = newStates; - _allStates = allStates; - _type = INITIAL_FULL_SYNC; - result = true; - } - public long getClusterId() { return _clusterId; } diff --git a/api/src/com/cloud/agent/api/ClusterSyncCommand.java b/api/src/com/cloud/agent/api/ClusterSyncCommand.java index 7cc2933272b..f70a8398a21 100644 --- a/api/src/com/cloud/agent/api/ClusterSyncCommand.java +++ b/api/src/com/cloud/agent/api/ClusterSyncCommand.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Cloud.com, Inc. All rights reserved. +/* Copyright (C) 2012 Citrix.com, Inc. All rights reserved. * * This software is licensed under the GNU General Public License v3 or later. * @@ -19,18 +19,20 @@ package com.cloud.agent.api; public class ClusterSyncCommand extends Command implements CronCommand { - private int _interval; - private int _skipSteps; // skip this many steps for full sync - private int _steps; - private boolean _init; - private long _clusterId; + int _interval; + int _skipSteps; // skip this many steps for full sync + int _steps; + + long _clusterId; + + public ClusterSyncCommand() { + } public ClusterSyncCommand(int interval, int skipSteps, long clusterId){ _interval = interval; _skipSteps = skipSteps; _clusterId = clusterId; _steps=0; - _init=true; } @Override @@ -44,10 +46,10 @@ public class ClusterSyncCommand extends Command implements CronCommand { public void incrStep(){ _steps++; - if (_steps>_skipSteps)_steps=0; + if (_steps>=_skipSteps)_steps=0; } - public boolean isRightStep(){ + public boolean isRightStep(){ return (_steps==0); } @@ -60,12 +62,4 @@ public class ClusterSyncCommand extends Command implements CronCommand { return false; } - public boolean isInit(){ - return _init; - } - - public void unsetInit(){ - _init = false; - } - } \ No newline at end of file diff --git a/api/src/com/cloud/agent/api/StartupRoutingCommand.java b/api/src/com/cloud/agent/api/StartupRoutingCommand.java index baecda31bef..c3776bf1e9d 100755 --- a/api/src/com/cloud/agent/api/StartupRoutingCommand.java +++ b/api/src/com/cloud/agent/api/StartupRoutingCommand.java @@ -23,6 +23,7 @@ import java.util.Map; import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Networks.RouterPrivateIpStrategy; +import com.cloud.utils.Pair; import com.cloud.vm.VirtualMachine.State; public class StartupRoutingCommand extends StartupCommand { @@ -48,6 +49,7 @@ public class StartupRoutingCommand extends StartupCommand { long dom0MinMemory; boolean poolSync; Map vms; + HashMap> _clusterVMStates; String caps; String pool; HypervisorType hypervisorType; @@ -127,6 +129,10 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr this.vms.put(vm_name, new VmState(vms.get(vm_name), null)); } } + + public void setClusterVMStateChanges(HashMap> allStates){ + _clusterVMStates = allStates; + } public int getCpus() { return cpus; @@ -151,6 +157,10 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr public Map getVmStates() { return vms; } + + public HashMap> getClusterVMStateChanges() { + return _clusterVMStates; + } public void setSpeed(long speed) { this.speed = speed; diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 42b82cc4230..e65401ba37e 100755 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -4032,6 +4032,20 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe cmd.setHypervisorType(HypervisorType.XenServer); cmd.setCluster(_cluster); cmd.setPoolSync(false); + + Pool pool; + try { + pool = Pool.getByUuid(conn, _host.pool); + Pool.Record poolr = pool.getRecord(conn); + + Host.Record hostr = poolr.master.getRecord(conn); + if (_host.uuid.equals(hostr.uuid)) { + HashMap> allStates=fullClusterSync(conn); + cmd.setClusterVMStateChanges(allStates); + } + } catch (Throwable e) { + s_logger.warn("Check for master failed, failing the FULL Cluster sync command"); + } StartupStorageCommand sscmd = initializeLocalSR(conn); if (sscmd != null) { @@ -6590,17 +6604,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return new Answer(cmd); } HashMap> newStates = deltaClusterSync(conn); + cmd.incrStep(); if (cmd.isRightStep()){ - cmd.incrStep(); // do full sync HashMap> allStates=fullClusterSync(conn); - if (cmd.isInit()){ - cmd.unsetInit(); - return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates, true); - } - else { - return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates); - } + return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates); } else { cmd.incrStep(); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index ae2455e69bf..991ca147064 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -2092,9 +2092,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene } else if (hs.isDelta()){ deltaSync(hs.getNewStates()); } - else { - fullSync(hs.getClusterId(), hs.getAllStates(), true); - } hs.setExecuted(); } } else if (!answer.getResult()) { @@ -2169,6 +2166,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene Long clusterId = agent.getClusterId(); long agentId = agent.getId(); if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen + StartupRoutingCommand startup = (StartupRoutingCommand) cmd; + HashMap> allStates = startup.getClusterVMStateChanges(); + if (allStates != null){ + this.fullSync(clusterId, allStates, true); + } + + // initiate the cron job ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()), Integer.parseInt(Config.ClusterFullSyncSkipSteps.getDefaultValue()), clusterId); try {