Skip to content

Commit 1a18899

Browse files
committed
HA: set correct hostId for HA work of vm migration and skip migration job if vm is running on a different host
1 parent 6c40a7b commit 1a18899

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

server/src/main/java/com/cloud/ha/HighAvailabilityManagerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ protected void wakeupWorkers() {
342342
@Override
343343
public boolean scheduleMigration(final VMInstanceVO vm) {
344344
if (vm.getHostId() != null) {
345-
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.Migration, Step.Scheduled, vm.getHostId(), vm.getState(), 0, vm.getUpdated());
345+
Long hostId = VirtualMachine.State.Migrating.equals(vm.getState()) ? vm.getLastHostId() : vm.getHostId();
346+
final HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.Migration, Step.Scheduled, hostId, vm.getState(), 0, vm.getUpdated());
346347
_haDao.persist(work);
347348
s_logger.info("Scheduled migration work of VM " + vm.getUuid() + " from host " + _hostDao.findById(vm.getHostId()) + " with HAWork " + work);
348349
wakeupWorkers();
@@ -716,6 +717,10 @@ public Long migrate(final HaWorkVO work) {
716717
s_logger.info("Unable to find vm: " + vmId + ", skipping migrate.");
717718
return null;
718719
}
720+
if (VirtualMachine.State.Running.equals(vm.getState()) && srcHostId != vm.getHostId()) {
721+
s_logger.info(String.format("VM %s is running on a different host %s, skipping migration", vm, vm.getHostId()));
722+
return null;
723+
}
719724
s_logger.info("Migration attempt: for VM " + vm.getUuid() + "from host id " + srcHostId +
720725
". Starting attempt: " + (1 + work.getTimesTried()) + "/" + _maxRetries + " times.");
721726
try {

0 commit comments

Comments
 (0)