Skip to content

Commit

Permalink
[dns-server] use the Generation type to represent generations (#6847)
Browse files Browse the repository at this point in the history
While working on reconfigurator simulation, the fact that generations were u64s
here was getting in the way. I could either work around it or simply fix it, so
here's the fix.
  • Loading branch information
sunshowers authored Oct 16, 2024
1 parent 7f90954 commit 5be473d
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 162 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,15 @@ impl From<ByteCount> for i64 {

/// Generation numbers stored in the database, used for optimistic concurrency
/// control
// Because generation numbers are stored in the database, we represent them as
// i64.
//
// A generation is a value between 0 and 2**63-1, i.e. equivalent to a u63.
// The reason is that we store it as an i64 in the database, and we want to
// disallow negative values. (We could potentially use two's complement to
// store values greater than that as negative values, but surely 2**63 is
// enough.)
//
// TODO: This allows deserialization into a value that's out of range. That's
// not correct. See <https://github.com/oxidecomputer/omicron/issues/6865>.
#[derive(
Copy,
Clone,
Expand Down
4 changes: 2 additions & 2 deletions dev-tools/reconfigurator-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,15 +1392,15 @@ fn cmd_load_example(
sim.internal_dns.insert(
blueprint.internal_dns_version,
DnsConfigParams {
generation: blueprint.internal_dns_version.into(),
generation: blueprint.internal_dns_version,
time_created: Utc::now(),
zones: vec![internal_dns],
},
);
sim.external_dns.insert(
blueprint.external_dns_version,
DnsConfigParams {
generation: blueprint.external_dns_version.into(),
generation: blueprint.external_dns_version,
time_created: Utc::now(),
zones: vec![external_dns],
},
Expand Down
1 change: 1 addition & 0 deletions dns-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ hickory-resolver.workspace = true
hickory-server.workspace = true
http.workspace = true
internal-dns-types.workspace = true
omicron-common.workspace = true
pretty-hex.workspace = true
schemars.workspace = true
serde.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions dns-server/src/bin/dnsadm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ async fn main() -> Result<()> {
.collect();

let new_config = DnsConfigParams {
generation: old_config.generation + 1,
generation: old_config.generation.next(),
time_created: chrono::Utc::now(),
zones,
};
Expand Down Expand Up @@ -275,7 +275,7 @@ fn add_record(
our_kv.1.push(record);

Ok(DnsConfigParams {
generation: generation + 1,
generation: generation.next(),
time_created: chrono::Utc::now(),
zones: other_zones
.into_iter()
Expand Down
Loading

0 comments on commit 5be473d

Please sign in to comment.