Copilot commented on code in PR #13363:
URL: https://github.com/apache/cloudstack/pull/13363#discussion_r3982054027
##########
server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java:
##########
@@ -1000,12 +980,8 @@ public boolean
postStateTransitionEvent(StateMachine2.Transition<State, Event> t
}
if ((newState == State.Starting || newState == State.Migrating || event
== Event.AgentReportMigrated) && vm.getHostId() != null) {
- boolean fromLastHost = false;
- if (vm.getHostId().equals(vm.getLastHostId())) {
- logger.debug("VM starting again on the last host it was stopped on");
- fromLastHost = true;
- }
- allocateVmCapacity(vm, fromLastHost);
+ releaseVmCapacity(vm, true, false, lastHost);
+ allocateVmCapacity(vm);
}
Review Comment:
The new unconditional `releaseVmCapacity(vm, true, false, lastHost)` inside
the `(newState == Starting || newState == Migrating || event ==
AgentReportMigrated)` block can corrupt capacity accounting for migrations: on
transitions like `Running -> Migrating` or `Running + AgentReportMigrated`, the
VM typically has no per-host *reserved* capacity on `lastHost`, but this call
will still subtract from the host’s aggregate reserved pool when `reserved* >=
vm*`. That can silently reduce reserved capacity belonging to other stopped VMs
on that host.
Drain reserved capacity only when the VM is starting from `Stopped` (the
state where capacity was previously moved into `reserved`). Keep the allocation
for `Migrating` / `AgentReportMigrated` unchanged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]