Skip to content

Commit e3cde1f

Browse files
authored
Leave one Instance as authoritative in sending state updates to Nexus. (#667)
For every Instance sled agent manages, it spawns a task to poll for state updates from propolis. After updating its in-memory state, it notifies Nexus to update the DB representation. In the Live Migration case, we're in a transitory state wherein there will be two distinct Instance objects (possibly across 2 different Sled Agents). We update Nexus here to only write the changes from the destination SA to the DB. Along with that, this pulls in the latest propolis side changes. We're still lacking actually transfering over all the necessary state but a lot more scaffolding is coming together.
1 parent 8d75a54 commit e3cde1f

File tree

20 files changed

+507
-83
lines changed

20 files changed

+507
-83
lines changed

Cargo.lock

Lines changed: 101 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/api/internal/nexus.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct InstanceRuntimeState {
3838
pub sled_uuid: Uuid,
3939
/// which propolis-server is running this Instance
4040
pub propolis_uuid: Uuid,
41+
/// the target propolis-server during a migration of this Instance
42+
pub dst_propolis_uuid: Option<Uuid>,
4143
/// address of propolis-server running this Instance
4244
pub propolis_addr: Option<SocketAddr>,
4345
/// migration id (if one in process)

common/src/api/internal/sled_agent.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ impl InstanceStateRequested {
9191
}
9292
}
9393

94+
/// Instance runtime state to update for a migration.
95+
#[derive(Copy, Clone, Debug, Deserialize, Serialize, JsonSchema)]
96+
pub struct InstanceRuntimeStateMigrateParams {
97+
pub migration_id: Uuid,
98+
pub dst_propolis_id: Uuid,
99+
}
100+
94101
/// Used to request an Instance state change from a sled agent
95102
///
96103
/// Right now, it's only the run state and migration id that can
@@ -99,5 +106,5 @@ impl InstanceStateRequested {
99106
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
100107
pub struct InstanceRuntimeStateRequested {
101108
pub run_state: InstanceStateRequested,
102-
pub migration_id: Option<Uuid>,
109+
pub migration_params: Option<InstanceRuntimeStateMigrateParams>,
103110
}

common/src/sql/dbinit.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ CREATE TABLE omicron.public.instance (
252252
*/
253253
active_server_id UUID,
254254
/* Identifies the underlying propolis-server backing the instance. */
255-
active_propolis_id UUID,
255+
active_propolis_id UUID NOT NULL,
256256
active_propolis_ip INET,
257257

258+
/* Identifies the target propolis-server during a migration of the instance. */
259+
target_propolis_id UUID,
260+
258261
/*
259262
* Identifies an ongoing migration for this instance.
260263
*/

nexus-client/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl From<omicron_common::api::internal::nexus::InstanceRuntimeState>
6868
run_state: s.run_state.into(),
6969
sled_uuid: s.sled_uuid,
7070
propolis_uuid: s.propolis_uuid,
71+
dst_propolis_uuid: s.dst_propolis_uuid,
7172
propolis_addr: s.propolis_addr.map(|addr| addr.to_string()),
7273
migration_uuid: s.migration_uuid,
7374
ncpus: s.ncpus.into(),
@@ -89,6 +90,7 @@ impl From<&omicron_common::api::internal::nexus::InstanceRuntimeState>
8990
run_state: s.run_state.into(),
9091
sled_uuid: s.sled_uuid,
9192
propolis_uuid: s.propolis_uuid,
93+
dst_propolis_uuid: s.dst_propolis_uuid,
9294
propolis_addr: s.propolis_addr.map(|addr| addr.to_string()),
9395
migration_uuid: s.migration_uuid,
9496
ncpus: s.ncpus.into(),

nexus/src/db/datastore.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,11 @@ impl DataStore {
11181118
.filter(dsl::time_deleted.is_null())
11191119
.filter(dsl::id.eq(*instance_id))
11201120
.filter(dsl::state_generation.lt(new_runtime.gen))
1121+
.filter(
1122+
dsl::migration_id
1123+
.is_null()
1124+
.or(dsl::target_propolis_id.eq(new_runtime.propolis_uuid)),
1125+
)
11211126
.set(new_runtime.clone())
11221127
.check_if_exists::<Instance>(*instance_id)
11231128
.execute_and_check(self.pool())

nexus/src/db/model.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ pub struct InstanceRuntimeState {
841841
pub sled_uuid: Uuid,
842842
#[column_name = "active_propolis_id"]
843843
pub propolis_uuid: Uuid,
844+
#[column_name = "target_propolis_id"]
845+
pub dst_propolis_uuid: Option<Uuid>,
844846
#[column_name = "active_propolis_ip"]
845847
pub propolis_ip: Option<ipnetwork::IpNetwork>,
846848
#[column_name = "migration_id"]
@@ -871,6 +873,7 @@ impl From<internal::nexus::InstanceRuntimeState> for InstanceRuntimeState {
871873
state: InstanceState::new(state.run_state),
872874
sled_uuid: state.sled_uuid,
873875
propolis_uuid: state.propolis_uuid,
876+
dst_propolis_uuid: state.dst_propolis_uuid,
874877
propolis_ip: state.propolis_addr.map(|addr| addr.ip().into()),
875878
migration_uuid: state.migration_uuid,
876879
ncpus: state.ncpus.into(),
@@ -889,6 +892,7 @@ impl Into<internal::nexus::InstanceRuntimeState> for InstanceRuntimeState {
889892
run_state: *self.state.state(),
890893
sled_uuid: self.sled_uuid,
891894
propolis_uuid: self.propolis_uuid,
895+
dst_propolis_uuid: self.dst_propolis_uuid,
892896
propolis_addr: self
893897
.propolis_ip
894898
.map(|ip| SocketAddr::new(ip.ip(), PROPOLIS_PORT)),

nexus/src/db/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ table! {
3939
state_generation -> Int8,
4040
active_server_id -> Uuid,
4141
active_propolis_id -> Uuid,
42+
target_propolis_id -> Nullable<Uuid>,
4243
active_propolis_ip -> Nullable<Inet>,
4344
migration_id -> Nullable<Uuid>,
4445
ncpus -> Int8,

0 commit comments

Comments
 (0)