Skip to content

Batch network lookups per NIC in NetworkOrchestrator to eliminate N+1 queries during migration#13354

Draft
vishesh92 wants to merge 1 commit into
apache:mainfrom
shapeblue:batch-network-lookups
Draft

Batch network lookups per NIC in NetworkOrchestrator to eliminate N+1 queries during migration#13354
vishesh92 wants to merge 1 commit into
apache:mainfrom
shapeblue:batch-network-lookups

Conversation

@vishesh92
Copy link
Copy Markdown
Member

Description

Three methods called _networksDao.findById(nic.getNetworkId()) per NIC in a loop: setHypervisorHostname, prepareNicForMigration, prepareAllNicsForMigration. Now batch-loads all networks for a VM's NICs in a single WHERE id IN (...) query.

  • Add NetworkDao.listByIds(List) for batch ID lookup
  • Add getNetworkMapForNics helper returning Map<Long, NetworkVO>
  • Replace per-NIC findById with map lookup at 3 sites
  • Add null guard for deleted networks (pre-existing NPE risk on all 3 sites)

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

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

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

… queries during migration

Three methods called _networksDao.findById(nic.getNetworkId()) per NIC in a loop:
setHypervisorHostname, prepareNicForMigration, prepareAllNicsForMigration.
Now batch-loads all networks for a VM's NICs in a single WHERE id IN (...) query.

- Add NetworkDao.listByIds(List<Long>) for batch ID lookup
- Add getNetworkMapForNics helper returning Map<Long, NetworkVO>
- Replace per-NIC findById with map lookup at 3 sites
- Add null guard for deleted networks (pre-existing NPE risk on all 3 sites)
- Site 2 (prepare) left unchanged — findById only on error path, not N+1
@vishesh92
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

❌ Patch coverage is 0% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.10%. Comparing base (21b2025) to head (81ca4c9).
⚠️ Report is 207 commits behind head on main.

Files with missing lines Patch % Lines
...tack/engine/orchestration/NetworkOrchestrator.java 0.00% 30 Missing ⚠️
...ain/java/com/cloud/network/dao/NetworkDaoImpl.java 0.00% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13354      +/-   ##
============================================
+ Coverage     17.67%   18.10%   +0.43%     
- Complexity    15792    16751     +959     
============================================
  Files          5922     6037     +115     
  Lines        533165   542832    +9667     
  Branches      65208    66463    +1255     
============================================
+ Hits          94242    98295    +4053     
- Misses       428276   433491    +5215     
- Partials      10647    11046     +399     
Flag Coverage Δ
uitests 3.51% <ø> (-0.18%) ⬇️
unittests 19.27% <0.00%> (+0.52%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blueorangutan
Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants