Skip to content

[nexus] Break up nexus.rs into app/ directory. - #1023

Merged
smklein merged 10 commits into
mainfrom
nexus-breakup
May 6, 2022
Merged

smklein merged 10 commits into
mainfrom
nexus-breakup

Conversation

@smklein

@smklein smklein commented May 6, 2022 •

Copy link
Copy Markdown
Collaborator

Part of #1016

  • Splits nexus.rs - really, the impl Nexus - into individual files within the nexus/src/app subdirectory. A module-level comment in each file explains scope.
  • Originally, I expected to group the "container" resources (like project) and all the "object-creation-within-container" (like project_create_instance) functions within the same file. This ended up kinda non-intuitive, since object creation is frequently much more about the "object being created" than it is about the container. Instead, I opted for a more nuanced "grouped-by-relevance" approach, which tries to keep "all logic related to instances" in "instance.rs", "all logic related to disks" in "disk.rs", etc.
  • I re-shuffled the order of some calls, and tried to group related operations together. For CRUD operations, I tried to keep to that order: "create" -> "list" -> "fetch" -> "update" -> "delete".
  • A lot of this PR is subjective - feedback welcome!

@smklein

smklein commented May 6, 2022

Copy link
Copy Markdown
Collaborator Author

As of 4036456 , this splits the previously-largest-rust-file-in-Omicron nexus.rs into the following:

   974 ./instance.rs
   471 ./mod.rs
   344 ./disk.rs
   308 ./vpc.rs
   294 ./vpc_router.rs
   281 ./vpc_subnet.rs
   272 ./update.rs
   248 ./image.rs
   211 ./oximeter.rs
   150 ./silo.rs
   148 ./project.rs
   141 ./organization.rs
   139 ./sled.rs
   133 ./session.rs
   121 ./saga.rs
   103 ./test_interfaces.rs
    62 ./rack.rs

@smklein
smklein marked this pull request as ready for review May 6, 2022 02:19
@smklein smklein added nexus Related to nexus cleanup Code cleanliness labels May 6, 2022
@david-crespo

Copy link
Copy Markdown
Contributor

Definitely into the general idea. Glad to see the former nexus.rs layer explicitly called out as the "app" layer. Will look in more detail at the groupings but it all feels natural so far.

Comment thread nexus/src/app/mod.rs Resolved
Comment thread nexus/src/app/mod.rs Resolved
Comment thread nexus/src/app/mod.rs Resolved
Comment thread nexus/src/app/silo.rs Resolved
Comment thread nexus/src/app/sled.rs

// TODO-robustness we should have a limit on how many sled agents there can
// be (for graceful degradation at large scale).
pub async fn upsert_sled(

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.

I gather we've grouped things by the noun that they seem to relate to (e.g., "sled" here). I find it a little weird to combine the internal vs. external functions in this way. That is, upsert_sled is eventually going to do a whole bunch of work in response to the new information that a Sled Agent has started up...that all feels pretty unrelated to the public-facing sled CRUD functions.

sled_allocate() is different than both of these.

I felt a similar dissonance around saga.rs, where execute_saga() really has little to do with the saga fetch/list functions.

I don't know what else to suggest, though. Maybe a better structure will emerge when we flesh these things out more. (e.g., maybe upsert_sled will eventually become part of a stationkeeping submodule that monitors the rack's health and takes appropriate action as data comes in).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm still a little split on this - I'm not sure if this layer even needs to make a distinction of "internal" vs "external" APIs. After all, the internal_api and external_api directories in Nexus are sorta making this distinction for us, in a literal sense.

After all, if both interfaces (external and internal) poke at a sled, what's the issue with grouping them together? They'll be accessing the same underlying structures, and the implementations may end up needing to be aware of each other. As an example: The "notify_instance_changed" implementation is internal (called only by sled agent) but the external "change instance state" methods are aware of the sled agent "owning" instance state data.

Definitely agree though, we can keep iterating on this - this is my first cut at grouping things by related functionality, but this will undoubtedly keep changing.

@smklein
smklein merged commit 2e67373 into main May 6, 2022
@smklein
smklein deleted the nexus-breakup branch May 6, 2022 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code cleanliness nexus Related to nexus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants