Skip to content

Commit a60d8ce

Browse files
author
Abhinandan Prateek
committed
bug 12530: moved the initial full sunc from the cron to host connect.
1 parent 7e6bbf9 commit a60d8ce

5 files changed

Lines changed: 44 additions & 37 deletions

File tree

‎api/src/com/cloud/agent/api/ClusterSyncAnswer.java‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public class ClusterSyncAnswer extends Answer {
3131

3232
public static final int FULL_SYNC=0;
3333
public static final int DELTA_SYNC=1;
34-
public static final int INITIAL_FULL_SYNC=2;
3534

3635
// this is here because a cron command answer is being sent twice
3736
// AgentAttache.processAnswers
@@ -61,14 +60,6 @@ public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> ne
6160
result = true;
6261
}
6362

64-
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates, HashMap<String, Pair<String, State>> allStates, boolean init){
65-
_clusterId = clusterId;
66-
_newStates = newStates;
67-
_allStates = allStates;
68-
_type = INITIAL_FULL_SYNC;
69-
result = true;
70-
}
71-
7263
public long getClusterId() {
7364
return _clusterId;
7465
}

‎api/src/com/cloud/agent/api/ClusterSyncCommand.java‎

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
1+
/* Copyright (C) 2012 Citrix.com, Inc. All rights reserved.
22
*
33
* This software is licensed under the GNU General Public License v3 or later.
44
*
@@ -19,18 +19,20 @@
1919

2020

2121
public class ClusterSyncCommand extends Command implements CronCommand {
22-
private int _interval;
23-
private int _skipSteps; // skip this many steps for full sync
24-
private int _steps;
25-
private boolean _init;
26-
private long _clusterId;
22+
int _interval;
23+
int _skipSteps; // skip this many steps for full sync
24+
int _steps;
25+
26+
long _clusterId;
27+
28+
public ClusterSyncCommand() {
29+
}
2730

2831
public ClusterSyncCommand(int interval, int skipSteps, long clusterId){
2932
_interval = interval;
3033
_skipSteps = skipSteps;
3134
_clusterId = clusterId;
3235
_steps=0;
33-
_init=true;
3436
}
3537

3638
@Override
@@ -44,10 +46,10 @@ public int getSkipSteps(){
4446

4547
public void incrStep(){
4648
_steps++;
47-
if (_steps>_skipSteps)_steps=0;
49+
if (_steps>=_skipSteps)_steps=0;
4850
}
4951

50-
public boolean isRightStep(){
52+
public boolean isRightStep(){
5153
return (_steps==0);
5254
}
5355

@@ -60,12 +62,4 @@ public boolean executeInSequence() {
6062
return false;
6163
}
6264

63-
public boolean isInit(){
64-
return _init;
65-
}
66-
67-
public void unsetInit(){
68-
_init = false;
69-
}
70-
7165
}

‎api/src/com/cloud/agent/api/StartupRoutingCommand.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.cloud.host.Host;
2424
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2525
import com.cloud.network.Networks.RouterPrivateIpStrategy;
26+
import com.cloud.utils.Pair;
2627
import com.cloud.vm.VirtualMachine.State;
2728

2829
public class StartupRoutingCommand extends StartupCommand {
@@ -48,6 +49,7 @@ public String getHost() {
4849
long dom0MinMemory;
4950
boolean poolSync;
5051
Map<String, VmState> vms;
52+
HashMap<String, Pair<String, State>> _clusterVMStates;
5153
String caps;
5254
String pool;
5355
HypervisorType hypervisorType;
@@ -127,6 +129,10 @@ public void setStateChanges(Map<String, State> vms) {
127129
this.vms.put(vm_name, new VmState(vms.get(vm_name), null));
128130
}
129131
}
132+
133+
public void setClusterVMStateChanges(HashMap<String, Pair<String, State>> allStates){
134+
_clusterVMStates = allStates;
135+
}
130136

131137
public int getCpus() {
132138
return cpus;
@@ -151,6 +157,10 @@ public long getDom0MinMemory() {
151157
public Map<String, VmState> getVmStates() {
152158
return vms;
153159
}
160+
161+
public HashMap<String, Pair<String, State>> getClusterVMStateChanges() {
162+
return _clusterVMStates;
163+
}
154164

155165
public void setSpeed(long speed) {
156166
this.speed = speed;

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,6 +4032,20 @@ public StartupCommand[] initialize() throws IllegalArgumentException{
40324032
cmd.setHypervisorType(HypervisorType.XenServer);
40334033
cmd.setCluster(_cluster);
40344034
cmd.setPoolSync(false);
4035+
4036+
Pool pool;
4037+
try {
4038+
pool = Pool.getByUuid(conn, _host.pool);
4039+
Pool.Record poolr = pool.getRecord(conn);
4040+
4041+
Host.Record hostr = poolr.master.getRecord(conn);
4042+
if (_host.uuid.equals(hostr.uuid)) {
4043+
HashMap<String, Pair<String, State>> allStates=fullClusterSync(conn);
4044+
cmd.setClusterVMStateChanges(allStates);
4045+
}
4046+
} catch (Throwable e) {
4047+
s_logger.warn("Check for master failed, failing the FULL Cluster sync command");
4048+
}
40354049

40364050
StartupStorageCommand sscmd = initializeLocalSR(conn);
40374051
if (sscmd != null) {
@@ -6590,17 +6604,11 @@ protected Answer execute(final ClusterSyncCommand cmd) {
65906604
return new Answer(cmd);
65916605
}
65926606
HashMap<String, Pair<String, State>> newStates = deltaClusterSync(conn);
6607+
cmd.incrStep();
65936608
if (cmd.isRightStep()){
6594-
cmd.incrStep();
65956609
// do full sync
65966610
HashMap<String, Pair<String, State>> allStates=fullClusterSync(conn);
6597-
if (cmd.isInit()){
6598-
cmd.unsetInit();
6599-
return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates, true);
6600-
}
6601-
else {
6602-
return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates);
6603-
}
6611+
return new ClusterSyncAnswer(cmd.getClusterId(), newStates, allStates);
66046612
}
66056613
else {
66066614
cmd.incrStep();

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,9 +2092,6 @@ public boolean processAnswers(long agentId, long seq, Answer[] answers) {
20922092
} else if (hs.isDelta()){
20932093
deltaSync(hs.getNewStates());
20942094
}
2095-
else {
2096-
fullSync(hs.getClusterId(), hs.getAllStates(), true);
2097-
}
20982095
hs.setExecuted();
20992096
}
21002097
} else if (!answer.getResult()) {
@@ -2169,6 +2166,13 @@ public void processConnect(HostVO agent, StartupCommand cmd, boolean forRebalanc
21692166
Long clusterId = agent.getClusterId();
21702167
long agentId = agent.getId();
21712168
if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen
2169+
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
2170+
HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
2171+
if (allStates != null){
2172+
this.fullSync(clusterId, allStates, true);
2173+
}
2174+
2175+
// initiate the cron job
21722176
ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()),
21732177
Integer.parseInt(Config.ClusterFullSyncSkipSteps.getDefaultValue()), clusterId);
21742178
try {

0 commit comments

Comments
 (0)