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

Use a typed UUID for Dataset #7048

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jmpesp
Copy link
Contributor

@jmpesp jmpesp commented Nov 12, 2024

No description provided.

Copy link
Contributor

@jgallagher jgallagher left a comment

Choose a reason for hiding this comment

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

Thanks for this; LGTM except for that (pre-existing) confusion of zone ID / dataset ID. We probably want to fix that, I think?

@@ -51,6 +51,7 @@ progenitor::generate_api!(
TypedUuidForDemoSagaKind = omicron_uuid_kinds::DemoSagaUuid,
TypedUuidForDownstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DownstairsKind>,
TypedUuidForPropolisKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::PropolisKind>,
TypedUuidForDatasetKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DatasetKind>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Absurdly tiny nit - it looks like this list was alphabetized; maybe move this up a few lines to keep that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, done in 994cc4c

@@ -45,7 +47,7 @@ pub struct Dataset {
ip: Option<ipv6::Ipv6Addr>,
port: Option<SqlU16>,

pub kind: DatasetKind,
pub kind: DbDatasetKind,
Copy link
Contributor

Choose a reason for hiding this comment

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

This name collision is pretty unfortunate. Since we only use the UUID DatasetKind once in this file AFAICT, can we import that one as a different name instead? #[asset(uuid_kind = DatasetUuidKind)] or something, if the proc macro allows renamed imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, done in 0d24cc6

@@ -27,7 +28,7 @@ use chrono::Utc;
use diesel::prelude::*;
use diesel::upsert::excluded;
use futures::FutureExt;
use nexus_db_model::DatasetKind;
use nexus_db_model::DatasetKind as DbDatasetKind;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this rename necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no! 61b0be5

p.found_batch(&batch, &|d: &nexus_db_model::Dataset| d.id());
paginator = p
.found_batch(&batch, &|d: &nexus_db_model::Dataset| {
*d.id().as_untyped_uuid()
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC there's also

Suggested change
*d.id().as_untyped_uuid()
d.id().into_untyped_uuid()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -1043,7 +1044,8 @@ mod test {

for (dataset, region) in dataset_and_regions {
// Must be 3 unique datasets
assert!(disk_datasets.insert(dataset.id()));
let dataset_id = dataset.id();
assert!(disk_datasets.insert(*dataset_id.as_untyped_uuid()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert!(disk_datasets.insert(*dataset_id.as_untyped_uuid()));
assert!(disk_datasets.insert(dataset_id.into_untyped_uuid()));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -254,8 +255,10 @@ impl RackInitRequestBuilder {
let zone = self
.internal_dns_config
.host_zone(
// TODO-cleanup use TypedUuid everywhere
OmicronZoneUuid::from_untyped_uuid(dataset_id),
// XXX why is zone id being created from dataset id?
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem right; maybe related to #7000 (comment) (cc @smklein)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this dates back to #3364 , and there isn't really a strong justification for it, other than it's deterministic for tests. We probably got away with this for a while because there's only one caller (adding CockroachDB)

Given that we're already supplying a service_name here, it probably makes sense to force the caller to also supply a OmicronZoneUuid. I'm 99% sure the (one) caller could just use OmicronZoneUuid::new_v4() and this would work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

3 participants