From d3e9c609f5c25b06c4e5c81a6ea61252cf5c7a09 Mon Sep 17 00:00:00 2001 From: Levon Tarver Date: Tue, 14 Nov 2023 20:03:40 +0000 Subject: [PATCH] convert to SqlU32 to i64 --- nexus/db-model/src/ipv4_nat_entry.rs | 24 +++++++------------ .../src/db/datastore/ipv4_nat_entry.rs | 10 ++++---- openapi/nexus-internal.json | 3 +-- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/nexus/db-model/src/ipv4_nat_entry.rs b/nexus/db-model/src/ipv4_nat_entry.rs index 3e73c6e2d1..56417031a1 100644 --- a/nexus/db-model/src/ipv4_nat_entry.rs +++ b/nexus/db-model/src/ipv4_nat_entry.rs @@ -3,7 +3,7 @@ use std::net::{Ipv4Addr, Ipv6Addr}; use super::MacAddr; use crate::{ schema::{ipv4_nat_entry, ipv4_nat_version}, - Ipv4Net, Ipv6Net, SqlU16, SqlU32, Vni, + Ipv4Net, Ipv6Net, SqlU16, Vni, }; use chrono::{DateTime, Utc}; use omicron_common::api::external; @@ -34,8 +34,8 @@ pub struct Ipv4NatEntry { pub sled_address: Ipv6Net, pub vni: Vni, pub mac: MacAddr, - pub version_added: SqlU32, - pub version_removed: Option, + pub version_added: i64, + pub version_removed: Option, pub time_created: DateTime, pub time_deleted: Option>, } @@ -48,22 +48,14 @@ impl Ipv4NatEntry { pub fn last_port(&self) -> u16 { self.last_port.into() } - - pub fn version_added(&self) -> u32 { - self.version_added.into() - } - - pub fn version_removed(&self) -> Option { - self.version_removed.map(|i| i.into()) - } } /// Database representation of an Ipv4 NAT Generation. #[derive(Queryable, Debug, Clone, Selectable)] #[diesel(table_name = ipv4_nat_version)] pub struct Ipv4NatGen { - pub last_value: SqlU32, - pub log_cnt: SqlU32, + pub last_value: i64, + pub log_cnt: i64, pub is_called: bool, } @@ -76,15 +68,15 @@ pub struct Ipv4NatEntryView { pub sled_address: Ipv6Addr, pub vni: external::Vni, pub mac: external::MacAddr, - pub gen: u32, + pub gen: i64, pub deleted: bool, } impl From for Ipv4NatEntryView { fn from(value: Ipv4NatEntry) -> Self { let (gen, deleted) = match value.version_removed { - Some(gen) => (*gen, true), - None => (*value.version_added, false), + Some(gen) => (gen, true), + None => (value.version_added, false), }; Self { diff --git a/nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs b/nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs index 771aae2d2d..3b0abf32d5 100644 --- a/nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs +++ b/nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs @@ -332,7 +332,7 @@ mod test { // The NAT table has undergone one change. One entry has been added, // none deleted, so we should be at version 1. assert_eq!(nat_entries.len(), 1); - assert_eq!(nat_entries.last().unwrap().version_added(), 1); + assert_eq!(nat_entries.last().unwrap().version_added, 1); assert_eq!( datastore.ipv4_nat_current_version(&opctx).await.unwrap(), 1 @@ -358,9 +358,9 @@ mod test { // The NAT table has undergone two changes. Two entries have been // added, none deleted, so we should be at version 2. let nat_entry = - nat_entries.iter().find(|e| e.version_added() == 2).unwrap(); + nat_entries.iter().find(|e| e.version_added == 2).unwrap(); assert_eq!(nat_entries.len(), 2); - assert_eq!(nat_entry.version_added(), 2); + assert_eq!(nat_entry.version_added, 2); assert_eq!( datastore.ipv4_nat_current_version(&opctx).await.unwrap(), 2 @@ -393,9 +393,9 @@ mod test { // first entry was marked for deletion (and it was the third change), // the first entry's version number should now be 3. let nat_entry = - nat_entries.iter().find(|e| e.version_removed().is_some()).unwrap(); + nat_entries.iter().find(|e| e.version_removed.is_some()).unwrap(); assert_eq!(nat_entries.len(), 2); - assert_eq!(nat_entry.version_removed(), Some(3)); + assert_eq!(nat_entry.version_removed, Some(3)); assert_eq!(nat_entry.id, first_entry.id); assert_eq!( datastore.ipv4_nat_current_version(&opctx).await.unwrap(), diff --git a/openapi/nexus-internal.json b/openapi/nexus-internal.json index 15201d2fdf..c42fb2391f 100644 --- a/openapi/nexus-internal.json +++ b/openapi/nexus-internal.json @@ -3810,8 +3810,7 @@ }, "gen": { "type": "integer", - "format": "uint32", - "minimum": 0 + "format": "int64" }, "last_port": { "type": "integer",