From 9f4156a1e6ce8f3a88ce29e7876879efcd92cc67 Mon Sep 17 00:00:00 2001 From: Greg Colombo Date: Mon, 26 Aug 2024 19:51:09 +0000 Subject: [PATCH] get instance id from vmm find-and-update --- nexus/db-queries/src/db/datastore/vmm.rs | 20 +++++++++++++++++--- nexus/src/app/instance.rs | 5 ++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/nexus/db-queries/src/db/datastore/vmm.rs b/nexus/db-queries/src/db/datastore/vmm.rs index f909b7e9d3..089a2914be 100644 --- a/nexus/db-queries/src/db/datastore/vmm.rs +++ b/nexus/db-queries/src/db/datastore/vmm.rs @@ -39,8 +39,13 @@ use uuid::Uuid; /// The result of an [`DataStore::vmm_and_migration_update_runtime`] call, /// indicating which records were updated. -#[derive(Copy, Clone, Debug)] +#[derive(Clone, Debug)] pub struct VmmStateUpdateResult { + /// The VMM record that the update query found and possibly updated. + /// + /// NOTE: This is the record prior to the update! + pub found_vmm: Vmm, + /// `true` if the VMM record was updated, `false` otherwise. pub vmm_updated: bool, @@ -228,13 +233,21 @@ impl DataStore { .transaction(&conn, |conn| { let err = err.clone(); async move { - let vmm_updated = self + let vmm_update_result = self .vmm_update_runtime_on_connection( &conn, &vmm_id, new_runtime, ) - .await.map(|r| match r.status { UpdateStatus::Updated => true, UpdateStatus::NotUpdatedButExists => false })?; + .await?; + + + let found_vmm = vmm_update_result.found; + let vmm_updated = match vmm_update_result.status { + UpdateStatus::Updated => true, + UpdateStatus::NotUpdatedButExists => false + }; + let migration_out_updated = match migration_out { Some(migration) => { let r = self.migration_update_source_on_connection( @@ -282,6 +295,7 @@ impl DataStore { None => false, }; Ok(VmmStateUpdateResult { + found_vmm, vmm_updated, migration_in_updated, migration_out_updated, diff --git a/nexus/src/app/instance.rs b/nexus/src/app/instance.rs index bcc242db77..0f79ace564 100644 --- a/nexus/src/app/instance.rs +++ b/nexus/src/app/instance.rs @@ -1881,9 +1881,8 @@ pub(crate) async fn process_vmm_update( new_runtime_state, &result, ) { - let instance_id = InstanceUuid::from_untyped_uuid( - datastore.vmm_fetch(&opctx, &propolis_id).await?.instance_id, - ); + let instance_id = + InstanceUuid::from_untyped_uuid(result.found_vmm.instance_id); let (.., authz_instance) = LookupPath::new(&opctx, datastore) .instance_id(instance_id.into_untyped_uuid())