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

(9/5) [nexus] Allow anti-affinity members to be affinity groups #7572

Draft
wants to merge 8 commits into
base: vmm-reduce-contention
Choose a base branch
from
5 changes: 5 additions & 0 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use dropshot::HttpError;
pub use dropshot::PaginationOrder;
pub use error::*;
use futures::stream::BoxStream;
use omicron_uuid_kinds::AffinityGroupUuid;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::InstanceUuid;
use oxnet::IpNet;
Expand Down Expand Up @@ -1339,13 +1340,17 @@ impl SimpleIdentity for AffinityGroupMember {
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq)]
#[serde(tag = "type", content = "value", rename_all = "snake_case")]
pub enum AntiAffinityGroupMember {
/// An affinity group belonging to this group, identified by UUID.
AffinityGroup(AffinityGroupUuid),

/// An instance belonging to this group, identified by UUID.
Instance(InstanceUuid),
}

impl SimpleIdentity for AntiAffinityGroupMember {
fn id(&self) -> Uuid {
match self {
AntiAffinityGroupMember::AffinityGroup(id) => *id.as_untyped_uuid(),
AntiAffinityGroupMember::Instance(id) => *id.as_untyped_uuid(),
}
}
Expand Down
28 changes: 28 additions & 0 deletions nexus/db-model/src/affinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::Name;
use crate::schema::affinity_group;
use crate::schema::affinity_group_instance_membership;
use crate::schema::anti_affinity_group;
use crate::schema::anti_affinity_group_affinity_membership;
use crate::schema::anti_affinity_group_instance_membership;
use crate::typed_uuid::DbTypedUuid;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -257,3 +258,30 @@ impl From<AntiAffinityGroupInstanceMembership>
Self::Instance(member.instance_id.into())
}
}

#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = anti_affinity_group_affinity_membership)]
pub struct AntiAffinityGroupAffinityMembership {
pub anti_affinity_group_id: DbTypedUuid<AntiAffinityGroupKind>,
pub affinity_group_id: DbTypedUuid<AffinityGroupKind>,
}

impl AntiAffinityGroupAffinityMembership {
pub fn new(
anti_affinity_group_id: AntiAffinityGroupUuid,
affinity_group_id: AffinityGroupUuid,
) -> Self {
Self {
anti_affinity_group_id: anti_affinity_group_id.into(),
affinity_group_id: affinity_group_id.into(),
}
}
}

impl From<AntiAffinityGroupAffinityMembership>
for external::AntiAffinityGroupMember
{
fn from(member: AntiAffinityGroupAffinityMembership) -> Self {
Self::AffinityGroup(member.affinity_group_id.into())
}
}
8 changes: 8 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ table! {
}
}

table! {
anti_affinity_group_affinity_membership (anti_affinity_group_id, affinity_group_id) {
anti_affinity_group_id -> Uuid,
affinity_group_id -> Uuid,
}
}

table! {
metric_producer (id) {
id -> Uuid,
Expand Down Expand Up @@ -2074,6 +2081,7 @@ allow_tables_to_appear_in_same_query!(hw_baseboard_id, inv_sled_agent,);

allow_tables_to_appear_in_same_query!(
anti_affinity_group,
anti_affinity_group_affinity_membership,
anti_affinity_group_instance_membership,
affinity_group,
affinity_group_instance_membership,
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
///
/// This must be updated when you change the database schema. Refer to
/// schema/crdb/README.adoc in the root of this repository for details.
pub const SCHEMA_VERSION: Version = Version::new(128, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(129, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
// | leaving the first copy as an example for the next person.
// v
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
KnownVersion::new(129, "anti-affinity-group-affinity-member"),
KnownVersion::new(128, "sled-resource-for-vmm"),
KnownVersion::new(127, "bp-disk-disposition-expunged-cleanup"),
KnownVersion::new(126, "affinity"),
Expand Down
Loading
Loading