-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
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.
There was a problem hiding this 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; |
There was a problem hiding this comment.
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 use
d 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.
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! d2135f2
Err(ActionError::action_failed(format!( | ||
"existing volume {} deleted", | ||
old_volume_id | ||
))) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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
andinsert_region_snapshot_replacement_step
now returnInsertRegionSnapshotReplacementStepResult
volume_replace_region
andvolume_replace_snapshot
now returnVolumeReplaceResult
Notably,
VolumeReplaceResult::ExistingVolumeDeleted
replaces the previous error typeTargetVolumeDeleted
, 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.