Skip to content

[nexus] factor out instance management into free functions - #5622

Merged
hawkw merged 4 commits into
mainfrom
eliza/instance-refactor
Apr 26, 2024
Merged

hawkw merged 4 commits into
mainfrom
eliza/instance-refactor

Conversation

@hawkw

@hawkw hawkw commented Apr 25, 2024

Copy link
Copy Markdown
Member

Currently, the instance state management code in nexus is implemented as methods on the Nexus type. This is problematic, as these methods can only be called in HTTP endpoints, and not from background tasks or sagas. For example, as part of #5611, I needed to call the Nexus::notify_instance_updated method from a background task, which isn't possible with the current factoring. Therefore, this PR moves that method and its dependencies, as well as all the methods in the instance_network module into free functions that can be called without a Nexus reference.

The Nexus methods are left in place in order to avoid having to update all the callers as part of this PR, but they now just call into the free functions. The free functions take a few more arguments that are provided by the &self reference in the Nexus methods, such as the internal DNS Resolver and opctx_alloc, so the methods pass these in from &self, making them a bit more convenient to call when a Nexus reference is available. For both of those reasons, I thought keeping them around was the right thing to do.

I had briefly considered moving this code to a new nexus-instances crate, but it seemed a bit iffy to me as notify_instance_updated also unregisters an Oximeter producer, and I didn't love the idea of moving Oximeter-related code to a nexus-instances crate --- perhaps it also ought to go in a nexus-oximeter crate, or something, but that felt like a rabbit hole that I was afraid I might just end up going down forever, so I'll save it for later.

If there are any functional changes as part of this PR, I've made a very bad mistake; this should be a pure refactor...

@hawkw
hawkw requested review from andrewjstone, bnaecker, internet-diglett and smklein and removed request for bnaecker April 25, 2024 18:21
@hawkw
hawkw force-pushed the eliza/instance-refactor branch from 356facd to 503ad20 Compare April 25, 2024 19:16

@smklein smklein left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for refactoring this into a separate PR! I appreciate this mechanical stuff being easier to look at

@hawkw
hawkw enabled auto-merge (squash) April 25, 2024 19:56
@hawkw
hawkw merged commit 52aa9cf into main Apr 26, 2024
@hawkw
hawkw deleted the eliza/instance-refactor branch April 26, 2024 00:30
sunshowers added a commit that referenced this pull request Apr 26, 2024
Conflict between #5596 and #5622.

* #5596 changed `DataStore::sled_list` to take a `SledFilter` argument
-- and `Nexus::sled_list` always uses `InService`.
* #5622 made the functions call `DataStore::sled_list` instead of
`Nexus::sled_list`

Not entirely sure that `InService` is correct, but it seems fine to just
have all non-expunged sleds here for now.
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