@@ -971,7 +971,14 @@ impl super::Nexus {
971
971
}
972
972
}
973
973
974
- /// TODO describe how this relates to [Self::instance_request_state] (above)
974
+ /// For calls to [sled_agent_client::Client::instance_put_state] (such as
975
+ /// made by [Self::instance_request_state]) that involve a long-running
976
+ /// task such as creating a propolis zone (i.e. during instance creation
977
+ /// or migration target provisioning), sled-agent may send the resulting
978
+ /// instance state to Nexus via the internal API instead of blocking
979
+ /// during the request handler and risking an HTTP request timeout. This
980
+ /// function writes the asynchronously-returned updated instance state
981
+ /// to the database.
975
982
pub ( crate ) async fn instance_handle_creation_result (
976
983
& self ,
977
984
opctx : & OpContext ,
@@ -983,30 +990,20 @@ impl super::Nexus {
983
990
. lookup_for ( authz:: Action :: Modify )
984
991
. await ?;
985
992
986
- let state = self
987
- . db_datastore
988
- . instance_fetch_with_vmm ( opctx, & authz_instance)
989
- . await ?;
990
-
991
- // TODO: add param for sled-agent to show its 'previous' and compare with this
992
- // to validate consistency between nexus and sled-agent
993
- let prev_instance_runtime = & state. instance ( ) . runtime_state ;
994
-
995
993
match result {
996
994
Ok ( new_state) => self
997
- . db_datastore
998
- . instance_and_vmm_update_runtime (
999
- instance_id,
1000
- & new_state. instance_state . into ( ) ,
1001
- & new_state. propolis_id ,
1002
- & new_state. vmm_state . into ( ) ,
1003
- )
995
+ . write_returned_instance_state ( instance_id, Some ( new_state) )
1004
996
. await
1005
997
. map ( |_| ( ) ) ,
1006
998
Err ( error) => {
999
+ let state = self
1000
+ . db_datastore
1001
+ . instance_fetch_with_vmm ( opctx, & authz_instance)
1002
+ . await ?;
1003
+
1007
1004
self . mark_instance_failed (
1008
1005
instance_id,
1009
- prev_instance_runtime ,
1006
+ & state . instance ( ) . runtime_state ,
1010
1007
error,
1011
1008
)
1012
1009
. await
0 commit comments