Repository navigation
[sled-agent] remove queueing and backpressure in forceful termination - #11462
Conversation
| ) { | ||
| self.terminate_tx.send_if_modified(|current| { | ||
| if current.is_some() { | ||
| return false; |
There was a problem hiding this comment.
Could/should this be a SetOnce instead of a watch channel? Assuming "first state_owner to get here wins" is correct, at least - I don't really understand that side of it. It looks like InstanceRunner uses that value to decide whether to publish the state to Nexus - should we allow a state owner of Nexus to overwrite an earlier state owner of Runner? (That seems inherently racy though, which just leaves me with more questions 😬)
There was a problem hiding this comment.
Could/should this be a
SetOnceinstead of a watch channel?
Yes, it should. The only reason it isn't a SetOnce is that I forgot that existed.
Assuming "first
state_ownerto get here wins" is correct, at least - I don't really understand that side of it. It looks likeInstanceRunneruses that value to decide whether to publish the state to Nexus - should we allow a state owner ofNexusto overwrite an earlier state owner ofRunner? (That seems inherently racy though, which just leaves me with more questions 😬)
So, this implements the same behavior as the current thing: whichever termination request gets into the channel first decides whether the state gets published to Nexus or not. I've been trying to avoid changing any of the behavior here with this change except for the issue of the backpressure when the old termination channel fills up.
I think the VmmStateOwner stuff may deserve some re-thinking in the future as well, I always found this confusing. I'll have to dig up some of Greg's old commits and try to remember why we even needed to have the "sometimes don't publish state to Nexus" behavior in the first place.
a66832a to
67e4506
Compare
It turns out that the only reason the tests for this module were `#[cfg(target_os = "illumos")]` was because they used `VmmReservoir::stub_for_test()`, which was illumos-only...but because that's a _stub for tests_ which **doesn't** actually manage a real VMM reservoir, there's really no reason for it to be. All these tests actually run fine on Linux and macOS (and, presumably, also Windows? I assume?), so let's let them run on more people's dev machines. Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
ec0df90 to
653409f
Compare
Signed-off-by: Eliza Weisman <[email protected]>
| /// Released in 1984 and starring Arnold Schwarzenegger and Linda Hamilton, _The | ||
| /// Terminator_ is an American science fiction film used to request the forceful | ||
| /// termination of a Propolis zone. This is used by the `ensure_unregistered` |
bnaecker
left a comment
There was a problem hiding this comment.
Looks like some nice cleanup, thanks! Two small suggestions, not blocking.
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
| let (tx, rx) = oneshot::channel(); | ||
| // This will fail if the tx has been dropped, which we just...don't do. | ||
| let _ = instance.get_filesystem_zpool(tx); | ||
| let Ok(Ok(Some(filesystem_pool))) = rx.await else { |
There was a problem hiding this comment.
I don't think this bit from the PR description is quite right:
This means InstanceManager::use_only_currently_managed_zpools can no longer block the entire InstanceManager from making progress forever
because an instance stuck in an infinite retry loop will never respond to this message. Ben's PR already accounted for this by moving this bit off into a new task, and I think this PR's changes means that task can no longer deadlock around termination. But just wanted to note it.
There was a problem hiding this comment.
Oh, ugh, yeah, that's true. Looking at it, since the RunningZone's root filessytem can't change once it's started, I don't get why this part has to be a whole request-response thing either? It seems like it could also go in a SetOnce that the InstanceRunner publishes once the zone has started, so that callers don't need to wait on that, either.
I'd be happy to put up a change for that too, or we could do it in @bnaecker's branch?
There was a problem hiding this comment.
I'd advocate for a dedicated PR, given that approximately none of the recent PRs have unambiguously fixed subtle locking issues without introducing others :)
There was a problem hiding this comment.
I have a change for this almost ready to PR, then!
There was a problem hiding this comment.
Hm, actually, after looking closer at it, this part is also a bit sketchy, since if the zone is not yet ensured, we need to wait until a potentially-in-progress propolis ensure finishes. I think we still need to spawn a task as Ben's PR is currently doing, but rather than contending over a single big shared request channel, that task could wait() for the zpool name to be set and then check if the (potentially newly created) zpool is one of the ones that we are getting rid of. I think it actually would make more sense to figure that out in Ben's branch along with the other stuff...
There was a problem hiding this comment.
I think there might still be benefit in doing it that way, because we can avoid the channel filling up, and it's a bit simpler to say instance.filesystem_zpool.wait().await then send requests in a retry loop, but we still have to spawn a task that waits until a potential instance ensure completes regardless.
There was a problem hiding this comment.
I guess, in this case, leaving it "actor-y" is probably the best way to ensure that we don't race with creating the zone, but maybe the move here is just to not use try_send in get_filesystem_zpool id the only caller is in a spawned task...
This change makes it so that sled-agent can ensure that it's using only currently-managed zpools without using `use_only_currently_managed_zpools`. :) At present, the mechanism that sled-agent uses to ensure that any Propolis zones whose zone-root filesystems are on zpools that no longer exist is the `InstanceManager::use_only_currently_managed_zpools` method. This is called in the `InstanceManager` main loop when the set of currently-managed zpools changes, and works by looping over all managed instances, asking them which zpool the root filesystem for the Propolis zone is on, and then telling the `InstanceRunner` to terminate the Propolis zone if it is on a zpool that is no longer managed. Because this occurs within the `InstanceManager` main loop, it's important that nothing that happens here can prevent that loop from making progress indefinitely, as it would prevent any unrelated instance management operations from running. In #11492, I made an attempt to tidy this up a bit by having the `InstanceRunner` publish its zpool separately from its main request channel. After thinking it through, though, @smklein, @jgallagher, and I all came to the conclusion (see [this comment][1]) that there's actually a much better way of doing this. Rather than having the `InstanceManager` loop over all *instances* and check if they are using un-managed zpools, we can just give the `watch` channel of currently managed zpools to each `InstanceRunner`, and have it wait for changes to that set and check whether its zpools are still in the currently managed set. This avoids a lot of the potential raciness with publishing the zpool name once the zone is running, since we can just wait to spawn a task to wait for changes to the set of currently-managed zpools only once a zone is actually running. After that point, the zpool name will never change, and we cannot race with creating the zone *or* get stuck if the zone fails to start. This simplifies a lot of other aspects of the implementation, too, since it makes one of the two paths to instance termination completely internal to the `instance.rs` module, and we no longer have to do any of this work in the `InstanceManager` main loop. We no longer need the `GetFilesystemZpool` request to the `InstanceRunner` actor at all, because the task is now spawned with the zpool name once it's determined. Building on the changes to termination in #11462, the entire "zpool no longer managed, terminate propolis forcefully" path is now completely separate from the synchronous (well, async-but-actor-blocking) request/response channels in both `InstanceManager` and `InstanceRunner`. Closes #11492 [1]: https://github.com/oxidecomputer/omicron/pull/11492/changes/BASE..837f552c06380587eba3526da5236cce68983bea#r4275100226

The sled-agent has a mechanism to request the "rude" or "forceful"
termination of a VMM process. Forceful termination does not send a
request to Propolis to gracefully stop the instance, and instead
attempts to immediately destroy the Propolis zone and tear down all
sled-agent-internal state related to that instance. Unlike other
requests to operate on an instance, forceful termination bypasses the
queue of requests to the VMM's
InstanceRunnertask, and if a requestto the propolis-server is currently in progress, it will cancel that
request immediately. This is intended to ensure that even if the
propolis-server process has gotten stuck handling a request for some
reason, and therefore, the
InstanceRunneris in turn stuck waitingfor that request to complete, the stuck VMM process can still be killed
and its zone cleaned up regardless. See PRs #6915, #7928, and #7548 for
additional context around why this mechanism is necessary.
Unfortunately, the way this is currently implemented has some...issues,
which came up while reviewing PR #11456. The termination request is
currently sent using a
tokio::sync::mpscchannel, which means that thechannel can become full, and callers must handle backpressure. This is
necessary because callers currently wait for the termination to
complete by sending a
tokio::sync::oneshot::Senderover thetermination-request channel, which the
InstanceRunnerwill send toonce the VMM has been terminated. #11456 introduces an infinite retry
loop to the termination sequence in order to ensure the zone is
destroyed successfully. Because backpressure is exerted on callers who
request termination if the termination request channel has filled up,
this means that the infinite retry loop there will put callers in a
position where they must either load-shed (and therefore be unable to
guarantee that the termination request has ever made it through), or
wait indefinitely for their request to be sent. This was scary to see,
so I wanted to see if it could be avoided.
This branch changes the implementation of the termination mechanism to
remove the use of the
mpscchannel. This is based on the observationthat the goal here is really just to communicate that "you need to shut
down", and if multiple callers request that, their requests need not be
handled individually: in practice, in the current design, the first such
request will actually result in termination, and all the others will sit
in the queue until the termination sequence has completed and the
InstanceRunnerdrains any other requests. The only reason it worksthis way today is that a similar
mpscrequest channel withoneshotresponses is used to place HTTP requests in the queue of the
InstanceManagerfor dispatching to the individualInstanceRunnertasks, so the same oneshot
txen could be sent all the way through tothe runner.
Since there is no actual need to handle these requests individually,
though, we can replace the
mpscandoneshotwith a pair oftokio::sync::SetOncechannels: one to signal the termination request,and another to publish that it has completed. This way, the first
caller to request termination sets the
signalledSetOnce, andsubsequent callers can just see that it has already been signalled
without having to wait on a
mpscchannel. Callers which need to waitfor termination to complete and receive the final state (in this case,
the
ensure_unregisteredHTTP endpoint) can then wait for the otherSetOnce. Meanwhile, callers that don't actually need to wait forthe termination sequence to complete can now choose not to wait for
that while still knowing that it has been successfully signalled. This
means
InstanceManager::use_only_currently_managed_zpoolscan nolonger block the entire
InstanceManagerfrom making progress forever,even once #11456 changes the termination process to retry forever when
destroying the zone.
Other than the change to stop waiting for the termination to complete
in
InstanceManager::use_only_currently_managed_zpools, I've tried topreserve the existing behavior as closely as possible. Just like in the
previous code, the first caller to request termination gets to
determine the
VmmStateOwner(i.e. whether or not the final state ispublished to Nexus). This may deserve to be revisited, and perhaps
simplified, later, but this change should leave it the way it was until
then.