Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return richer enum types from datastore functions #6604

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

jmpesp
Copy link
Contributor

@jmpesp jmpesp commented Sep 19, 2024

Create new enum types and return those to give more information to callers:

  • create_region_snapshot_replacement_step and insert_region_snapshot_replacement_step now return InsertRegionSnapshotReplacementStepResult

  • volume_replace_region and volume_replace_snapshot now return VolumeReplaceResult

Notably, VolumeReplaceResult::ExistingVolumeDeleted replaces the previous error type TargetVolumeDeleted, and is not an error, allowing the caller to take action of the existing volume was deleted.

This commit was peeled off work in progress to address #6353.

Create new enum types and return those to give more information to
callers:

- `create_region_snapshot_replacement_step` and
  `insert_region_snapshot_replacement_step` now return
  `InsertRegionSnapshotReplacementStepResult`

- `volume_replace_region` and `volume_replace_snapshot` now return
  `VolumeReplaceResult`

Notably, `VolumeReplaceResult::ExistingVolumeDeleted` replaces the
previous error type `TargetVolumeDeleted`, and is not an error, allowing
the caller to take action of the existing volume was deleted.

This commit was peeled off work in progress to address oxidecomputer#6353.
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

I had a few pretty minor suggestions around logging and assertions, hope they're helpful?

@@ -120,6 +120,7 @@ pub use rack::RackInit;
pub use rack::SledUnderlayAllocationResult;
pub use region::RegionAllocationFor;
pub use region::RegionAllocationParameters;
pub use region_snapshot_replacement::InsertRegionSnapshotReplacementStepResult;
Copy link
Member

Choose a reason for hiding this comment

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

nitpicky, take it or leave it: if this wasn't pub used and we instead made the region_snapshot_replacement module public, then this could just be region_snapshot_replacement::InsertStepResult or something and code that depends on it could import it to avoid having to type out the whole thing, or not do that if it needs to be disambiguated?

not a big deal either way though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this, done in d2135f2

use async_bb8_diesel::AsyncConnection;
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::prelude::*;
use omicron_common::api::external::Error;
use uuid::Uuid;

#[must_use]
#[derive(Debug, PartialEq)]
Copy link
Member

Choose a reason for hiding this comment

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

any reason to not also derive Eq?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope! d2135f2

existing_step_id,
} = result
else {
panic!("wrong return type");
Copy link
Member

Choose a reason for hiding this comment

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

could we have this panic include result so that if we hit it, the test's failure output includes the unexpected value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, done in d2135f2

existing_step_id,
} = result
else {
panic!("wrong return type");
Copy link
Member

Choose a reason for hiding this comment

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

similarly, might be good for this panic to show what the wrong thing was?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep: d2135f2

let InsertRegionSnapshotReplacementStepResult::Inserted { step_id } =
result
else {
panic!("wrong return type");
Copy link
Member

Choose a reason for hiding this comment

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

...and this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep! d2135f2

Comment on lines 576 to 579
Err(ActionError::action_failed(format!(
"existing volume {} deleted",
old_volume_id
)))
Copy link
Member

Choose a reason for hiding this comment

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

should this be Error::conflict? i suppose it doesn't really matter since these sagas are triggered by a background task, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even so, it should be a conflict, yeah: done in d2135f2

@@ -361,20 +364,40 @@ async fn rsrss_replace_snapshot_in_volume(
.await
.map_err(ActionError::action_failed)?;

Ok(())
info!(
Copy link
Member

Choose a reason for hiding this comment

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

i wonder whether this should be info or debug?

it might also be nice to include the volume ID and stuff here, unless that's in the saga context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to debug in d2135f2, and yeah, same answer - it's even more so in the context for this saga because the entire replace params is.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -554,7 +555,30 @@ async fn srrs_replace_region_in_volume(
.await
.map_err(ActionError::action_failed)?;

Ok(())
info!(log, "replacement returned {:?}", volume_replace_region_result);
Copy link
Member

Choose a reason for hiding this comment

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

i wonder whether this should be info or debug?

it might also be nice to include the volume ID, region ID, and stuff here, unless that's in the saga context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to debug in d2135f2

yeah, all that context should be in the saga context

@jmpesp jmpesp enabled auto-merge (squash) September 20, 2024 20:43
@jmpesp jmpesp merged commit d00b684 into oxidecomputer:main Sep 20, 2024
16 checks passed
@jmpesp jmpesp deleted the return_richer_enum_types branch September 20, 2024 21:21
hawkw pushed a commit that referenced this pull request Sep 21, 2024
Create new enum types and return those to give more information to
callers:

- `create_region_snapshot_replacement_step` and
`insert_region_snapshot_replacement_step` now return
`InsertRegionSnapshotReplacementStepResult`

- `volume_replace_region` and `volume_replace_snapshot` now return
`VolumeReplaceResult`

Notably, `VolumeReplaceResult::ExistingVolumeDeleted` replaces the
previous error type `TargetVolumeDeleted`, and is not an error, allowing
the caller to take action of the existing volume was deleted.

This commit was peeled off work in progress to address #6353.
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