Skip to content

Fix query execution in countVgpuVMs#12713

Open
vishesh92 wants to merge 1 commit intoapache:4.22from
shapeblue:fixup-query-countVgpuVMs
Open

Fix query execution in countVgpuVMs#12713
vishesh92 wants to merge 1 commit intoapache:4.22from
shapeblue:fixup-query-countVgpuVMs

Conversation

@vishesh92
Copy link
Member

@vishesh92 vishesh92 commented Feb 26, 2026

Description

This PR fixes #12712

Generated Summary

This pull request makes a minor adjustment to the order of prepared statement execution in the countVgpuVMs method of VMInstanceDaoImpl.java. The change ensures that the legacy query is executed and processed before preparing and executing the main query, which improves clarity and may help prevent resource conflicts.

  • Refactored the execution order in countVgpuVMs so that the legacy query is prepared, parameters set, and results processed before preparing and executing the main query, potentially improving resource management and code clarity.

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 vishesh92 requested a review from Copilot February 26, 2026 09:26
@vishesh92 vishesh92 changed the base branch from main to 4.22 February 26, 2026 09:26
@vishesh92 vishesh92 requested review from Copilot and removed request for Copilot February 26, 2026 09:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the execution order of statements in countVgpuVMs to ensure the legacy query is executed and processed before the main query, aligning with the intended behavior in the linked issue.

Changes:

  • Reordered prepared statement creation/execution so the legacy query runs first.
  • Moved parameter binding for the main query to occur after legacy results are processed.
Comments suppressed due to low confidence (1)

engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java:864

  • The ResultSet from the legacy query is reassigned (rs = pstmt.executeQuery()) without being closed first, which can leak DB/cursor resources depending on the JDBC driver. Use separate ResultSet variables and/or wrap each executeQuery() in its own try-with-resources block so the legacy ResultSet is closed before executing the main query.
            ResultSet rs = pstmtLegacy.executeQuery();
            while (rs.next()) {
                result.put(rs.getString(1).concat(rs.getString(2)), rs.getLong(3));
            }

            pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
            for (int i = 0; i < resourceIdList.size(); i++) {
                pstmt.setLong(1 + i, resourceIdList.get(i));
            }
            rs = pstmt.executeQuery();
            while (rs.next()) {
                result.put(rs.getString(1).concat(rs.getString(2)), rs.getLong(3));
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.92%. Comparing base (b74f21b) to head (27d3c48).
⚠️ Report is 1 commits behind head on 4.22.

Files with missing lines Patch % Lines
.../main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12713      +/-   ##
============================================
+ Coverage     17.61%   17.92%   +0.31%     
- Complexity    15662    16155     +493     
============================================
  Files          5917     5939      +22     
  Lines        531360   533148    +1788     
  Branches      64969    65238     +269     
============================================
+ Hits          93584    95573    +1989     
+ Misses       427224   426834     -390     
- Partials      10552    10741     +189     
Flag Coverage Δ
uitests 3.66% <ø> (-0.04%) ⬇️
unittests 19.03% <0.00%> (+0.35%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@vishesh92
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

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

@vishesh92 vishesh92 added this to the 4.22.1 milestone Feb 26, 2026
@blueorangutan
Copy link

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

Copy link
Contributor

@sureshanaparti sureshanaparti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgmt

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

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

An error getting clusters resources information on GUI ACS 4.22

4 participants