Skip to content

Commit

Permalink
Setup the VMM reservoir in a background task (#5124)
Browse files Browse the repository at this point in the history
Fixes the most immediate problem of #5121
  • Loading branch information
andrewjstone authored Mar 7, 2024
1 parent 19ad111 commit 87c9b13
Show file tree
Hide file tree
Showing 28 changed files with 1,525 additions and 428 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.

5 changes: 5 additions & 0 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ progenitor::generate_api!(
MacAddr = omicron_common::api::external::MacAddr,
Name = omicron_common::api::external::Name,
NewPasswordHash = omicron_passwords::NewPasswordHash,
},
patch = {
SledAgentInfo = { derives = [PartialEq, Eq] },
ByteCount = { derives = [PartialEq, Eq] },
Baseboard = { derives = [PartialEq, Eq] }
}
);

Expand Down
3 changes: 2 additions & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use omicron_common::api::external::SemverVersion;
///
/// This should be updated whenever the schema is changed. For more details,
/// refer to: schema/crdb/README.adoc
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(38, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(39, 0, 0);

table! {
disk (id) {
Expand Down Expand Up @@ -827,6 +827,7 @@ table! {
last_used_address -> Inet,
sled_policy -> crate::sled_policy::SledPolicyEnum,
sled_state -> crate::SledStateEnum,
sled_agent_gen -> Int8,
}
}

Expand Down
49 changes: 47 additions & 2 deletions nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ use super::{ByteCount, Generation, SledState, SqlU16, SqlU32};
use crate::collection::DatastoreCollectionConfig;
use crate::ipv6;
use crate::schema::{physical_disk, service, sled, zpool};
use crate::sled::shared::Baseboard;
use crate::sled_policy::DbSledPolicy;
use chrono::{DateTime, Utc};
use db_macros::Asset;
use nexus_types::{external_api::shared, external_api::views, identity::Asset};
use nexus_types::{
external_api::{shared, views},
identity::Asset,
internal_api::params,
};
use std::net::Ipv6Addr;
use std::net::SocketAddrV6;
use uuid::Uuid;
Expand Down Expand Up @@ -41,7 +46,7 @@ pub struct Sled {
#[diesel(embed)]
identity: SledIdentity,
time_deleted: Option<DateTime<Utc>>,
rcgen: Generation,
pub rcgen: Generation,

pub rack_id: Uuid,

Expand All @@ -66,6 +71,12 @@ pub struct Sled {

#[diesel(column_name = sled_state)]
state: SledState,

/// A generation number owned and incremented by sled-agent
///
/// This is specifically distinct from `rcgen`, which is incremented by
/// child resources as part of `DatastoreCollectionConfig`.
pub sled_agent_gen: Generation,
}

impl Sled {
Expand Down Expand Up @@ -119,6 +130,34 @@ impl From<Sled> for views::Sled {
}
}

impl From<Sled> for params::SledAgentInfo {
fn from(sled: Sled) -> Self {
let role = if sled.is_scrimlet {
params::SledRole::Scrimlet
} else {
params::SledRole::Gimlet
};
let decommissioned = match sled.state {
SledState::Active => false,
SledState::Decommissioned => true,
};
Self {
sa_address: sled.address(),
role,
baseboard: Baseboard {
serial: sled.serial_number.clone(),
part: sled.part_number.clone(),
revision: sled.revision,
},
usable_hardware_threads: sled.usable_hardware_threads.into(),
usable_physical_ram: sled.usable_physical_ram.into(),
reservoir_size: sled.reservoir_size.into(),
generation: sled.sled_agent_gen.into(),
decommissioned,
}
}
}

impl DatastoreCollectionConfig<super::PhysicalDisk> for Sled {
type CollectionId = Uuid;
type GenerationNumberColumn = sled::dsl::rcgen;
Expand Down Expand Up @@ -161,6 +200,9 @@ pub struct SledUpdate {
// ServiceAddress (Sled Agent).
pub ip: ipv6::Ipv6Addr,
pub port: SqlU16,

// Generation number - owned and incremented by sled-agent.
pub sled_agent_gen: Generation,
}

impl SledUpdate {
Expand All @@ -170,6 +212,7 @@ impl SledUpdate {
baseboard: SledBaseboard,
hardware: SledSystemHardware,
rack_id: Uuid,
sled_agent_gen: Generation,
) -> Self {
Self {
id,
Expand All @@ -185,6 +228,7 @@ impl SledUpdate {
reservoir_size: hardware.reservoir_size,
ip: addr.ip().into(),
port: addr.port().into(),
sled_agent_gen,
}
}

Expand Down Expand Up @@ -220,6 +264,7 @@ impl SledUpdate {
ip: self.ip,
port: self.port,
last_used_address,
sled_agent_gen: self.sled_agent_gen,
}
}

Expand Down
8 changes: 3 additions & 5 deletions nexus/db-queries/src/db/datastore/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ impl DataStore {
mod test {
use super::*;
use crate::db::datastore::test_utils::datastore_test;
use nexus_db_model::Generation;
use nexus_db_model::SledBaseboard;
use nexus_db_model::SledSystemHardware;
use nexus_db_model::SledUpdate;
Expand Down Expand Up @@ -222,12 +223,9 @@ mod test {
reservoir_size: (16 << 30).try_into().unwrap(),
},
Uuid::new_v4(),
Generation::new(),
);
datastore
.sled_upsert(sled)
.await
.expect("failed to upsert sled")
.unwrap();
datastore.sled_upsert(sled).await.expect("failed to upsert sled");

// Create a fake zpool that backs our fake datasets.
let zpool_id = Uuid::new_v4();
Expand Down
11 changes: 7 additions & 4 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ pub use instance::InstanceAndActiveVmm;
pub use inventory::DataStoreInventoryTest;
pub use rack::RackInit;
pub use silo::Discoverability;
pub use sled::SledUpsertOutput;
pub use switch_port::SwitchPortSettingsCombinedResult;
pub use virtual_provisioning_collection::StorageType;
pub use volume::read_only_resources_associated_with_volume;
Expand Down Expand Up @@ -393,6 +392,7 @@ mod test {
use futures::stream;
use futures::StreamExt;
use nexus_config::RegionAllocationStrategy;
use nexus_db_model::Generation;
use nexus_db_model::IpAttachState;
use nexus_test_utils::db::test_setup_database;
use nexus_types::external_api::params;
Expand Down Expand Up @@ -619,8 +619,9 @@ mod test {
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Generation::new(),
);
datastore.sled_upsert(sled_update).await.unwrap().unwrap();
datastore.sled_upsert(sled_update).await.unwrap();
sled_id
}

Expand Down Expand Up @@ -1338,8 +1339,9 @@ mod test {
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Generation::new(),
);
datastore.sled_upsert(sled1).await.unwrap().unwrap();
datastore.sled_upsert(sled1).await.unwrap();

let addr2 = "[fd00:1df::1]:12345".parse().unwrap();
let sled2_id = "66285c18-0c79-43e0-e54f-95271f271314".parse().unwrap();
Expand All @@ -1349,8 +1351,9 @@ mod test {
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Generation::new(),
);
datastore.sled_upsert(sled2).await.unwrap().unwrap();
datastore.sled_upsert(sled2).await.unwrap();

let ip = datastore.next_ipv6_address(&opctx, sled1_id).await.unwrap();
let expected_ip = Ipv6Addr::new(0xfd00, 0x1de, 0, 0, 0, 0, 1, 0);
Expand Down
3 changes: 2 additions & 1 deletion nexus/db-queries/src/db/datastore/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod test {
use crate::db::datastore::test_utils::datastore_test;
use crate::db::model::{PhysicalDiskKind, Sled, SledUpdate};
use dropshot::PaginationOrder;
use nexus_db_model::Generation;
use nexus_test_utils::db::test_setup_database;
use nexus_types::identity::Asset;
use omicron_test_utils::dev;
Expand All @@ -159,11 +160,11 @@ mod test {
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id,
Generation::new(),
);
db.sled_upsert(sled_update)
.await
.expect("Could not upsert sled during test prep")
.unwrap()
}

fn list_disk_params() -> DataPageParams<'static, Uuid> {
Expand Down
4 changes: 2 additions & 2 deletions nexus/db-queries/src/db/datastore/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ mod test {
use async_bb8_diesel::AsyncSimpleConnection;
use internal_params::DnsRecord;
use nexus_config::NUM_INITIAL_RESERVED_IP_ADDRESSES;
use nexus_db_model::{DnsGroup, InitialDnsGroup, SledUpdate};
use nexus_db_model::{DnsGroup, Generation, InitialDnsGroup, SledUpdate};
use nexus_test_utils::db::test_setup_database;
use nexus_types::external_api::shared::SiloIdentityMode;
use nexus_types::identity::Asset;
Expand Down Expand Up @@ -1065,11 +1065,11 @@ mod test {
sled_baseboard_for_test(),
sled_system_hardware_for_test(),
rack_id(),
Generation::new(),
);
db.sled_upsert(sled_update)
.await
.expect("Could not upsert sled during test prep")
.unwrap()
}

// Hacky macro helper to:
Expand Down
Loading

0 comments on commit 87c9b13

Please sign in to comment.