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 1 commit 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 1 commit 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?

…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
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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.51%. Comparing base (21b2025) to head (9550ebe).
⚠️ Report is 207 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (21b2025) and HEAD (9550ebe). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (21b2025) HEAD (9550ebe)
unittests 1 0
Additional details and impacted files
@@              Coverage Diff              @@
##               main   #13353       +/-   ##
=============================================
- Coverage     17.67%    3.51%   -14.16%     
=============================================
  Files          5922      464     -5458     
  Lines        533165    40159   -493006     
  Branches      65208     7560    -57648     
=============================================
- Hits          94242     1413    -92829     
+ Misses       428276    38556   -389720     
+ Partials      10647      190    -10457     
Flag Coverage Δ
uitests 3.51% <ø> (-0.18%) ⬇️
unittests ?

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 ✖️ debian ✖️ suse15. SL-JID 18160

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