-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[nexus] Turn
instance.boot_on_fault
into an enum (#6499)
Currently, the `instance` table has a `boot_on_fault` column, which is a `bool`. This is intended to indicate whether an instance should be automatically restarted in response to failures, although currently, it isn't actually consumed by anything. However, as determined in RFD 486, Nexus will eventually grow functionality for automatically restarting instances that have transitioned to the `Failed` state, if `boot_on_fault` is set. @gjcolombo suggests that this field should probably be replaced with an enum, rather than a `bool`. This way, we could represent more boot-on-fault disciplines than "always reboot on faults" and "never do that". Since nothing is currently consuming this field, it's probably a good idea to go ahead and do the requisite SQL surgery to turn it into an enum _now_, before we write code that actually consumes it...especially since I'm planning on actually doing that next (see #6491). This commit replaces the `boot_on_fault` column with a new `auto_restart_policy` column. The type for this column is a newly-added `InstanceAutoRestart` enum, which currently has variants for `AllFailures` (the instance should be automatically restarted any time it fails), `SledFailuresOnly`, (the instance should be restarted if the sled it's on reboots or is expunged, but it should *not* be restarted if its individual VMM process crashes), and `Never` (the instance should never be automatically restarted). The database migration adding `auto_restart_policy` backfills any existing `boot_on_fault: true` instances with `InstanceAutoRestart::AllFailures` (although, because users can't currently set a value for `boot_on_fault`, there should usually be no such instances). For instances with `boot_on_fault: false`, the auto-restart policy is left `NULL`; in the future, we can determine what the default policy should be (perhaps at the project-level) and backfill these `NULL`s as well. For now, instances with an unset (`NULL`) policy will not be restarted. Closes #6490
- Loading branch information
Showing
11 changed files
with
134 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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::impl_enum_type; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use std::fmt; | ||
|
||
impl_enum_type!( | ||
#[derive(SqlType, Debug)] | ||
#[diesel(postgres_type(name = "instance_auto_restart", schema = "public"))] | ||
pub struct InstanceAutoRestartEnum; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, AsExpression, FromSqlRow, Serialize, Deserialize)] | ||
#[diesel(sql_type = InstanceAutoRestartEnum)] | ||
pub enum InstanceAutoRestart; | ||
|
||
// Enum values | ||
Never => b"never" | ||
SledFailuresOnly => b"sled_failures_only" | ||
AllFailures => b"all_failures" | ||
); | ||
|
||
impl InstanceAutoRestart { | ||
pub fn label(&self) -> &'static str { | ||
match self { | ||
Self::Never => "never", | ||
Self::SledFailuresOnly => "sled_failures_only", | ||
Self::AllFailures => "all_failures", | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for InstanceAutoRestart { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.label()) | ||
} | ||
} | ||
|
||
impl diesel::query_builder::QueryId for InstanceAutoRestart { | ||
type QueryId = (); | ||
const HAS_STATIC_QUERY_ID: bool = false; | ||
} |
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
18 changes: 18 additions & 0 deletions
18
schema/crdb/turn-boot-on-fault-into-auto-restart/README.adoc
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,18 @@ | ||
= Overview | ||
|
||
This migration replaces the `omicron.public.instance.boot_on_fault` column, | ||
which is a `bool`, with a new `auto_restart_policy` column, which is an enum | ||
(`omicron.public.instance_auto_restart`). The new enum type will allow | ||
auto-restart policies other than "always" and "never". | ||
Existing instance records are backfilled with the `all_failures` variant of | ||
`instance_auto_restart` if `boot_on_fault` is `true`. Otherwise, the | ||
auto-restart policy is `NULL`. | ||
|
||
The migration performs the following operations: | ||
|
||
1. `up01.sql` creates the `instance_auto_restart` enum. | ||
2. `up02.sql` adds a (nullable) `auto_restart_policy` column to the `instance` | ||
table. | ||
3. `up03.sql` updates instance records by setting `auto_restart_policy` to | ||
`all_failures` if `boot_on_fault` is `true`. | ||
4. Finally, `up04.sql` drops the now-defunct `boot_on_fault` column. |
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,19 @@ | ||
CREATE TYPE IF NOT EXISTS omicron.public.instance_auto_restart AS ENUM ( | ||
/* | ||
* The instance should not, under any circumstances, be automatically | ||
* rebooted by the control plane. | ||
*/ | ||
'never', | ||
/* | ||
* The instance should be automatically restarted if, and only if, the sled | ||
* it was running on has restarted or become unavailable. If the individual | ||
* Propolis VMM process for this instance crashes, it should *not* be | ||
* restarted automatically. | ||
*/ | ||
'sled_failures_only', | ||
/* | ||
* The instance should be automatically restarted any time a fault is | ||
* detected | ||
*/ | ||
'all_failures' | ||
); |
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,2 @@ | ||
ALTER TABLE omicron.public.instance | ||
ADD COLUMN IF NOT EXISTS auto_restart_policy omicron.public.instance_auto_restart; |
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,5 @@ | ||
SET LOCAL disallow_full_table_scans = off; | ||
UPDATE omicron.public.instance SET auto_restart_policy = CASE | ||
WHEN boot_on_fault = true THEN 'all_failures' | ||
ELSE NULL | ||
END; |
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 @@ | ||
ALTER TABLE omicron.public.instance DROP COLUMN IF EXISTS boot_on_fault; |