Skip to content

Commit

Permalink
convert to SqlU32 to i64
Browse files Browse the repository at this point in the history
  • Loading branch information
internet-diglett committed Nov 14, 2023
1 parent 351a0a8 commit d3e9c60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
24 changes: 8 additions & 16 deletions nexus/db-model/src/ipv4_nat_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SqlU32>,
pub version_added: i64,
pub version_removed: Option<i64>,
pub time_created: DateTime<Utc>,
pub time_deleted: Option<DateTime<Utc>>,
}
Expand All @@ -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<u32> {
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,
}

Expand All @@ -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<Ipv4NatEntry> 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 {
Expand Down
10 changes: 5 additions & 5 deletions nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions openapi/nexus-internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -3810,8 +3810,7 @@
},
"gen": {
"type": "integer",
"format": "uint32",
"minimum": 0
"format": "int64"
},
"last_port": {
"type": "integer",
Expand Down

0 comments on commit d3e9c60

Please sign in to comment.