Repository navigation
Conversation
unmanaged zpools This commit reworks `InstanceManager::use_only_currently_managed_zpools` to ensure that it cannot block the `InstanceManager` main loop indefinitely. This is accomplished by spawning a separate task for each instance immediately, which then waits for the zone to start if it is in the process of starting, checks if the zpool is managed, and terminates it if it is not. This also removes `get_filesystem_zpool` from the main instance request channel, so that a full request channel cannot cause us to skip a Propolis zone, and instead publishes the filesystem zpool using a `SetOnce`. Because there are no HTTP entrypoints that call `get_filesystem_zpool`, it need not be an actor-style request/response thingy like the actual API requests.
| /// | ||
| /// This returns `None` if the zone is running but its root filesystem is on | ||
| /// the ramdisk rather than a zpool. | ||
| pub async fn wait_for_filesystem_zpool(&self) -> Option<&ZpoolName> { |
There was a problem hiding this comment.
Tiny nit - ZpoolName is Copy (it's just a UUID wrapped in a couple layers of enums), so I think we could return Option<ZpoolName> here if you'd like.
| // we may as well jam the propolis ID in there... | ||
| let log = self.log.new(o!("propolis_id" => id.to_string())); | ||
| let instance = instance.clone(); | ||
| tokio::spawn(async move { |
There was a problem hiding this comment.
is it a problem that this basically spawns a bunch of tasks with no backpressure, since it never awaits them?
There was a problem hiding this comment.
🤷♀️ i think it's a much less bad problem than exerting backpressure on the entire InstanceManager loop. In the longer term, I think we may want to consider decoupling all of this from that and having some way to limit the number of these tasks, but I'm still a lot less concerned about it than the alternative?
| // be set up before checking if it is using an unknown zpool, and we | ||
| // do not want to block the main instance-manager loop waiting for | ||
| // all instances to finish having their Propolis zones set up. | ||
| let current_zpools = current_zpools.clone(); |
There was a problem hiding this comment.
I'm not sure if this is new, but is it possible for this to race with setting up an instance?
E.g., imagine the following:
- Someone starts a propolis instance (
put_statethrough the instance manager, which hands off to the instance task). TheInstanceRunnerhas not chosen which zpool to use yet. But it is registered, and shows up inself.jobs. - The
InstanceManagercallsuse_only_currently_managed_zpools, for some reason (maybe an old zpool got removed. Doesn't really matter. just needs to fire somehow). Let's imagine this is the set of pools: {zpool = A, zpool = B}. Since we clone thecurrent_zpools, that's what we'll see later in the spawned task too. - Suppose a new {zpool = C} is added to the set of "currently managed zpools".
- Suppose the instance picks that new zpool C for it's root filesystem, and starts.
- ... Now the spawned tasks here run to completion.
use_only_currently_managed_zpoolswould have an out-dated view of current zpools, and would kill the new instance, even though it's using a valid zpool.
I think this issues comes from "the instance manager / instance both monitoring data from the reconciler, but reading them mostly-independently". I wonder if we could mitigate this by only letting instances choose pools seen by the instance manager, to ensure "the view used by instances cannot get ahead of the view used by the instance manager".
There was a problem hiding this comment.
I think this issues comes from "the instance manager / instance both monitoring data from the reconciler, but reading them mostly-independently". I wonder if we could mitigate this by only letting instances choose pools seen by the instance manager, to ensure "the view used by instances cannot get ahead of the view used by the instance manager".
Hmm. Is another option "only monitor from instance"? It's already watching for a termination signal; could it also watch for .changed() and terminate itself if the zpool it picked is gone at some later point?
There was a problem hiding this comment.
Yeah, I bet that could work too
| /// This returns `None` if the zone is running but its root filesystem is on | ||
| /// the ramdisk rather than a zpool. | ||
| pub async fn wait_for_filesystem_zpool(&self) -> Option<&ZpoolName> { | ||
| self.root_fs_zpool.wait().await.as_ref() |
There was a problem hiding this comment.
If we register a propolis zone, but never start it, does anything stop this task from waiting? Is that possible?
(or I guess, if the startup fails before we set root_fs_zpool?)
There was a problem hiding this comment.
Argh, yup. I think we need the instance runner task to send None when it terminates, or something.
There was a problem hiding this comment.
Read @jgallagher 's feedback in #11492 (comment) before doing this! I wonder if we move the "watching responsibility" to the instance itself, if that simplifies the lifetime, and avoids the need to "wait for a filesystem zpool" at all
| let Some(filesystem_pool) = | ||
| instance.wait_for_filesystem_zpool().await | ||
| else { | ||
| // Zone is not on the ramdisk, so skip it. |
There was a problem hiding this comment.
Doesn't this case (function returns None) mean the zone is on the ramdisk?
There was a problem hiding this comment.
Yeah, that's what I meant. Whoops.
There was a problem hiding this comment.
FWIW #11495 gets rid of this branch entirely, since we never actually start instance zones on ramdisks.
| @@ -1090,31 +1090,39 @@ impl InstanceManagerRunner { | |||
There was a problem hiding this comment.
FWIW as written, I don't think this function needs to be async - it's not awaiting anything, right?
bnaecker
left a comment
There was a problem hiding this comment.
Another good simplification, thanks!
| // Zone is not on the ramdisk, so skip it. | ||
| return; | ||
| }; | ||
| if !current_zpools.contains(filesystem_pool) { |
There was a problem hiding this comment.
Related to Sean's question above, should we wait until this point to actually fetch the set of current pools? By the time the instance has started, this view could be outdated.
| let current_zpools = current_zpools.clone(); | ||
| // Since we must clone the logger anyway in order to spawn the task, | ||
| // we may as well jam the propolis ID in there... | ||
| let log = self.log.new(o!("propolis_id" => id.to_string())); |
There was a problem hiding this comment.
I might add the instance ID to the logger too.
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
This commit reworks
InstanceManager::use_only_currently_managed_zpoolsto ensure that it cannot block theInstanceManagermain loop indefinitely. This is accomplished by spawning a separate task for each instance immediately, which then waits for the zone to start if it is in the process of starting, checks if the zpool is managed, and terminates it if it is not. This also removesget_filesystem_zpoolfrom the main instance request channel, so that a full request channel cannot cause us to skip a Propolis zone, and instead publishes the filesystem zpool using aSetOnce. Because there are no HTTP entrypoints that callget_filesystem_zpool, it need not be an actor-style request/response thingy like the actual API requests.See: #11462 (comment) and #11462 (comment)