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 per physical network in our production
zone - so every createNetwork with an explicit VLAN/VXLAN tag spent tens of
seconds in it (NetworkOrchestrator.createGuestNetwork, inside the
commitNetwork transaction). That transaction already holds the resource_count
rows of the account, its domains and ROOT, so every network create and delete
in the cloud waited behind it 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. CloudStack
writes the vnet column as Integer.toString, so the string match finds the
same rows as the previous numeric comparison. No schema change.
Upstream: none yet - same code in apache/cloudstack main, to offer
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.
Record of the fix shipped as
cs-4.23.0.0+mdc-3.3.1(already onmdc/productionas303c3cc2ff, cherry-pick of this branch's6a1a2de40b), kept here with the full analysis for the upstream PR. Upstreammainstill has the same code;DataCenterVnetDaoImpl.javais identical between4.23.0.0andapache/cloudstackmain(8eaff972a0, 2026-12-01), so the commit applies there unchanged.Symptom (cloudstack-production, 2026-12-01)
createNetworkwith an explicit VLAN/VXLAN tag (here: the VMware migrator's per-NIC dry-run sandbox networks, L2 offering, VXLAN physical network) took 30-100 s.ResourceCountDaoImplfailed withLock wait timeout exceeded; try restarting transaction(HTTP 530 "Unable to find on DB"),NetworkOrchestratorlogged "Failed to delete network", API clients timed out.resource_countnetwork counters drifted below the real counts (cid-78140 vs 3,cid-62843 vs 4,cid-67561 vs 2) while increments failed or were rolled back.Root cause
NetworkServiceImpl.commitNetworkcreates the network in one transaction. Inside itNetworkOrchestrator.createGuestNetworkcallsDataCenterVnetDao.findVnet(...)(NetworkOrchestrator.java:2835/2840/2857).DataCenterVnetDaoImpl.findOverlappingVnetsthen ranlistBy(dc[, physical network])with no vnet condition: it loaded everyop_dc_vnet_allocrow of the zone (or physical network) intoDataCenterVnetVOobjects and searched for the requested vnet in Java.200000-2000000and2000001-3800000, 3.6 M in the zone; thefindVnet(dcId, vnet)overload without a physical network scans all of them).resource_countrows for the network type of the account, its domains and ROOT (ResourceLimitManagerImpl.lockAccountAndOwnerDomainRows,SELECT ... FOR UPDATE), so every network create/delete in the whole cloud queued behind the scan; waiters pastinnodb_lock_wait_timeout(50 s) failed.NetworkServiceImpl.java:443and:4912) paid the full scan per number.Evidence
csmig-sandbox-mig-98bf0fb2aeeff382), idle on the DB side (Sleep) while holding the networkresource_countrows ofcid-6756, its domain and ROOT for ~95 s; tworesource_countstatements waiting behind it.Lock wait timeout(MS1, 16:40:42 UTC): threadqtp...-7864,RUNNABLE, inGenericDaoBase.toEntityBean←DataCenterVnetDaoImpl.findOverlappingVnets←findVnet←NetworkOrchestrator.createGuestNetwork←NetworkServiceImpl$4.doInTransaction(commitNetwork) ←CreateNetworkCmd.execute.async_job: the migrator'sDeleteNetworkCmdtook 22-51 s in the incident windows (two failed).op_dc_vnet_allocon production:physical_network_id 203: 1800001 rows,205: 1800000 rows.Fix
findOverlappingVnetsasks only for the requested vnets:vnet IN (...)withdata_center_idand the optionalphysical_network_id(new search builderVnetsInDcSearch), served by the existing unique indexi_op_dc_vnet_alloc__vnet__data_center_id (vnet, physical_network_id, data_center_id)(EXPLAIN on production:range, 2 rows instead of 1.8 M). A tag range is looked up in batches of 1000. CloudStack writes thevnetcolumn asInteger.toString, so the string match finds the same rows as the old numeric comparison (production has no other format). No schema change, no interface change.Tests
DataCenterVnetDaoImplTest: one query for one vnet, one without a physical network, three for a 2500-vnet range, none for an empty one.mvn -pl engine/schema testonmdc/production3.3.0 + the commit: 388 tests, 0 failures, Checkstyle clean.git archiveof the tag, ubuntu:24.04): file lists identical to 3.3.0; the shippedDataCenterVnetDaoImpl.classhas the new search and noNumbersUtilscan.DeleteNetworkCmd0.1 s average.For the upstream PR
main(same code; applies unchanged). Probably also worth offering for the 4.20/4.22 LTS branches.NetworkServiceImpl(:443,:4912) benefit too; a follow-up could replace them with one range query.