Skip to content

Commit

Permalink
Fix bad service NIC slots (#5080)
Browse files Browse the repository at this point in the history
This is the second half of the fix for #5056. #5065 (already merged)
fixed _how_ we were getting service NICs with nonzero slot values, and
this PR adds a schema migration to apply a one-time fix to any existing
service NICs with nonzero slot values. This matters to the
Reconfigurator, because currently the NICs sled-agent thinks it has
don't match the NICs recorded in CRDB (differing only by slot number).

Closes #5056.
  • Loading branch information
jgallagher authored Feb 16, 2024
1 parent 235420e commit 475fb62
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use omicron_common::api::external::SemverVersion;
///
/// This should be updated whenever the schema is changed. For more details,
/// refer to: schema/crdb/README.adoc
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(34, 0, 0);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(35, 0, 0);

table! {
disk (id) {
Expand Down
5 changes: 5 additions & 0 deletions nexus/db-queries/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub mod subquery;
pub(crate) mod true_or_cast_error;
mod update_and_check;

/// Batch statement to disable full table scans.
// This is `pub` so tests that don't go through our connection pool can disable
// full table scans the same way pooled connections do.
pub use pool_connection::DISALLOW_FULL_TABLE_SCAN_SQL;

#[cfg(test)]
mod test_utils;

Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/pool_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static CUSTOM_TYPE_KEYS: &'static [&'static str] = &[
];
const CUSTOM_TYPE_SCHEMA: &'static str = "public";

const DISALLOW_FULL_TABLE_SCAN_SQL: &str =
pub const DISALLOW_FULL_TABLE_SCAN_SQL: &str =
"set disallow_full_table_scans = on; set large_full_scan_rows = 0;";

#[derive(Debug)]
Expand Down
6 changes: 6 additions & 0 deletions nexus/tests/integration_tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use nexus_db_model::schema::SCHEMA_VERSION as LATEST_SCHEMA_VERSION;
use nexus_db_queries::db::datastore::{
all_sql_for_version_migration, EARLIEST_SUPPORTED_VERSION,
};
use nexus_db_queries::db::DISALLOW_FULL_TABLE_SCAN_SQL;
use nexus_test_utils::{db, load_test_config, ControlPlaneTestContextBuilder};
use omicron_common::api::external::SemverVersion;
use omicron_common::api::internal::shared::SwitchLocation;
Expand Down Expand Up @@ -118,6 +119,11 @@ async fn apply_update(

let client = crdb.connect().await.expect("failed to connect");

client
.batch_execute(DISALLOW_FULL_TABLE_SCAN_SQL)
.await
.expect("failed to disallow full table scans");

// We skip this for the earliest supported version because these tables
// might not exist yet.
if version != EARLIEST_SUPPORTED_VERSION {
Expand Down
6 changes: 6 additions & 0 deletions schema/crdb/35.0.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This isn't realy a schema migration, but is instead a one-off fix for
-- incorrect data (https://github.com/oxidecomputer/omicron/issues/5056) after
-- the root cause for the incorrect data has been addressed.
UPDATE omicron.public.network_interface
SET slot = 0
WHERE kind = 'service' AND time_deleted IS NULL;
2 changes: 1 addition & 1 deletion schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3515,7 +3515,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
( TRUE, NOW(), NOW(), '34.0.0', NULL)
( TRUE, NOW(), NOW(), '35.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;

0 comments on commit 475fb62

Please sign in to comment.