Graceful Shutdown of Nova Services Part 3: Safe Termination Point¶
This spec implements Spec 3 of the nova-services-graceful-shutdown backlog spec. Part 1 split the new and in-progress requests via a second RPC server on the compute service and added a time based wait. Part 2 replaced the time based wait with a task-tracking system that tracks and logs the in-progress tasks, waits for them to finish. This spec for the part 3 defines safe termination point for operations. It audits the Nova operations, categorizes them into two categories: 1. Ok to abort 2. Wait to complete, and implements the logic so that every in-progress operation reaches to the safe termination point during graceful shutdown.
Problem description¶
After graceful shutdown part1 and part2, nova services (compute, conductor, and
scheduler) wait for the in-progress operations to finish before they shutdown.
That wait is limited to the configured graceful shutdown timeout (
manager_shutdown_timeout) and that is why wait only is not enough:
Some operations cannot complete within the wait time, and if they are interrupted by the shutdown timeout then they leave instances in an unwanted or unrecoverable state.
Task tracking (graceful shutdown part2) has some issues in migration tasks where tracked tasks are never ended because of cross-node coordination gaps. The source compute can fail or rollback migration without notifying the dest compute, so the dest compute task stays in-progress forever. During graceful shutdown service waits for full timeout and also logs that task as unfinished where actual operation is completed. Also, it can leave instance in unrecoverable state. Details are in bug 2166009 and bug 2162090:
Without a per-operation safe termination point, graceful shutdown can either hang on tasks that will never complete, or exit and interrupt operations that cannot be performed (due to DB/instance in unrecoverable state) again once service is up.
Use Cases¶
As an operator, when I gracefully shut down a service, I want each in-progress operation to either complete or abort cleanly, so that instances and other resources are always left in a usable, recoverable state.
As an operator, I want the service to not hang on tasks that can never complete due to cross-node coordination gaps, and I want nova to track tasks properly and finish them when actual operation is not in-progress.
As a user, if my operation is not completed during graceful shutdown, I want a clear error/state so that I know I can safely retry it once the service is back.
Proposed change¶
I would like to address both problems (mentioned in the Problem section) as part of this spec which makes graceful shutdown to make operations to a safe termination point so that those can be re-performed or in recoverable state. The scope of this spec is:
Audit all Nova operations for their safe termination point and decide when they can be aborted or wait for their completion. Every operation will be categorized into either ‘wait to complete’ (which is nothing but the current category for all operations) or ‘ok to abort’.
For ‘wait to complete’ operations, no change needed as shutdown already wait for them to complete.
For ‘ok to abort’ operations:
An operation which needs to be abortable will add the shutdown-signal checkpoints and abort handler. Operations without checkpoints and abort handler stay ‘wait to complete’, which is the default and the current behaviour.
Depends on operation, decide the safe abortable point so that shutdown can decide till which stage the operation can be aborted. This is the last checkpoint before/at which the operation can be aborted.
Shutdown-signal checkpoints:
Checkpoints will be added inside the operation so it can abort/revert itself. A check is added at early stage at the operation entry and before any expensive or time consuming steps. The early checks avoid doing work when shutdown is already in progress and operation is anyways going to be aborted at its later abortable checkpoints.
Mostly, each operation will have two checkpoints (per node specific part of that operation) but some operation can have more depends on the operation.
For example, cold migration/resize:
Destination checkpoint 1: Start of
prep_resize()Destination checkpoint 2: Before calling source’s
resize_instancewhich start copying the disk from source to dest.Source checkpoint 1: Start of
resize_instance()Source checkpoint 2: Before disk copy start.
self.driver.migrate_disk_and_power_off().
An abort handler will be added (reusing existing rollback paths where available) that performs the rollback and ends the tracked task in a
cancelledstate.
Existing abort/rollback methods will be used if exist otherwise a new abort/rollback way will be implemented.
Live migration already has a way for admin to abort it via abort live migration API. We will leave it to ‘wait to complete’ and if admin finds that it is taking time then they can abort it via API. For that, we need one change to move abort live migration API onto the second RPC server (the one that stays alive during shutdown) so it is not rejected as a new request and can update the in-progress task. Whether nova should abort long-running live migrations by itself will be revisited based on operator feedback.
Close the cross-node coordination gaps (bug 2166009, bug 2162090) so that every tracked task has the path to complete either successful or failed.
Operation categories¶
Every operation is categorized into one of the following safe termination points:
Wait to complete: The operation is not long running operation or they reach to the point where they cannot be aborted. Their safe termination point is to let them complete. For example, shutdown should let server pause to complete.Ok to abort: The operation can be aborted before it reaches to the stage where we cannot stop it and the instance/resources will be rolled back to the pre-operation (or recoverable/usable) state. For example, shelve a server can be aborted and server can be re-shelved once service is up.
Below is the operation wise categorization:
Operation |
Stage |
Category |
Safe termination action |
|---|---|---|---|
Cold migration / resize |
Source shutdown: before
|
Ok to abort |
Abort; set migration |
Source shutdown : during copy until
dest’s |
Wait to complete |
Disk copy already started so let it complete. |
|
Dest shutdown: before source’s
|
Ok to abort |
Abort before source start anything, set migration
|
|
Dest shutdown: after source’s
|
Wait to complete |
Source might have started copying the disk and dest does not know about status so let it complete. |
|
Snapshot / create image / backup, shelve |
Image upload / snapshot |
Ok to abort |
Abort upload, delete partial image, reset task state; shelve returns to active. |
Shelve offload |
|
Wait to complete |
Short, destructive teardown (destroy domain, drop allocations, detach volumes, unbind ports); let it finish. |
Build / rebuild / unshelve |
Before |
Ok to abort |
Rollback, reset instance state to previous one |
During/after |
Wait to complete |
Let it finish so the running guest and instance state stay consistent. |
|
Live migration |
Always |
Wait to complete |
Let it complete. Admin can make live migration to its safe termination either by let it complete or abort via abort live migration API. |
Revert resize |
|
Wait to complete |
Coordinate so the source finishes before shutdown completes. |
Confirm resize |
|
Wait to complete |
Let it finish so the old instance/resources are cleanly released. |
Evacuate |
Always |
Wait to complete |
Source host is down, let it complete to restore the instance. |
Rescue/unrescue/suspend/resume/pause/ unpause/reboot/start/stop |
state transition |
Wait to complete |
Short operation or guest state transition. |
Volume / interface attach / detach |
Device operation |
Wait to complete |
Device operations; wait so the instance and cinder neutron stay consistent. |
Delete instance |
Wait to complete |
Let it finish so resources are fully released. |
|
All other operations |
GET / query / console / diagnostics, metadata, small sync actions, etc. |
Wait to complete |
Short operation and mostly on DB. |
Mechanism¶
Service already knows which tasks are in-progress when shutdown starts. This spec adds, per ‘ok to abort’ operation, shutdown-signal checkpoints and an abort handler.
An operation with no such checkpoints defaults to ‘wait to complete’, which is nothing but the current behaviour.
For ‘ok to abort’ operations, the
safe abortable pointis the last stage at which the operation can be aborted cleanly; everything before it in the operation is also abortable.For optimization, each abortable operations will have at least two checkpoints. 1. start of the operation 2. before each expensive tasks. For most of the operations, the 2nd checkpoint will be the last checkpoint (
safe abortable point) but some complex operations can have more than two checkpoints.For operations that have a safe abortable point, an abort handler performs the rollback and leaves the instance/resources in a usable state. Existing abort/rollback methods are reused where available otherwise a rollback/abort method is implemented. The abort handler ends the tracked task in a cancelled state so that we can log which operations are aborted by Nova during shutdown.
During graceful shutdown the service manager sets the shutdown signal and waits for the in-progress tasks to drain, up to
manager_shutdown_timeout. The manager does not abort any task, instead each abortable operation will self-abort themselves at various checkpoints. An operation with no safe abortable point (default), or one that has already passed its last safe point, runs to completion and the manager waits for it untilmanager_shutdown_timeout.Each abort is logged with the instance UUID, request-id, operation.
Example, cold migration/resize:
On the destination shutdown:
def _prep_resize(self, context, image, instance, flavor, ..., migration, ...):
# Checkpoint 1: Early abort
if self._shutdown_in_progress.is_set():
self.abort_resize_at_dest(context, instance, migration)
return
instance.new_flavor = flavor
...
with self.rt.resize_claim(context, instance, flavor, node,
migration, allocs, ...) as claim:
# Checkpoint 2: Last safe abortable point
if self._shutdown_in_progress.is_set():
self.abort_resize_at_dest(context, instance, migration)
return
self.compute_rpcapi.resize_instance(context, instance,
claim.migration, image, flavor,
request_spec, clean_shutdown)
def abort_resize_at_dest(self, context, instance, migration):
self.rt.drop_move_claim_at_dest(context, instance, migration)
self._revert_allocation(context, instance, migration)
instance.task_state = None
instance.save()
migration.status = 'cancelled'
migration.save()
self._end_pending_dest_resize_task(instance.uuid, status='cancelled')
LOG.info("prep_resize aborted at safe point due to graceful "
"shutdown", instance=instance)
On the source shutdown:
def _resize_instance(self, context, instance, migration, ...):
# Checkpoint 1: Early check:
if self._shutdown_in_progress.is_set():
self.abort_resize_at_source(context, instance, migration)
return
migration.status = 'migrating'
migration.save()
instance.task_state = task_states.RESIZE_MIGRATING
instance.save(expected_task_state=task_states.RESIZE_PREP)
# Checkpoint 2: Last safe abortable point
if self._shutdown_in_progress.is_set():
self.abort_resize_at_source(context, instance, migration)
return
disk_info = self.driver.migrate_disk_and_power_off(...)
...
self.compute_rpcapi.finish_resize(...)
def abort_resize_at_source(self, context, instance, migration):
# Reuse the rollback that resize failures already perform.
self._revert_allocation(context, instance, migration)
instance.task_state = None
instance.save()
migration.status = 'cancelled'
migration.save()
LOG.info("Cold migration aborted at safe point due to graceful "
"shutdown", instance=instance)
Closing the cross-node coordination gaps¶
For an operation to reach a safe termination point on both nodes, the node
that holds the task must be able to drive it to an end state even when the
other node that failed/rolled back but did not inform the node has stuck
task. Instead of adding more cross-node RPC requests between nodes, the
primary mechanism uses the shared Migration record as the coordination
channel and decide to end the hanging task.
This relies on the Migration record being updated so each node can see the
updates state. In a single cell this is reliable as the source and destination
share the same cell DB and read/write the same Migration record. If in any
case, it is missed to update then it is a bug to fix.
The cross-cell case is best-effort. There is a separate Migration record
per cell, the two records are kept in sync only when the conductor updates both
cell DB records. The conductor does this during the cross-cell migration (for
cross cell cold migration case). If the records are not updated then the
hanging node falls back to waiting until manager_shutdown_timeout. As CCLM
is not avaialble at the time of this spec writting, it is kept out of scope.
graceful_shutdown()monitors the in-progress migration tasks and self-terminates the hanging tasks. For each migration task, it will keep monitor theMigrationrecord. If one node has already moved the migration toerror``| ``failed, then other node will drive the task to its own end state and stops waiting on it.bug 2166009 (destination task never ended on source rollback): a hanged
live_migration_at_destis ended viarollback_live_migration_at_destination(); a hanged resize is ended via theprep_resize_at_destcleanup.bug 2162090 (
revert_resizecan leave a VM unrecoverable): per the 2027.1 PTG, therevert_resizeRPC cast from the destination to the source (finish_revert_resize) is converted to a call, so the destination can know whether the source finished the revert and can recover it if the source did not.
Alternatives¶
Keep the behaviour of only waiting-and-logging, and never aborting. This interrupts abortable operations at process exit with no clean state, and still hangs on tasks that can never complete.
Fix cross-node coordination gaps (bug 2166009 / bug 2162090) by adding more RPC requests between nodes.
For cold migration/resize, abort at a later point than the checkpoints chosen above (for example after the disk copy but before
finish_resize()).Source shutdown - not aborting before
migrate_disk_and_power_off(): The copy is the long-running (if VM has large ephemeral disk) task and there is no safe way to stop it mid-copy without implementing a new logic to poll and copy the disk. Aborting after the copy also needs a much heavier rollback: delete the already-copied disk on the dest and power on the VM back on at the source. User will see VM power off and on.Destination shutdown - not aborting before calling source’s
resize_instance(): Dest makes RPC cast to sourceresize_instance()and it does not know what stage the source is and dest cannot take the decision to abort at this stage. Dest can only wait for source to complete it and callfinish_resizeon dest. But at this point the disk has already been copied (50% of the resize work) to the dest and the VM is in powered off on the source, so aborting it at this stage does not make sense.
Data model impact¶
None.
REST API impact¶
The abort live migration API RPC requests will be moved to the second RPC server so it is not rejected while a graceful shutdown is in progress.
Security impact¶
None.
Notifications impact¶
None.
Other end user impact¶
None.
Performance Impact¶
None to any operations performance but it will improve the graceful shutdown performance to shutdown early by aborting some of the long running tasks.
Other deployer impact¶
None.
Developer impact¶
Developers adding a new RPC operation to a service manager should check and categorize it ‘ok to abort’ if needed and provide an abort handler.
Upgrade impact¶
None.
Implementation¶
Assignee(s)¶
Primary assignee:
gmaan
Other contributors:
None
Feature Liaison¶
None
Work Items¶
Fix the cross-node coordination gaps by adding monitoring logic for the
Migrationrecord so hung migration tasks are driven to an end state.Convert the
revert_resize→finish_revert_resizeRPC cast to a call and revert the destination revert resize if needed.Mark the ‘ok to abort’ operations and decide their safe abortable point (the last stage at which they can be aborted cleanly).
Add the shutdown-signal checkpoints inside the ‘ok to abort’ operations (at entry, before any expensive step, and at the last safe abortable point) so they self-abort.
Implement the abort handlers for the ‘ok to abort’ operations, reusing existing rollback/abort paths where available, ending the tracked task in a
cancelledstate with clear logging.For live migration, move abort live migration API RPC requests to the second RPC server which is alive during shutdown.
Unit and functional tests.
Dependencies¶
None.
Testing¶
Unit and functional tests covering, for each category, the behaviour on graceful shutdown (abort-and-rollback vs wait-to-complete).
Functional tests for the cross-node coordination fixes.
Add more testing in graceful-shutdown-job to perform some testing at post-run phase of jobs.
Documentation Impact¶
Document the ‘ok to abort’ operations table.
References¶
Backlog spec: https://specs.openstack.org/openstack/nova-specs/specs/backlog/approved/nova-services-graceful-shutdown.html
Part 1:
Part 2:
Bugs:
PTG discussions:
History¶
Release Name |
Description |
|---|---|
2027.1 Indri |
Introduced |