oxidecomputer / oxidecomputer/omicron
`volume_repair_insert_in_txn` should return its own error
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 572
- Forks
- 97
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 96
Description
This issue tracks a suggestion during the review of #7046:
If possible it might be nice to have volume_repair_insert_in_txn return its own error enum so that we're not relying on it returning this specific message appearing in this error.
Something like:
diff --git a/nexus/db-queries/src/db/datastore/volume_repair.rs b/nexus/db-queries/src/db/datastore/volume_repair.rs
index 598d9d77a..a910a12ef 100644
--- a/nexus/db-queries/src/db/datastore/volume_repair.rs
+++ b/nexus/db-queries/src/db/datastore/volume_repair.rs
@@ -20,6 +20,30 @@ use diesel::result::Error as DieselError;
use omicron_common::api::external::Error;
use uuid::Uuid;
+pub enum VolumeRepairInsertError {
+ /// Another lock exists for this Volume
+ Conflict,
+
+ /// Volume was hard-deleted or never existed
+ VolumeNotFound { volume_id },
+}
+
+impl VolumeRepairInsertError {
+ pub fn into_external_error(self) -> Error {
+ match self {
+ Self::Conflict => {
+ Error::conflict("volume repair lock")
+ }
+
+ Self::VolumeNotFound { volume_id } => {
+ Error::invalid_request(format!(
+ "cannot create record: volume {volume_id} does not exist"
+ ))
+ }
+ }
+ }
+}
+
impl DataStore {
/// Insert a volume repair record, taking a "lock" on the volume pointed to
/// by volume id with some repair id.
with the required propagation of this enum up from functions that call it, so that those callers can decide what to do.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in nexus/db-queries/src/db/datastore/volume_repair.rs at volume_repair_insert_in_txn and read the callers that currently depend on its error message. Trace the error propagation through those callers and confirm that the volume-repair conflict and missing-volume cases remain distinguishable without matching message text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- database
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100