Skip to content

Commit e65c9ff

Browse files
authored
Fix: Select another pod if all hosts in the pod becomes unavailable (#8085)
1 parent e6f048b commit e65c9ff

File tree

2 files changed

+283
-40
lines changed

2 files changed

+283
-40
lines changed

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ public void allocate(final String vmInstanceName, final VirtualMachineTemplate t
569569
allocate(vmInstanceName, template, serviceOffering, new DiskOfferingInfo(diskOffering), new ArrayList<>(), networks, plan, hyperType, null, null);
570570
}
571571

572-
private VirtualMachineGuru getVmGuru(final VirtualMachine vm) {
572+
VirtualMachineGuru getVmGuru(final VirtualMachine vm) {
573573
if(vm != null) {
574574
return _vmGurus.get(vm.getType());
575575
}
@@ -1443,6 +1443,7 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
14431443
}
14441444
if (canRetry) {
14451445
try {
1446+
conditionallySetPodToDeployIn(vm);
14461447
changeState(vm, Event.OperationFailed, null, work, Step.Done);
14471448
} catch (final NoTransitionException e) {
14481449
throw new ConcurrentOperationException(e.getMessage());
@@ -1460,6 +1461,24 @@ public void orchestrateStart(final String vmUuid, final Map<VirtualMachineProfil
14601461
}
14611462
}
14621463

1464+
/**
1465+
* Setting pod id to null can result in migration of Volumes across pods. This is not desirable for VMs which
1466+
* have a volume in Ready state (happens when a VM is shutdown and started again).
1467+
* So, we set it to null only when
1468+
* migration of VM across cluster is enabled
1469+
* Or, volumes are still in allocated state for that VM (happens when VM is Starting/deployed for the first time)
1470+
*/
1471+
private void conditionallySetPodToDeployIn(VMInstanceVO vm) {
1472+
if (MIGRATE_VM_ACROSS_CLUSTERS.valueIn(vm.getDataCenterId()) || areAllVolumesAllocated(vm.getId())) {
1473+
vm.setPodIdToDeployIn(null);
1474+
}
1475+
}
1476+
1477+
boolean areAllVolumesAllocated(long vmId) {
1478+
final List<VolumeVO> vols = _volsDao.findByInstance(vmId);
1479+
return CollectionUtils.isEmpty(vols) || vols.stream().allMatch(v -> Volume.State.Allocated.equals(v.getState()));
1480+
}
1481+
14631482
private void logBootModeParameters(Map<VirtualMachineProfile.Param, Object> params) {
14641483
if (params == null) {
14651484
return;

0 commit comments

Comments
 (0)