-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
migration
table and explicit migration tracking in sled-agent (#…
…5859) As part of ongoing work on improving instance lifecycle management (see #5749) , we intend to remove the `InstanceRuntimeState` tracking from `sled-agent`, and make Nexus the sole owner of `instance` records in CRDB, with a new `instance-update` saga taking over the responsibility of managing the instance's state transitions. In order to properly manage the instance state machine, Nexus will need information about the status of active migrations that are currently only available to sled-agents. For example, if an instance is migrating, and a sled agent reports that the source VMM is `Destroyed`, Nexus doesn't presently have the capability to determine whether the source VMM was destroyed because the migration completed successfully, or that the source shut down prior to starting the migration, resulting in a failure. In order for Nexus to correctly manage state updates during live migration, we introduce a new `migration` table to the schema for tracking the state of ongoing migrations. The `instance-migrate` saga creates a `migration` record when beginning a migration. The Nexus and sled-agent APIs are extended to include migration state updates from sled-agents to Nexus. In *this* branch, the `migration` table is (basically) write-only; Nexus doesn't really read from it, and just stuffs updates into it. In the future, however, this will be used by the `instance-update` saga. It occurred to me that, in addition to using the migration table for instance updates, it might also be useful to add an OMDB command to look up the status of a migration using this table. However, I decided that made more sense as a follow-up change, as I'd like to get back to integrating this into #5749. Fixes #2948
- Loading branch information
Showing
24 changed files
with
1,389 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// 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 super::Generation; | ||
use crate::schema::migration; | ||
use crate::MigrationState; | ||
use chrono::DateTime; | ||
use chrono::Utc; | ||
use omicron_common::api::internal::nexus; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use uuid::Uuid; | ||
|
||
/// The state of a migration as understood by Nexus. | ||
#[derive( | ||
Clone, Debug, Queryable, Insertable, Selectable, Serialize, Deserialize, | ||
)] | ||
#[diesel(table_name = migration)] | ||
pub struct Migration { | ||
/// The migration's UUID. | ||
/// | ||
/// This is the primary key of the migration table and is referenced by the | ||
/// `instance` table's `migration_id` field. | ||
pub id: Uuid, | ||
|
||
/// The time at which this migration record was created. | ||
pub time_created: DateTime<Utc>, | ||
|
||
/// The time at which this migration record was deleted, | ||
pub time_deleted: Option<DateTime<Utc>>, | ||
|
||
/// The state of the migration source VMM. | ||
pub source_state: MigrationState, | ||
|
||
/// The ID of the migration source VMM. | ||
pub source_propolis_id: Uuid, | ||
|
||
/// The generation number for the source state. | ||
pub source_gen: Generation, | ||
|
||
/// The time the source VMM state was most recently updated. | ||
pub time_source_updated: Option<DateTime<Utc>>, | ||
|
||
/// The state of the migration target VMM. | ||
pub target_state: MigrationState, | ||
|
||
/// The ID of the migration target VMM. | ||
pub target_propolis_id: Uuid, | ||
|
||
/// The generation number for the target state. | ||
pub target_gen: Generation, | ||
|
||
/// The time the target VMM state was most recently updated. | ||
pub time_target_updated: Option<DateTime<Utc>>, | ||
} | ||
|
||
impl Migration { | ||
pub fn new( | ||
migration_id: Uuid, | ||
source_propolis_id: Uuid, | ||
target_propolis_id: Uuid, | ||
) -> Self { | ||
Self { | ||
id: migration_id, | ||
time_created: Utc::now(), | ||
time_deleted: None, | ||
source_state: nexus::MigrationState::Pending.into(), | ||
source_propolis_id, | ||
source_gen: Generation::new(), | ||
time_source_updated: None, | ||
target_state: nexus::MigrationState::Pending.into(), | ||
target_propolis_id, | ||
target_gen: Generation::new(), | ||
time_target_updated: None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// 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/. | ||
|
||
//! Database representation of a migration's state as understood by Nexus. | ||
|
||
use super::impl_enum_wrapper; | ||
use omicron_common::api::internal::nexus; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use std::fmt; | ||
use std::io::Write; | ||
|
||
impl_enum_wrapper!( | ||
#[derive(Clone, SqlType, Debug, QueryId)] | ||
#[diesel(postgres_type(name = "migration_state", schema = "public"))] | ||
pub struct MigrationStateEnum; | ||
|
||
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq, Eq)] | ||
#[diesel(sql_type = MigrationStateEnum)] | ||
pub struct MigrationState(pub nexus::MigrationState); | ||
|
||
// Enum values | ||
Pending => b"pending" | ||
InProgress => b"in_progress" | ||
Completed => b"completed" | ||
Failed => b"failed" | ||
); | ||
|
||
impl MigrationState { | ||
/// Returns `true` if this migration state means that the migration is no | ||
/// longer in progress (it has either succeeded or failed). | ||
#[must_use] | ||
pub fn is_terminal(&self) -> bool { | ||
self.0.is_terminal() | ||
} | ||
} | ||
|
||
impl fmt::Display for MigrationState { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
fmt::Display::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
impl From<nexus::MigrationState> for MigrationState { | ||
fn from(s: nexus::MigrationState) -> Self { | ||
Self(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.