Repository navigation
Conversation
DataCenterVnetDaoImpl.findOverlappingVnets loaded every op_dc_vnet_alloc row
of the zone (or of the physical network) into entity objects and then looked
for the requested vnet in Java. With a VXLAN physical network that is one row
per VNI of its range - 1.8 million rows for one physical network in the zone
where we hit this - so every createNetwork with an explicit VLAN/VXLAN tag
spent tens of seconds in it (NetworkOrchestrator.createGuestNetwork, inside
the commitNetwork transaction). While that transaction was open, other
network creates and deletes waited on the resource_count rows and failed
after innodb_lock_wait_timeout ("Lock wait timeout exceeded",
ResourceCountDaoImpl), and the network counts drifted. The callers that check
a range one number at a time (NetworkServiceImpl) paid the full scan per
number.
Query only the requested vnets: vnet IN (...) with data_center_id and the
optional physical_network_id, which the existing unique index
i_op_dc_vnet_alloc__vnet__data_center_id (vnet, physical_network_id,
data_center_id) serves; ranges are looked up in batches of 1000. No schema
change.
CloudStack writes the vnet column as Integer.toString, so for the rows it
wrote the string match finds the same rows as the previous numeric
comparison. The order of the rows was not defined before and is not now.
calvix
force-pushed
the
fix/vnet-overlap-lookup
branch
from
December 3, 2026 08:11
ccf156b to
d0c56c7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Creating a network with an explicit VLAN/VXLAN tag scans the whole
op_dc_vnet_allocof the zone inside the network-create transaction. On a zone with a large VXLAN range this makes other network creates and deletes wait for it, and they fail withLock wait timeout exceeded.DataCenterVnetDaoImpl.findOverlappingVnets(used byfindVnet) loads every vnet row of the zone, or of the physical network, into entity objects and then looks for the requested vnet in Java. A VXLAN physical network has one row per VNI of its range: 1.8 million rows for one physical network in the zone where we hit this. Each call took tens of seconds.It is called from
NetworkOrchestrator.createGuestNetwork, inside thecommitNetworktransaction. While that transaction was open:resource_countrows and failed afterinnodb_lock_wait_timeout(ResourceCountDaoImpl, "Lock wait timeout exceeded");NetworkServiceImplalso calls it once per number when it checks a vnet range, so a range check paid the full scan for every number in it.This PR queries only the requested vnets:
vnet IN (...)withdata_center_idand, when given,physical_network_id. The existing unique indexi_op_dc_vnet_alloc__vnet__data_center_id (vnet, physical_network_id, data_center_id)serves it. Ranges are looked up in batches of 1000 values.vnetcolumn withInteger.toString, so for the rows it wrote, matching the string finds the same rows as the old numeric comparison. A row edited by hand to something like0100matched before and does not now.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
Unit tests: new
DataCenterVnetDaoImplTest(7 tests):mvn -pl engine/schema teston this branch (4.20, JDK 11): 240 tests, 0 failures.With the same change on 4.23, on KVM zones with a VXLAN physical network:
op_dc_vnet_allocrows, 306 ms on the zone with 1.8 million rows (30-100 s before);Lock wait timeout exceededon network create/delete while another network is created.EXPLAINof the new query with 1000 values on the table with 1.8 million rows per physical network (MySQL 8.4), with and without the physical network condition:How did you try to break this feature and the system with this change?