Skip to content

Commit b40fcbd

Browse files
committed
nexus: update switch_port_settings_route_config schema
I renamed the `local_pref` column to `rib_priority` to complete the rename in #6693. I also changed the type of the renamed column from `INT8` to `INT2`, clamping existing values to `0` or `255`. This was missed in #6693 and led to the following error when reading the value from the database. ``` {"msg":"request completed","v":0,"name":"omicron-dev","level":30,"time":"2025-07-11T13:57:48.670343242Z","hostname":"ms-ox01","pid":3113,"uri":"/v1/system/networking/switch-port-settings","method":"POST","req_id":"12b35f5a-2255-4244-a5aa-f9c84032fb81","remote_addr":"127.0.0.1:41766","local_addr":"127.0.0.1:12220","component":"dropshot_external","name":"e6bff1ff-24fb-49dc-a54e-c6a350cd4d6c","error_message_external":"Internal Server Error","error_message_internal":"Unknown diesel error creating SwitchPortSettings called \"example\": Error deserializing field 'local_pref': Received more than 2 bytes while decoding an i16. Was an Integer expression accidentally marked as SmallInt?","latency_us":133766,"response_code":500} ``` The error occurred because the Rust type was `SqlU8` and the database type was `INT8`. Reads would fail because `INT8` columns could not be read into `SqlU8` types without loss of precision. This was caught in oxidecomputer/terraform-provider-oxide#426 when implementing a Terraform provider resource for switch port settings. It's likely that this has been broken since #6693 and any user that attempted to set `rib_priority` in their Rack Setup Service (RSS) would have encountered this error. However, `rib_priority` is an uncommon configuration option and none of our customer's RSS configurations show this as being set. Given this information, it seems safe to assume that no customer has the `rib_priority` column set so the clamping logic implemented here should work well for customer installations.
1 parent 3619914 commit b40fcbd

File tree

10 files changed

+20
-10
lines changed

10 files changed

+20
-10
lines changed

common/src/api/external/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2998,7 +2998,8 @@ pub struct SwitchPortRouteConfig {
29982998
/// over an 802.1Q tagged L2 segment.
29992999
pub vlan_id: Option<u16>,
30003000

3001-
/// RIB Priority indicating priority within and across protocols.
3001+
/// Route RIB priority. Higher priority indicates precedence within and across
3002+
/// protocols.
30023003
pub rib_priority: Option<u8>,
30033004
}
30043005

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
1616
///
1717
/// This must be updated when you change the database schema. Refer to
1818
/// schema/crdb/README.adoc in the root of this repository for details.
19-
pub const SCHEMA_VERSION: Version = Version::new(161, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(162, 0, 0);
2020

2121
/// List of all past database schema versions, in *reverse* order
2222
///
@@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
2828
// | leaving the first copy as an example for the next person.
2929
// v
3030
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
31+
KnownVersion::new(162, "route-config-rib-priority"),
3132
KnownVersion::new(161, "inv_cockroachdb_status"),
3233
KnownVersion::new(160, "tuf-trust-root"),
3334
KnownVersion::new(159, "sled-config-desired-host-phase-2"),

nexus/db-model/src/switch_port.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,6 @@ pub struct SwitchPortRouteConfig {
609609
pub dst: IpNetwork,
610610
pub gw: IpNetwork,
611611
pub vid: Option<SqlU16>,
612-
#[diesel(column_name = local_pref)]
613612
pub rib_priority: Option<SqlU8>,
614613
}
615614

nexus/db-schema/src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ table! {
202202
dst -> Inet,
203203
gw -> Inet,
204204
vid -> Nullable<Int4>,
205-
local_pref -> Nullable<Int2>,
205+
rib_priority -> Nullable<Int2>,
206206
}
207207
}
208208

nexus/types/src/external_api/params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,8 +2003,8 @@ pub struct Route {
20032003
/// VLAN id the gateway is reachable over.
20042004
pub vid: Option<u16>,
20052005

2006-
/// Local preference for route. Higher preference indictes precedence
2007-
/// within and across protocols.
2006+
/// Route RIB priority. Higher priority indicates precedence within and across
2007+
/// protocols.
20082008
pub rib_priority: Option<u8>,
20092009
}
20102010

openapi/nexus.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22294,7 +22294,7 @@
2229422294
},
2229522295
"rib_priority": {
2229622296
"nullable": true,
22297-
"description": "Local preference for route. Higher preference indictes precedence within and across protocols.",
22297+
"description": "Route RIB priority. Higher priority indicates precedence within and across protocols.",
2229822298
"type": "integer",
2229922299
"format": "uint8",
2230022300
"minimum": 0
@@ -24570,7 +24570,7 @@
2457024570
},
2457124571
"rib_priority": {
2457224572
"nullable": true,
24573-
"description": "RIB Priority indicating priority within and across protocols.",
24573+
"description": "Route RIB priority. Higher priority indicates precedence within and across protocols.",
2457424574
"type": "integer",
2457524575
"format": "uint8",
2457624576
"minimum": 0

schema/crdb/dbinit.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,7 +3144,7 @@ CREATE TABLE IF NOT EXISTS omicron.public.switch_port_settings_route_config (
31443144
dst INET,
31453145
gw INET,
31463146
vid INT4,
3147-
local_pref INT8,
3147+
rib_priority INT2,
31483148

31493149
/* TODO https://github.com/oxidecomputer/omicron/issues/3013 */
31503150
PRIMARY KEY (port_settings_id, interface_name, dst, gw)
@@ -6198,7 +6198,7 @@ INSERT INTO omicron.public.db_metadata (
61986198
version,
61996199
target_version
62006200
) VALUES
6201-
(TRUE, NOW(), NOW(), '161.0.0', NULL)
6201+
(TRUE, NOW(), NOW(), '162.0.0', NULL)
62026202
ON CONFLICT DO NOTHING;
62036203

62046204
COMMIT;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE omicron.public.switch_port_settings_route_config ADD COLUMN rib_priority INT2;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
UPDATE omicron.public.switch_port_settings_route_config
2+
SET rib_priority =
3+
CASE
4+
WHEN local_pref > 255 THEN 255
5+
WHEN local_pref < 0 THEN 0
6+
ELSE local_pref::INT2
7+
END;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE omicron.public.switch_port_settings_route_config DROP COLUMN local_pref;

0 commit comments

Comments
 (0)