Skip to content

Commit 6019289

Browse files
Re-check every migration, not only VMs in an affinity group
Review feedback on the PR. applyAffinityConstraints also applies DPDK and dedicated-resource exclusions, and neither depends on affinity group membership. Returning early for VMs with no groups therefore skipped those checks, which the method's own documentation said it covered. The cost is one call per planned migration, bounded by drs.max.migrations, at execution time rather than in any hot loop. Also move executeDrsPlan's javadoc back onto executeDrsPlan; it was left stranded above the method inserted before it. Signed-off-by: Brad House <bhouse@nexthop.ai>
1 parent 192bab5 commit 6019289

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

‎server/src/main/java/org/apache/cloudstack/cluster/ClusterDrsServiceImpl.java‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,6 @@ void processPlans() {
787787
}
788788
}
789789

790-
/**
791-
* Executes the DRS plan by migrating virtual machines to their destination hosts.
792-
* If there are no migrations to be executed, the plan is marked as completed.
793-
*
794-
* @param plan
795-
* the DRS plan to be executed
796-
*/
797790
/**
798791
* Checks a planned migration against the placement rules as they stand now.
799792
*
@@ -802,8 +795,9 @@ void processPlans() {
802795
* against current placements, and nothing downstream re-checks it - migrateVirtualMachine does
803796
* not enforce affinity groups.
804797
*
805-
* The processors also cover dedicated resources and DPDK, so a refusal is not necessarily about
806-
* an affinity group.
798+
* Checked for every VM, not only those in an affinity group: applyAffinityConstraints also
799+
* applies DPDK and dedicated-resource exclusions, which apply regardless of group membership.
800+
* A refusal here is therefore not necessarily about an affinity group.
807801
*
808802
* @param vm
809803
* the VM the plan wants to move
@@ -821,9 +815,6 @@ protected boolean destinationViolatesAffinity(VirtualMachine vm, Host destHost,
821815
logger.debug("VM {} is no longer running, so its planned migration is out of date", vm);
822816
return true;
823817
}
824-
if (CollectionUtils.isEmpty(affinityGroupVMMapDao.listByInstanceId(vm.getId()))) {
825-
return false;
826-
}
827818
if (dispatchedSourceHosts.contains(destHost.getId())) {
828819
logger.debug("Host {} is still occupied by a VM whose migration away from it is only queued", destHost);
829820
return true;
@@ -837,6 +828,13 @@ protected boolean destinationViolatesAffinity(VirtualMachine vm, Host destHost,
837828
return excludes.shouldAvoid(destHost);
838829
}
839830

831+
/**
832+
* Executes the DRS plan by migrating virtual machines to their destination hosts.
833+
* If there are no migrations to be executed, the plan is marked as completed.
834+
*
835+
* @param plan
836+
* the DRS plan to be executed
837+
*/
840838
void executeDrsPlan(ClusterDrsPlanVO plan) {
841839
List<ClusterDrsPlanMigrationVO> planMigrations = drsPlanMigrationDao.listPlanMigrationsToExecute(plan.getId());
842840
if (planMigrations == null || planMigrations.isEmpty()) {

‎server/src/test/java/org/apache/cloudstack/cluster/ClusterDrsServiceImplTest.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,15 +993,20 @@ private void affinityExcludes(Long... hostIds) {
993993
}
994994

995995
@Test
996-
public void testDestinationAllowedWhenVmHasNoAffinityGroups() {
996+
public void testAVmWithNoAffinityGroupsIsStillRechecked() {
997+
// applyAffinityConstraints also applies DPDK and dedicated-resource exclusions, which do
998+
// not depend on affinity group membership, so every VM has to go through it
997999
VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
9981000
Mockito.when(vm.getId()).thenReturn(1L);
9991001
Mockito.when(vm.getHostId()).thenReturn(10L);
1000-
Mockito.when(affinityGroupVMMapDao.listByInstanceId(1L)).thenReturn(Collections.emptyList());
1002+
Mockito.when(vm.getServiceOfferingId()).thenReturn(5L);
1003+
Mockito.when(serviceOfferingDao.findByIdIncludingRemoved(1L, 5L))
1004+
.thenReturn(Mockito.mock(ServiceOfferingVO.class));
1005+
affinityExcludes(21L);
10011006

10021007
assertFalse(clusterDrsService.destinationViolatesAffinity(vm, host(20L),
10031008
Collections.emptyList(), Collections.emptyList()));
1004-
Mockito.verify(managementServer, Mockito.never())
1009+
Mockito.verify(managementServer)
10051010
.applyAffinityConstraints(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
10061011
}
10071012

0 commit comments

Comments
 (0)