Skip to content

network: look up only the requested vnets in findOverlappingVnets - #29

Draft
calvix wants to merge 1 commit into
4.20from
fix/vnet-overlap-lookup
Draft

calvix wants to merge 1 commit into
4.20from
fix/vnet-overlap-lookup

Conversation

@calvix

@calvix calvix commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Description

Creating a network with an explicit VLAN/VXLAN tag scans the whole op_dc_vnet_alloc of 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 with Lock wait timeout exceeded.

DataCenterVnetDaoImpl.findOverlappingVnets (used by findVnet) 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 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 (ResourceCountDaoImpl, "Lock wait timeout exceeded");
  • the network resource counts drifted, because some of those operations failed half way.

NetworkServiceImpl also 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 (...) with data_center_id and, when given, physical_network_id. The existing unique index i_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.

  • No schema change, no API change.
  • CloudStack writes the vnet column with Integer.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 like 0100 matched before and does not now.
  • The order of the returned rows was not defined before and is not now. It can differ when the same vnet exists in two physical networks of a zone and the caller gives no physical network.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

How Has This Been Tested?

Unit tests: new DataCenterVnetDaoImplTest (7 tests):

  • the search has the vnet, zone and physical network conditions, and the vnets are passed as strings (the column is a varchar);
  • without a physical network the search has no physical network condition;
  • a vnet given twice is asked for once;
  • a range of 2500 vnets is 3 queries (batches of 1000, 1000, 500);
  • an empty request runs no query.

mvn -pl engine/schema test on 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:

  • createNetwork with a free tag: 0.24 s on a zone with a small range, 0.30 s on a zone with 190k op_dc_vnet_alloc rows, 306 ms on the zone with 1.8 million rows (30-100 s before);
  • no more Lock wait timeout exceeded on network create/delete while another network is created.

EXPLAIN of 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:

type: range
key:  i_op_dc_vnet_alloc__vnet__data_center_id
rows: 1000

How did you try to break this feature and the system with this change?

  • createNetwork with a tag inside the physical network's VXLAN range, a tag that is already used, and a free tag: refused, refused, created, as before.
  • A range larger than one batch, and a request that names the same vnet twice (unit tests).

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
calvix force-pushed the fix/vnet-overlap-lookup branch from ccf156b to d0c56c7 Compare December 3, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant