Skip to content

Commit

Permalink
[π˜€π—½π—Ώ] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Apr 15, 2024
1 parent e849545 commit 924cf0d
Show file tree
Hide file tree
Showing 28 changed files with 142 additions and 77 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ progenitor::generate_api!(
NetworkInterfaceKind = omicron_common::api::internal::shared::NetworkInterfaceKind,
TypedUuidForCollectionKind = omicron_uuid_kinds::CollectionUuid,
TypedUuidForDownstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DownstairsKind>,
TypedUuidForOmicronZoneKind = omicron_uuid_kinds::OmicronZoneUuid,
TypedUuidForUpstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::UpstairsKind>,
TypedUuidForUpstairsRepairKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::UpstairsRepairKind>,
TypedUuidForUpstairsSessionKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::UpstairsSessionKind>,
Expand Down
23 changes: 14 additions & 9 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use diesel::TextExpressionMethods;
use gateway_client::types::SpType;
use ipnetwork::IpNetwork;
use nexus_config::PostgresConfigWithUrl;
use nexus_db_model::to_db_typed_uuid;
use nexus_db_model::Dataset;
use nexus_db_model::Disk;
use nexus_db_model::DnsGroup;
Expand Down Expand Up @@ -92,6 +93,7 @@ use omicron_common::api::external::Generation;
use omicron_common::api::external::InstanceState;
use omicron_common::api::external::MacAddr;
use omicron_uuid_kinds::CollectionUuid;
use omicron_uuid_kinds::OmicronZoneUuid;
use sled_agent_client::types::VolumeConstructionRequest;
use std::borrow::Cow;
use std::cmp::Ordering;
Expand Down Expand Up @@ -1144,7 +1146,7 @@ async fn cmd_db_disk_physical(
for did in dataset_ids.clone().into_iter() {
use db::schema::region::dsl as region_dsl;
let regions = region_dsl::region
.filter(region_dsl::dataset_id.eq(did))
.filter(region_dsl::dataset_id.eq(to_db_typed_uuid(did)))
.select(Region::as_select())
.load_async(&*conn)
.await
Expand Down Expand Up @@ -1229,7 +1231,10 @@ async fn cmd_db_disk_physical(
let limit = fetch_opts.fetch_limit;
use db::schema::region_snapshot::dsl as region_snapshot_dsl;
let region_snapshots = region_snapshot_dsl::region_snapshot
.filter(region_snapshot_dsl::dataset_id.eq_any(dataset_ids))
.filter(
region_snapshot_dsl::dataset_id
.eq_any(dataset_ids.into_iter().map(to_db_typed_uuid)),
)
.limit(i64::from(u32::from(limit)))
.select(RegionSnapshot::as_select())
.load_async(&*conn)
Expand Down Expand Up @@ -2332,7 +2337,7 @@ async fn cmd_db_validate_volume_references(

#[derive(Tabled)]
struct Row {
dataset_id: Uuid,
dataset_id: OmicronZoneUuid,
region_id: Uuid,
snapshot_id: Uuid,
error: String,
Expand Down Expand Up @@ -2394,7 +2399,7 @@ async fn cmd_db_validate_volume_references(

if matching_volumes != region_snapshot.volume_references as usize {
rows.push(Row {
dataset_id: region_snapshot.dataset_id,
dataset_id: region_snapshot.dataset_id.into(),
region_id: region_snapshot.region_id,
snapshot_id: region_snapshot.snapshot_id,
error: format!(
Expand All @@ -2412,7 +2417,7 @@ async fn cmd_db_validate_volume_references(

if matching_volumes == 0 && !region_snapshot.deleting {
rows.push(Row {
dataset_id: region_snapshot.dataset_id,
dataset_id: region_snapshot.dataset_id.into(),
region_id: region_snapshot.region_id,
snapshot_id: region_snapshot.snapshot_id,
error: String::from(
Expand Down Expand Up @@ -2470,7 +2475,7 @@ async fn cmd_db_validate_region_snapshots(

#[derive(Tabled)]
struct Row {
dataset_id: Uuid,
dataset_id: OmicronZoneUuid,
region_id: Uuid,
snapshot_id: Uuid,
dataset_addr: std::net::SocketAddrV6,
Expand Down Expand Up @@ -2549,7 +2554,7 @@ async fn cmd_db_validate_region_snapshots(
// This is ok - Nexus currently soft-deletes its
// resource records.
rows.push(Row {
dataset_id: region_snapshot.dataset_id,
dataset_id: region_snapshot.dataset_id.into(),
region_id: region_snapshot.region_id,
snapshot_id: region_snapshot.snapshot_id,
dataset_addr: dataset.address(),
Expand All @@ -2564,7 +2569,7 @@ async fn cmd_db_validate_region_snapshots(
// higher level Snapshot was not deleted!

rows.push(Row {
dataset_id: region_snapshot.dataset_id,
dataset_id: region_snapshot.dataset_id.into(),
region_id: region_snapshot.region_id,
snapshot_id: region_snapshot.snapshot_id,
dataset_addr: dataset.address(),
Expand Down Expand Up @@ -2593,7 +2598,7 @@ async fn cmd_db_validate_region_snapshots(
// the Agent, so it's a bug.

rows.push(Row {
dataset_id: region_snapshot.dataset_id,
dataset_id: region_snapshot.dataset_id.into(),
region_id: region_snapshot.region_id,
snapshot_id: region_snapshot.snapshot_id,
dataset_addr: dataset.address(),
Expand Down
4 changes: 3 additions & 1 deletion nexus/db-model/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::ipv6;
use crate::schema::{dataset, region};
use chrono::{DateTime, Utc};
use db_macros::Asset;
use omicron_uuid_kinds::OmicronZoneUuid;
use serde::{Deserialize, Serialize};
use std::net::{Ipv6Addr, SocketAddrV6};
use uuid::Uuid;
Expand All @@ -28,6 +29,7 @@ use uuid::Uuid;
PartialEq,
)]
#[diesel(table_name = dataset)]
#[asset(uuid_kind = OmicronZoneKind)]
pub struct Dataset {
#[diesel(embed)]
identity: DatasetIdentity,
Expand All @@ -45,7 +47,7 @@ pub struct Dataset {

impl Dataset {
pub fn new(
id: Uuid,
id: OmicronZoneUuid,
pool_id: Uuid,
addr: SocketAddrV6,
kind: DatasetKind,
Expand Down
5 changes: 3 additions & 2 deletions nexus/db-model/src/region_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use crate::schema::region_snapshot;
use crate::{schema::region_snapshot, typed_uuid::DbTypedUuid};
use omicron_uuid_kinds::OmicronZoneKind;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand All @@ -23,7 +24,7 @@ use uuid::Uuid;
#[diesel(table_name = region_snapshot)]
pub struct RegionSnapshot {
// unique identifier of this region snapshot
pub dataset_id: Uuid,
pub dataset_id: DbTypedUuid<OmicronZoneKind>,
pub region_id: Uuid,
pub snapshot_id: Uuid,

Expand Down
19 changes: 13 additions & 6 deletions nexus/db-queries/src/db/datastore/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ use crate::db::error::ErrorHandler;
use crate::db::identity::Asset;
use crate::db::model::Dataset;
use crate::db::model::Zpool;
use crate::db::pagination::paginated;
use crate::db::pagination::paginated_mapped;
use crate::db::pagination::Paginator;
use async_bb8_diesel::AsyncRunQueryDsl;
use chrono::Utc;
use diesel::prelude::*;
use diesel::upsert::excluded;
use nexus_db_model::to_db_typed_uuid;
use nexus_db_model::DatasetKind;
use omicron_common::api::external::CreateResult;
use omicron_common::api::external::DataPageParams;
Expand All @@ -30,6 +31,7 @@ use omicron_common::api::external::ListResultVec;
use omicron_common::api::external::LookupResult;
use omicron_common::api::external::LookupType;
use omicron_common::api::external::ResourceType;
use omicron_uuid_kinds::OmicronZoneUuid;
use uuid::Uuid;

impl DataStore {
Expand Down Expand Up @@ -131,13 +133,18 @@ impl DataStore {
&self,
opctx: &OpContext,
filter_kind: Option<DatasetKind>,
pagparams: &DataPageParams<'_, Uuid>,
pagparams: &DataPageParams<'_, OmicronZoneUuid>,
) -> ListResultVec<Dataset> {
opctx.authorize(authz::Action::ListChildren, &authz::FLEET).await?;
use db::schema::dataset::dsl;

let mut query = paginated(dsl::dataset, dsl::id, pagparams)
.filter(dsl::time_deleted.is_null());
let mut query = paginated_mapped(
dsl::dataset,
dsl::id,
pagparams,
to_db_typed_uuid,
)
.filter(dsl::time_deleted.is_null());

if let Some(kind) = filter_kind {
query = query.filter(dsl::kind.eq(kind));
Expand Down Expand Up @@ -238,7 +245,7 @@ mod test {
// Inserting a new dataset should succeed.
let dataset1 = datastore
.dataset_insert_if_not_exists(Dataset::new(
Uuid::new_v4(),
OmicronZoneUuid::new_v4(),
zpool_id,
"[::1]:0".parse().unwrap(),
DatasetKind::Crucible,
Expand Down Expand Up @@ -287,7 +294,7 @@ mod test {
// We can can also upsert a different dataset...
let dataset2 = datastore
.dataset_upsert(Dataset::new(
Uuid::new_v4(),
OmicronZoneUuid::new_v4(),
zpool_id,
"[::1]:0".parse().unwrap(),
DatasetKind::Cockroach,
Expand Down
22 changes: 12 additions & 10 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ mod test {
ByteCount, Error, IdentityMetadataCreateParams, LookupType, Name,
};
use omicron_test_utils::dev;
use omicron_uuid_kinds::CollectionUuid;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::SledUuid;
use omicron_uuid_kinds::{CollectionUuid, OmicronZoneUuid};
use std::collections::HashMap;
use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddrV6};
Expand Down Expand Up @@ -751,12 +751,12 @@ mod test {
ineligible: SledToDatasetMap,

// A map from eligible dataset IDs to their corresponding sled IDs.
eligible_dataset_ids: HashMap<Uuid, SledUuid>,
ineligible_dataset_ids: HashMap<Uuid, IneligibleSledKind>,
eligible_dataset_ids: HashMap<OmicronZoneUuid, SledUuid>,
ineligible_dataset_ids: HashMap<OmicronZoneUuid, IneligibleSledKind>,
}

// Map of sled IDs to dataset IDs.
type SledToDatasetMap = HashMap<SledUuid, Vec<Uuid>>;
type SledToDatasetMap = HashMap<SledUuid, Vec<OmicronZoneUuid>>;

impl TestDatasets {
async fn create(
Expand Down Expand Up @@ -892,7 +892,7 @@ mod test {
let zpool_iter: Vec<Zpool> =
(0..3).map(|_| zpool).collect();
stream::iter(zpool_iter).then(|zpool| {
let dataset_id = Uuid::new_v4();
let dataset_id = OmicronZoneUuid::new_v4();
let dataset = Dataset::new(
dataset_id,
zpool.pool_id,
Expand Down Expand Up @@ -982,8 +982,10 @@ mod test {
// This is a little goofy, but it catches a bug that has
// happened before. The returned columns share names (like
// "id"), so we need to process them in-order.
assert!(regions.get(&dataset.id()).is_none());
assert!(disk_datasets.get(&region.id()).is_none());
assert!(regions.get(dataset.id().as_untyped_uuid()).is_none());
assert!(disk_datasets
.get(&OmicronZoneUuid::from_untyped_uuid(region.id()))
.is_none());

// Dataset must not be eligible for provisioning.
if let Some(kind) =
Expand Down Expand Up @@ -1263,7 +1265,7 @@ mod test {
// 1 dataset per zpool
stream::iter(zpool_ids.clone())
.then(|zpool_id| {
let id = Uuid::new_v4();
let id = OmicronZoneUuid::new_v4();
let dataset = Dataset::new(
id,
zpool_id,
Expand Down Expand Up @@ -1362,7 +1364,7 @@ mod test {
// 1 dataset per zpool
stream::iter(zpool_ids)
.then(|zpool_id| {
let id = Uuid::new_v4();
let id = OmicronZoneUuid::new_v4();
let dataset = Dataset::new(
id,
zpool_id,
Expand Down Expand Up @@ -1438,7 +1440,7 @@ mod test {
.await;
let bogus_addr = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 8080, 0, 0);
let dataset = Dataset::new(
Uuid::new_v4(),
OmicronZoneUuid::new_v4(),
zpool_id,
bogus_addr,
DatasetKind::Crucible,
Expand Down
6 changes: 4 additions & 2 deletions nexus/db-queries/src/db/datastore/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ use crate::transaction_retry::OptionalError;
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::prelude::*;
use nexus_config::RegionAllocationStrategy;
use nexus_db_model::to_db_typed_uuid;
use nexus_types::external_api::params;
use omicron_common::api::external;
use omicron_common::api::external::DeleteResult;
use omicron_common::api::external::Error;
use omicron_uuid_kinds::OmicronZoneUuid;
use slog::Logger;
use uuid::Uuid;

Expand Down Expand Up @@ -294,13 +296,13 @@ impl DataStore {
/// Return the total occupied size for a dataset
pub async fn regions_total_occupied_size(
&self,
dataset_id: Uuid,
dataset_id: OmicronZoneUuid,
) -> Result<u64, Error> {
use db::schema::region::dsl as region_dsl;

let total_occupied_size: Option<diesel::pg::data_types::PgNumeric> =
region_dsl::region
.filter(region_dsl::dataset_id.eq(dataset_id))
.filter(region_dsl::dataset_id.eq(to_db_typed_uuid(dataset_id)))
.select(diesel::dsl::sum(
region_dsl::block_size
* region_dsl::blocks_per_extent
Expand Down
10 changes: 6 additions & 4 deletions nexus/db-queries/src/db/datastore/region_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use crate::db::model::RegionSnapshot;
use async_bb8_diesel::AsyncRunQueryDsl;
use diesel::prelude::*;
use diesel::OptionalExtension;
use nexus_db_model::to_db_typed_uuid;
use omicron_common::api::external::CreateResult;
use omicron_common::api::external::DeleteResult;
use omicron_common::api::external::LookupResult;
use omicron_uuid_kinds::OmicronZoneUuid;
use uuid::Uuid;

impl DataStore {
Expand All @@ -35,14 +37,14 @@ impl DataStore {

pub async fn region_snapshot_get(
&self,
dataset_id: Uuid,
dataset_id: OmicronZoneUuid,
region_id: Uuid,
snapshot_id: Uuid,
) -> LookupResult<Option<RegionSnapshot>> {
use db::schema::region_snapshot::dsl;

dsl::region_snapshot
.filter(dsl::dataset_id.eq(dataset_id))
.filter(dsl::dataset_id.eq(to_db_typed_uuid(dataset_id)))
.filter(dsl::region_id.eq(region_id))
.filter(dsl::snapshot_id.eq(snapshot_id))
.select(RegionSnapshot::as_select())
Expand All @@ -56,14 +58,14 @@ impl DataStore {

pub async fn region_snapshot_remove(
&self,
dataset_id: Uuid,
dataset_id: OmicronZoneUuid,
region_id: Uuid,
snapshot_id: Uuid,
) -> DeleteResult {
use db::schema::region_snapshot::dsl;

diesel::delete(dsl::region_snapshot)
.filter(dsl::dataset_id.eq(dataset_id))
.filter(dsl::dataset_id.eq(to_db_typed_uuid(dataset_id)))
.filter(dsl::region_id.eq(region_id))
.filter(dsl::snapshot_id.eq(snapshot_id))
.execute_async(&*self.pool_connection_unauthorized().await?)
Expand Down
Loading

0 comments on commit 924cf0d

Please sign in to comment.