Skip to content

Commit c9b2ce2

Browse files
committed
Store -1 directly for unlimited NIC network rate instead of NULL
nics.network_rate was unsigned, so the only way to represent "unlimited" was NULL, even though every response-building call site already normalizes null/non-positive to -1 for API output - meaning NULL and -1 were already behaviorally equivalent, just inconsistent at the storage layer. NetworkModelImpl.getNetworkRate() never actually returns null (always a positive rate or -1), so the null-coalescing in NetworkOrchestrator was dead code once the column can hold -1 directly. Make the column signed so it can store -1 like every other "resolved" rate value in the codebase, simplify both NetworkOrchestrator call sites to store the value as-is, and let the backfill persist -1 for NICs whose legacy rate is unlimited instead of leaving them NULL.
1 parent f7d3e72 commit c9b2ce2

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final N
12331233
NicVO vo = checkForRaceAndAllocateNic(requested, network, isDefaultNic, deviceId, vm);
12341234

12351235
final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
1236-
vo.setNetworkRate(networkRate != null && networkRate > 0 ? networkRate : null);
1236+
vo.setNetworkRate(networkRate);
12371237
final NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network),
12381238
_networkModel.getNetworkTag(vm.getHypervisorType(), network));
12391239
if (vm.getType() == Type.DomainRouter) {
@@ -2307,7 +2307,7 @@ public NicProfile prepareNic(final VirtualMachineProfile vmProfile, final Deploy
23072307
nic.setState(Nic.State.Reserved);
23082308
}
23092309

2310-
nic.setNetworkRate(networkRate != null && networkRate > 0 ? networkRate : null);
2310+
nic.setNetworkRate(networkRate);
23112311

23122312
if (vmProfile.getType() == Type.DomainRouter) {
23132313
Pair<NetworkVO, VpcVO> networks = getGuestNetworkRouterAndVpcDetails(vmProfile.getId());

engine/schema/src/main/java/com/cloud/upgrade/NetworkRateBackfill.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private void backfillNicNetworkRates() {
9090
final boolean defaultNic = rs.getBoolean("default_nic");
9191
try {
9292
final Integer rate = computeLegacyNicNetworkRate(networkId, instanceId, defaultNic);
93-
if (rate != null && rate > 0) {
93+
if (rate != null && rate != 0) {
9494
updateNicNetworkRate(nicId, rate);
9595
}
9696
} catch (Exception e) {

engine/schema/src/main/resources/META-INF/db/schema-42300to2400.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
-- Schema upgrade from 4.23.0.0 to 24.0.0
2020
--;
2121

22-
ALTER TABLE `cloud`.`nics` ADD COLUMN `network_rate` int unsigned DEFAULT NULL COMMENT 'effective network rate in Mb/s for this NIC';
22+
ALTER TABLE `cloud`.`nics` ADD COLUMN `network_rate` int DEFAULT NULL COMMENT 'effective network rate in Mb/s for this NIC, -1 means unlimited';
2323

2424
ALTER TABLE `cloud`.`vpc_offerings` ADD COLUMN `public_nw_rate` smallint unsigned DEFAULT NULL COMMENT 'public gateway (internet-facing) network rate throttle mbits/s';

0 commit comments

Comments
 (0)