Skip to content

Commit

Permalink
Order NextItem subquery results predictably
Browse files Browse the repository at this point in the history
- Fixes #5055
- Add a new column, `index` to the `NextItem` subquery, which indexes
  the shifts from 0..n.
- Add an `ORDER BY index` clause to guarantee order.
- Add test
  • Loading branch information
bnaecker committed Feb 14, 2024
1 parent a93462f commit 604b19b
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 43 deletions.
11 changes: 6 additions & 5 deletions nexus/db-queries/src/db/queries/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ struct NextDiskSlot {

impl NextDiskSlot {
fn new(instance_id: Uuid) -> Self {
let generator = DefaultShiftGenerator {
base: 0,
max_shift: i64::try_from(MAX_DISKS_PER_INSTANCE).unwrap(),
min_shift: 0,
};
let generator = DefaultShiftGenerator::new(
0,
i64::try_from(MAX_DISKS_PER_INSTANCE).unwrap(),
0,
)
.expect("invalid min/max shift");
Self { inner: NextItem::new_scoped(generator, instance_id) }
}
}
Expand Down
19 changes: 10 additions & 9 deletions nexus/db-queries/src/db/queries/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ impl NextIpv4Address {
let subnet = IpNetwork::from(subnet);
let net = IpNetwork::from(first_available_address(&subnet));
let max_shift = i64::from(last_address_offset(&subnet));
let generator =
DefaultShiftGenerator { base: net, max_shift, min_shift: 0 };
let generator = DefaultShiftGenerator::new(net, max_shift, 0)
.expect("invalid min/max shift");
Self { inner: NextItem::new_scoped(generator, subnet_id) }
}
}
Expand Down Expand Up @@ -563,12 +563,12 @@ pub struct NextNicSlot {

impl NextNicSlot {
pub fn new(parent_id: Uuid) -> Self {
let generator = DefaultShiftGenerator {
base: 0,
max_shift: i64::try_from(MAX_NICS)
.expect("Too many network interfaces"),
min_shift: 0,
};
let generator = DefaultShiftGenerator::new(
0,
i64::try_from(MAX_NICS).expect("Too many network interfaces"),
0,
)
.expect("invalid min/max shift");
Self { inner: NextItem::new_scoped(generator, parent_id) }
}
}
Expand Down Expand Up @@ -613,7 +613,8 @@ impl NextMacAddress {
(base.into(), max_shift, min_shift)
}
};
let generator = DefaultShiftGenerator { base, max_shift, min_shift };
let generator = DefaultShiftGenerator::new(base, max_shift, min_shift)
.expect("invalid min/max shift");
Self { inner: NextItem::new_scoped(generator, vpc_id) }
}
}
Expand Down
Loading

0 comments on commit 604b19b

Please sign in to comment.