Skip to content

instance lifecycle: allow stopping instances stopped for sled evacuation - #11639

Merged
jgallagher merged 4 commits into
mainfrom
john/stop-instances-in-sled-evacuating
Oct 30, 2026
Merged

jgallagher merged 4 commits into
mainfrom
john/stop-instances-in-sled-evacuating

Conversation

@jgallagher

Copy link
Copy Markdown
Contributor

This allows users to stop an instance that appears stuck in rebooting but is actually stopped for sled evacuation and waiting to be reincarnated, as described in #11504 (review).

@jgallagher
jgallagher requested review from hawkw and karencfv October 30, 2026 13:14
Comment thread nexus/src/app/instance.rs
// still allow some changes in this state (in particular: the
// user should be able to stop it).
InstanceState::Rebooting => {
match instance_state.nexus_state {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maching on nexus_state inside the match on InstanceState feels a little grimy, since the nexus_state was part of the input to pick which InstanceState we're in. But I think it's still worth doing purely as an "ensure we don't have some other combination of internal states we don't expect" measure?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's a bit unfortunate how much it complicates this code, but I think I agree with you that it's correct. A quasi-related change I've been working on will probably also require matching on internal states here, too (see #11608 (comment)). So, I think it's probably the right thing.

@hawkw hawkw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, with a couple notes.

Comment thread nexus/src/app/instance.rs Outdated
// instances. But there's no source VMM to migrate from.
InstanceStateChangeRequest::Migrate(_) => {
return Err(Error::invalid_request(
"cannot migrate instance that was stopped \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be slightly nicer to say

Suggested change
"cannot migrate instance that was stopped \
"cannot migrate instance that is rebooting \

because that's how it appears to the user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I waffled on this one quite a lot (e.g., is it okay to say "due to sled evacuation" when that's not really a user-visible state) before realizing that a user can't actually see it - there's no external API to induce a VM migration. This is only reachable via the internal lockstep API. But I'm happy to reword it in case that changes.

Comment thread nexus/src/app/instance.rs Outdated
Comment on lines +289 to +307
impl InstanceStateChangeRequestAction {
/// Construct a [`Self::UpdateRuntime`] with a runtime state constructed by
/// updating `prev_runtime` with `new_nexus_state` (and the expected
/// accounting for a state change, such as bumping the generation).
fn update_runtime(
prev_runtime: db::model::InstanceRuntimeState,
new_nexus_state: db::model::InstanceState,
) -> Self {
Self::UpdateRuntime(db::model::InstanceRuntimeState {
time_updated: chrono::Utc::now(),
generation: InstanceStateGeneration::from(prev_runtime.generation)
.next()
.into(),
nexus_state: new_nexus_state,
..prev_runtime
})
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice, thanks for adding it! i do think there might be places outside of this module (i.e. in the instance-update saga) where we might want to use the internal part that takes a state and bumps the generation and sets the new state. so, I wonder a bit if it might be better to have an InstanceRuntimeState::update_state(self, new_nexus_state) that's defined in db ::model, so that more code can use it, and have this helper use that?

Not a blocker here though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to InstanceRuntimeState::with_new_nexus_state() in 1289b81

@jgallagher
jgallagher merged commit fdac116 into main Oct 30, 2026
19 checks passed
@jgallagher
jgallagher deleted the john/stop-instances-in-sled-evacuating branch October 30, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants