bhouse-nexthop opened a new pull request, #14233:
URL: https://github.com/apache/cloudstack/pull/14233

   ### Description
   
   With `vm.destroy.forcestop=true`, destroying an instance whose host is 
briefly unreachable releases the instance's NICs, addresses and volumes without 
stopping it. The domain keeps running with no record in CloudStack, and its 
address is handed to the next instance.
   
   Fixes #14232
   
   A forced stop that gets no answer from the host treats the instance as 
stopped. That is right for a host that is gone, and wrong for one that is only 
unreachable for a while: an agent or management server restart, a management 
server crash before its peers take over its hosts, or an inconclusive 
disconnect investigation. `vm.destroy.forcestop` applies that to every destroy.
   
   This change keeps `vm.destroy.forcestop` and keeps the stop forced, so a 
host that answers still gets a hard stop. What changes is what a destroy does 
when the host does not confirm the stop. The decision is made at that point, 
not before the stop is queued:
   
   | when a destroy's stop is not confirmed by the host        | before         
                          | after                                            |
   
|-----------------------------------------------------------|------------------------------------------|--------------------------------------------------|
   | host is none, record gone, Down or Removed                | resources 
released                       | unchanged                                      
  |
   | any other host status, StopCommand unanswered             | resources 
released, domain left running  | stop fails, instance left as it was, destroy 
fails and can be retried |
   | any other host status, host answers that it could not stop | resources 
released, domain left running | same as above                                   
 |
   | instance stalled in Starting or Migrating                 | released 
whatever the host answered      | an ordinary stop is tried first; released 
only once the host confirms it, or if the host is gone |
   
   | commit | change |
   |--------|--------|
   | 1 | first version: decided from the host status before the stop. 
Superseded by 2 |
   | 2 | `VirtualMachineManager.advanceStopForDestroy()`: the stop is forced 
per `vm.destroy.forcestop`, and a `releaseOnlyIfHostIsGone` flag on 
`VmWorkStop` makes `advanceStop()` release without the host's confirmation only 
when the host is gone |
   | 3 | account cleanup no longer expunges an instance whose destroy failed 
while it is still on its host |
   | 4 | second review: stalled instances try an ordinary stop before the 
forced cleanup instead of deciding from host status; account cleanup defers the 
rest of the account while such an instance remains; one host lookup in the 
release decision; tests for the flag through the job queue and serialization |
   | 5 | review: a destroy stop of a Migrating instance is refused while the 
source host may still be running it |
   | 6 | the rolling restart (`restartNetwork`/`restartVPC` with 
`cleanup=true`) no longer force-releases old routers (see below); 
`advanceStop()` returns after a successful forced cleanup instead of failing 
the stop of an instance it has just stopped |
   
   Commit 1 is kept so the review history makes sense; it can be squashed on 
merge.
   
   Every path that stops an instance to destroy it now goes through 
`advanceStopForDestroy()`:
   
   - `UserVmManagerImpl.destroyVm(DestroyVMCmd)`
   - `VirtualMachineManagerImpl.destroy()`, also used by host deletion with 
`forcedestroylocalstorage`
   - `VirtualMachineManagerImpl.advanceExpunge()`, which also expunges virtual 
routers (network restart with cleanup, network deletion, network GC), CPVM/SSVM 
and internal load balancer VMs
   
   HA destroy is not affected: it stops the instance with an explicit forced 
stop before destroying it.
   
   The rolling restart (`restartNetwork` and `restartVPC` with `cleanup=true`, 
the default with `network.rolling.restart=true`) stopped each old router with 
an explicit forced stop before destroying it, so a router on a Disconnected 
host was released while still running and holding the gateway next to the new 
router. It now refuses up front when an old router is migrating or on a host 
that is neither Up nor Down/Removed, because the new router is deployed before 
the old ones are stopped. The old routers are then stopped with a forced stop 
that releases without the host's confirmation only when the host is gone. That 
stop stays forced whatever `vm.destroy.forcestop` says, so a router on a Down 
host is still released.
   
   A forced stop of an instance with no StopRequested transition (Starting, 
Migrating) cleaned it up and moved it to Stopped, then went on to the 
StopCommand path, which requires Stopping, and failed. `advanceStop()` now 
returns after a successful forced cleanup. This predates the change, but this 
PR changes that block.
   
   Behaviour that does **not** change:
   
   - an explicit forced stop (`stopVirtualMachine forced=true`, HA) still 
releases regardless of the host. That is a caller stating the instance is to be 
treated as stopped
   - with `vm.destroy.forcestop=false` nothing changes
   - a `VmWorkStop` job queued before the upgrade deserializes with the flag 
false and keeps the previous behaviour; one queued by an upgraded management 
server and run by an old one is read without the flag, as before
   
   ### Known limitations
   
   - An instance on a host that stays unreachable without being marked Down, 
for example Alert after an inconclusive investigation, can no longer be 
destroyed with `vm.destroy.forcestop` alone. Stop it with `forced=true` first, 
which is an explicit decision (and needs `allow.user.force.stop.vm` for 
non-admins), then destroy it. The same applies to routers: 
`restartNetwork`/`restartVPC` with `cleanup=true` (rolling or not) and network 
GC fail on such a host until the router is stopped with `forced=true`. The 
rolling restart checks the host before it deploys the new router; if the host 
becomes unreachable while the new router is deployed, the old router's stop 
fails and both routers remain until the restart is retried.
   - A hung agent on an Up host now makes the destroy fail rather than release. 
That is intended: the host may still be running the domain.
   - A stop request joins a stop job already pending for the same instance, 
whatever flags that job was queued with. This is existing behaviour for the 
`cleanup` flag too. An explicit forced stop that joins a destroy's stop 
inherits its caution, and a destroy that joins an explicit forced stop inherits 
the force.
   - Account cleanup defers an instance whose destroy failed for any reason 
while it still has a host, not only when the host is unreachable, and the rest 
of that account's cleanup waits for it. The account is retried every 
`account.cleanup.interval`.
   - `destroyVm(DestroyVMCmd)` with `expunge=true` removes the backup offering 
before the stop. If the stop now fails, the instance stays without it. That 
ordering predates this change.
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing 
functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [x] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] Build/CI
   - [ ] Test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [x] Critical
   - [ ] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### How Has This Been Tested?
   
   - unit tests through `advanceStop()`: a destroy stop that cannot reach a 
Disconnected host fails, does not call `releaseVmResources()` and leaves the 
instance Running; with the host Down it releases; an explicit forced stop still 
releases on a Disconnected host
   - unit tests for a stalled (Starting) instance: no cleanup when the host 
does not confirm, cleanup once an Up host confirms, cleanup without asking a 
Down host
   - unit tests that the flag reaches the queued `VmWorkStop`, that the job 
handler and the in-job path pass it on, and that it survives `VmWorkSerializer` 
(a job without it reads false)
   - unit tests for `isHostGone()` over every host status, 
`mayReleaseWithoutHostConfirmation()`, `advanceStopForDestroy()`, the three 
destroy paths, the force-stop permission check, and the account cleanup guard 
and deferral
   - unit tests for the rolling restart: an old router on a host that is 
neither Up nor Down/Removed (every host status), or migrating, refuses 
`restartNetwork` and `restartVPC` before any router is destroyed or deployed; 
routers that are Stopped, have no host or whose host record is gone pass; old 
routers are stopped with `advanceStop(uuid, true, true)` and not destroyed if 
that fails
   - unit tests that a forced stop of a Starting instance returns once cleaned 
up, for an explicit forced stop and a destroy stop, without sending a 
StopCommand
   - mutation-tested: dropping the flag at each step of the job queue, dropping 
the stalled-instance stop, restoring the old release check, treating Up or 
Disconnected as gone, dropping the rolling restart's up-front check, restoring 
its explicit forced stop, or dropping the return after the forced cleanup each 
fail a test
   - `VirtualMachineManagerImplTest` (121), `NetworkOrchestratorTest`, 
`VpcManagerImplTest`, `UserVmManagerImplTest` and `AccountManagerImplTest` pass
   - traced on a running 4.22 deployment: during two rolling agent and 
management server upgrades, 31 instances were left running unmanaged, each 
preceded by `Unable to actually stop ... but continue with release because it's 
a force stop` with `AgentUnavailableException ... Disconnected` for a destroy. 
8 of them were destroyed by management servers that already had #14207, whose 
expunge-time StopCommand also could not reach the host
   
   #### How did you try to break this feature and the system with this change?
   
   Two adversarial reviews, each checked against the code:
   
   - the first found that deciding from the host status before the stop misses 
hosts that are unreachable while still Up, and that the decision was baked into 
a job that may run much later. Commit 2 moves the decision to where the stop 
goes unconfirmed. It also found that account cleanup expunges an instance whose 
destroy failed, and expunge releases network resources before it stops the 
instance (commit 3)
   - the second found that stalled instances were still decided from host 
status, refusing even when an Up host would answer; that account cleanup went 
on to remove the security groups, networks and resource counts of an instance 
it had left running; a race where a host removed between two lookups caused an 
NPE in a `finally`; and that the job-queue plumbing of the flag was untested. 
Commit 4 addresses all four
   - checked the flag across mixed-version clusters: `VmWorkStop` is 
Java-serialized with an unchanged `serialVersionUID`, and a stream without the 
field reads false
   
   


-- 
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]

Reply via email to