Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7865,25 +7865,24 @@ async fn cmd_db_vmm_info(
include_sled_id: bool,
) {
use db::model::ByteCount;
let db::model::SledResourceVmm {
id: _,
sled_id,
resources:
db::model::Resources {
hardware_threads,
rss_ram: ByteCount(rss),
reservoir_ram: ByteCount(reservoir),
},
instance_id: _,
} = resource;

let sled_id = &resource.sled_id;
let db::model::Resources {
hardware_threads,
rss_ram: ByteCount(rss),
reservoir_ram: ByteCount(reservoir),
} = &resource.resources;

const SLED_ID: &'static str = "sled ID";
const THREADS: &'static str = "hardware threads";
const RSS: &'static str = "RSS RAM";
const RESERVOIR: &'static str = "reservoir RAM";
const WIDTH: usize = const_max_len(&[SLED_ID, THREADS, RSS, RESERVOIR]);

if include_sled_id {
println!(" {SLED_ID:>WIDTH$}: {sled_id}");
}

println!(" {THREADS:>WIDTH$}: {hardware_threads}");
println!(" {RSS:>WIDTH$}: {rss}");
println!(" {RESERVOIR:>WIDTH$}: {reservoir}");
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(261, 0, 0);
pub const SCHEMA_VERSION: Version = Version::new(262, 0, 0);

/// List of all past database schema versions, in *reverse* order
///
Expand All @@ -28,6 +28,7 @@ pub 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(262, "sled-resource-vmm-instance-state-generation"),
KnownVersion::new(261, "remove-add-zones-with-mupdate-override"),
KnownVersion::new(260, "ereport-trim-serial-trailing-nulls"),
KnownVersion::new(259, "vmm-failure-reason"),
Expand Down
26 changes: 26 additions & 0 deletions nexus/db-model/src/sled_resource_vmm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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::Generation;
use crate::typed_uuid::DbTypedUuid;
use crate::{ByteCount, SqlU32};
use nexus_db_schema::schema::sled_resource_vmm;
Expand Down Expand Up @@ -34,6 +35,14 @@ impl Resources {
}
}

#[derive(Clone, Debug)]
pub enum SledResourceVmmInstanceStateGeneration {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

super annoying obnoxious nitpick: man this is a long name...I suppose including the SledResourceVmm prefix is necessary because this type is currently re-exported by a pub use sled_resource_vmm::*; so we can't just expect callers to refer to it as sled_resource_vmm::InstanceStateGeneration. which...I dunno if it's worth trying to fix that. I guess this is fine, it just makes me feel a certain type of way!

/// Row was created prior to Nexus recording this
Unspecified,

Specified(Generation),
}

/// Describes sled resource usage by a VMM
#[derive(Clone, Selectable, Queryable, Insertable, Debug)]
#[diesel(table_name = sled_resource_vmm)]
Expand All @@ -45,6 +54,9 @@ pub struct SledResourceVmm {
pub resources: Resources,

pub instance_id: Option<DbInstanceUuid>,

/// The instance's state_generation at the moment of reservation
instance_state_generation: Option<Generation>,
}

impl SledResourceVmm {
Expand All @@ -53,12 +65,14 @@ impl SledResourceVmm {
instance_id: InstanceUuid,
sled_id: SledUuid,
resources: Resources,
instance_state_generation: Generation,
) -> Self {
Self {
id: id.into(),
instance_id: Some(instance_id.into()),
sled_id: sled_id.into(),
resources,
instance_state_generation: Some(instance_state_generation),
}
}

Expand All @@ -73,4 +87,16 @@ impl SledResourceVmm {
pub fn instance_id(&self) -> Option<InstanceUuid> {
self.instance_id.map(|x| x.into())
}

pub fn instance_state_generation(
&self,
) -> SledResourceVmmInstanceStateGeneration {
match &self.instance_state_generation {
Some(generation) => {
SledResourceVmmInstanceStateGeneration::Specified(*generation)
}

None => SledResourceVmmInstanceStateGeneration::Unspecified,
}
}
}
1 change: 1 addition & 0 deletions nexus/db-queries/benches/harness/db_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub async fn create_reservation(
.sled_reservation_create(
&opctx,
instance_id,
nexus_db_model::Generation::new(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit, may not be important: I wonder if rather than always inserting the reservation at generation 1, we ought to change this function to take an &Instance rather than an InstanceUuid, and use the generation from the instance record. Clearly, there aren't currently any tests which are calling this helper multiple times for the same InstanceUuid, or else they would have already broken, but it seems like it could be potentially annoying if someone were to start adding a new test that does so and was surprised to discover this doesn't actually use the generation from the instance record.

on the other hand, maybe updating all the test code that uses this to pass an &Instance is going to be too painful.

vmm_id,
small_resource_request(),
SledReservationConstraintBuilder::new().build(),
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/affinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,7 @@ mod tests {
ByteCount::from_kibibytes_u32(1).into(),
ByteCount::from_kibibytes_u32(1).into(),
),
nexus_db_model::Generation::new(),
))
.execute_async(
&*datastore.pool_connection_for_tests().await.unwrap(),
Expand Down
Loading
Loading