Skip to content

Batch VM and host lookups in StorageManagerImpl to eliminate N+1 queries during cleanup and pool connect#13353

Draft
vishesh92 wants to merge 2 commits into
apache:mainfrom
shapeblue:batch-vm-host-lookups
Draft

Batch VM and host lookups in StorageManagerImpl to eliminate N+1 queries during cleanup and pool connect#13353
vishesh92 wants to merge 2 commits into
apache:mainfrom
shapeblue:batch-vm-host-lookups

Conversation

@vishesh92

Copy link
Copy Markdown
Member

Description

cleanupStorage: replaced per-volume _vmInstanceDao.findById(vol.getInstanceId()) with a single batch SELECT ... WHERE id IN (...) before the loop, using a HashMap for O(1) lookups. Added null guard for volumes with null instanceId.

connectHostsToPool: replaced per-thread _hostDao.findById(hostId) with a batch load before thread pool submission. Each thread now reads from a pre-built HashMap instead of hitting the DB. Added null guard with warning log for hosts removed between list assembly and batch read.

Added VMInstanceDao.listByIds(List) with empty-list guard and IN-clause SearchBuilder, matching the established pattern in HostDao.

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?

@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

codecov Bot commented Jun 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.75%. Comparing base (6bc83a3) to head (d867216).

Files with missing lines Patch % Lines
.../main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java 0.00% 10 Missing ⚠️
...ain/java/com/cloud/storage/StorageManagerImpl.java 44.44% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #13353      +/-   ##
============================================
- Coverage     18.75%   18.75%   -0.01%     
+ Complexity    17966    17964       -2     
============================================
  Files          6160     6160              
  Lines        552578   552604      +26     
  Branches      67348    67352       +4     
============================================
  Hits         103660   103660              
- Misses       437512   437538      +26     
  Partials      11406    11406              
Flag Coverage Δ
uitests 3.53% <ø> (ø)
unittests 19.95% <28.57%> (-0.01%) ⬇️

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.

…ies during cleanup and pool connect

cleanupStorage: replaced per-volume _vmInstanceDao.findById(vol.getInstanceId())
with a single batch SELECT ... WHERE id IN (...) before the loop, using a
HashMap for O(1) lookups. Added null guard for volumes with null instanceId.

connectHostsToPool: replaced per-thread _hostDao.findById(hostId) with a
batch load before thread pool submission. Each thread now reads from a
pre-built HashMap instead of hitting the DB. Added null guard with warning
log for hosts removed between list assembly and batch read.

Added VMInstanceDao.listByIds(List<Long>) with empty-list guard and IN-clause
SearchBuilder, matching the established pattern in HostDao.
@vishesh92 vishesh92 force-pushed the batch-vm-host-lookups branch from dad9933 to d867216 Compare June 8, 2026 12:43
@vishesh92

Copy link
Copy Markdown
Member Author

@blueorangutan package

@apache apache deleted a comment from blueorangutan Jun 8, 2026
@apache apache deleted a comment from blueorangutan Jun 8, 2026
@apache apache deleted a comment from blueorangutan Jun 8, 2026
@apache apache deleted a comment from github-actions Bot Jun 8, 2026
@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.

@blueorangutan

Copy link
Copy Markdown

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

@vishesh92

Copy link
Copy Markdown
Member Author

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@vishesh92 a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-16262)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 64134 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr13353-t16262-kvm-ol8.zip
Smoke tests completed. 145 look OK, 6 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestVPCConserveModeRules>:setup Error 0.00 test_vpc_conserve_mode.py
ContextSuite context=TestIpv6Vpc>:setup Error 0.00 test_vpc_ipv6.py
ContextSuite context=TestVPCRedundancy>:setup Error 0.00 test_vpc_redundant.py
ContextSuite context=TestVPCNics>:setup Error 0.00 test_vpc_router_nics.py
ContextSuite context=TestRVPCSite2SiteVpn>:setup Error 0.00 test_vpc_vpn.py
ContextSuite context=TestVPCSite2SiteVPNMultipleOptions>:setup Error 0.00 test_vpc_vpn.py
ContextSuite context=TestVpcRemoteAccessVpn>:setup Error 0.00 test_vpc_vpn.py
ContextSuite context=TestVpcSite2SiteVpn>:setup Error 0.00 test_vpc_vpn.py
test_disable_oobm_ha_state_ineligible Error 1517.95 test_hostha_kvm.py

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