-
Notifications
You must be signed in to change notification settings - Fork 44
add migration
table and explicit migration tracking in sled-agent
#5859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 33 commits
370b73c
d017eb0
9362651
e6e5e14
c8a0c7c
00c2c93
7f95255
6304817
d57060f
77e3080
6b63d22
7f3c7fa
45d7844
c6311fb
43254ad
f649f82
fd5e49c
631ba0f
1aecc88
270368f
47cfd55
f399eb1
8e75658
762febc
7634307
e4f7c6b
9d0de2b
f6c9875
77a6dfe
29eae36
18ccc7e
00ad191
4e3e4f2
a1ca946
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
Comment on lines
+45
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not opposed to starting with the "state" being the same at source and destination, but I wonder if we'll eventually want different types here. Seems possible that there's a source-only or target-only state in the future. (No change needed, just musing) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, the intention for this table is to store pretty low-resolution data about the migration state, basically just whether it's completed or failed, so we're not including more detailed migration status reported by Propolis. So, we don't really expect these to include states that are specific to one side of the migration currently, although I suppose we could... |
||
|
||
/// 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, | ||
} | ||
} | ||
} |
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) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.