Skip to content

Conversation

@abh1sar
Copy link
Collaborator

@abh1sar abh1sar commented Jan 14, 2026

Description

This PR fixes #12397

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?

Tested listCapacity api with fetchlatest parameter. No exceptions were observed.
Tested with the Fetch Latest button on the capacity dashboard. Capacities were lister correctly.

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

@abh1sar abh1sar changed the base branch from main to 4.20 January 14, 2026 08:04
@abh1sar abh1sar requested a review from shwstppr January 14, 2026 08:04
@abh1sar abh1sar added this to the 4.20.3 milestone Jan 14, 2026
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 17.76%. Comparing base (56a39e6) to head (da4377e).
⚠️ Report is 21 commits behind head on 4.20.

Files with missing lines Patch % Lines
...rc/main/java/com/cloud/alert/AlertManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #12421      +/-   ##
============================================
+ Coverage     16.23%   17.76%   +1.52%     
- Complexity    13378    15863    +2485     
============================================
  Files          5657     5923     +266     
  Lines        498866   530603   +31737     
  Branches      60545    64835    +4290     
============================================
+ Hits          81011    94273   +13262     
- Misses       408821   425783   +16962     
- Partials       9034    10547    +1513     
Flag Coverage Δ
uitests 3.59% <ø> (-0.41%) ⬇️
unittests 18.85% <0.00%> (+1.75%) ⬆️

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.

@abh1sar
Copy link
Collaborator Author

abh1sar commented Jan 14, 2026

@blueorangutan package

@blueorangutan
Copy link

@abh1sar 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 requested a review from Copilot January 14, 2026 09:50
Copy link
Member

@vishesh92 vishesh92 left a comment

Choose a reason for hiding this comment

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

clgtm

@blueorangutan
Copy link

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

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

This PR fixes a RuntimeException that occurs when using the listCapacity API with the fetchlatest parameter. The issue is caused by nested transaction handling when updateCapacityForHost (which has the @DB annotation and manages its own transactions) is wrapped in an additional Transaction.execute block within a multi-threaded executor context.

Changes:

  • Removed redundant Transaction.execute wrapper around updateCapacityForHost call in recalculateHostCapacities()
  • Simplified the code by calling updateCapacityForHost directly, relying on its @DB annotation for transaction management

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

Comment on lines +297 to +298
final HostVO host = hostDao.findById(hostId);
_capacityMgr.updateCapacityForHost(host);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The change correctly removes the redundant Transaction.execute wrapper. However, there's an inconsistency with recalculateStorageCapacities() (lines 313-347) which still uses Transaction.execute wrapper. For consistency and to prevent similar nested transaction issues, consider applying the same pattern if the methods called within have their own transaction management (e.g., if they use @db annotation or Transaction.execute internally).

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@RosiKyu RosiKyu left a comment

Choose a reason for hiding this comment

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

LGTM

Screencast.from.2026-01-14.16-55-55.webm

Test steps:

  1. Ran list capacity fetchlatest=true via CloudMonkey
  2. Clicked "Fetch latest" button in UI Dashboard → Storage widget
  3. Checked management server logs for RuntimeException

Results:

  • API returns capacity data successfully
  • No NO EVENT PUBLISH CAN BE WRAPPED WITHIN DB TRANSACTION exception in logs
  • Capacity values update correctly after VM start/stop operations (verified MEMORY went from 11% → 41%, CPU_CORE from 25% → 87.5% after starting VMs)

Initial State

(localcloud) 🐱 > list capacity fetchlatest=true
{
  "capacity": [
    {
      "capacityallocated": 1610612736,
      "capacitytotal": 14491254784,
      "capacityused": 1610612736,
      "name": "MEMORY",
      "percentused": "11.11",
      "type": 0,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacityallocated": 1000,
      "capacitytotal": 37600,
      "capacityused": 1000,
      "name": "CPU",
      "percentused": "2.66",
      "type": 1,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 2111479742464,
      "capacityused": 1449457090560,
      "name": "STORAGE",
      "percentused": "68.65",
      "type": 2,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 4222959484928,
      "capacityused": 10485956688,
      "name": "STORAGE_ALLOCATED",
      "percentused": "0.25",
      "type": 3,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 20,
      "capacityused": 2,
      "name": "VIRTUAL_NETWORK_PUBLIC_IP",
      "percentused": "10",
      "type": 4,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 20,
      "capacityused": 2,
      "name": "PRIVATE_IP",
      "percentused": "10",
      "type": 5,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 1055739871232,
      "capacityused": 724728545280,
      "name": "SECONDARY_STORAGE",
      "percentused": "68.65",
      "type": 6,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 20,
      "capacityused": 0,
      "name": "VLAN",
      "percentused": "0",
      "type": 7,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 0,
      "capacityused": 0,
      "name": "GPU",
      "percentused": "0",
      "type": 19,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacityallocated": 2,
      "capacitytotal": 8,
      "capacityused": 2,
      "name": "CPU_CORE",
      "percentused": "25",
      "type": 90,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    }
  ],
  "count": 10
}

After deploying VMs - recalc

(localcloud) 🐱 > list capacity fetchlatest=true
{
  "capacity": [
    {
      "capacityallocated": 5905580032,
      "capacitytotal": 14491254784,
      "capacityused": 5905580032,
      "name": "MEMORY",
      "percentused": "40.75",
      "type": 0,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacityallocated": 5000,
      "capacitytotal": 37600,
      "capacityused": 5000,
      "name": "CPU",
      "percentused": "13.3",
      "type": 1,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 2111479742464,
      "capacityused": 1457191387136,
      "name": "STORAGE",
      "percentused": "69.01",
      "type": 2,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 4222959484928,
      "capacityused": 200412823888,
      "name": "STORAGE_ALLOCATED",
      "percentused": "4.75",
      "type": 3,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 20,
      "capacityused": 3,
      "name": "VIRTUAL_NETWORK_PUBLIC_IP",
      "percentused": "15",
      "type": 4,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 20,
      "capacityused": 2,
      "name": "PRIVATE_IP",
      "percentused": "10",
      "type": 5,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 1055739871232,
      "capacityused": 728595693568,
      "name": "SECONDARY_STORAGE",
      "percentused": "69.01",
      "type": 6,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 20,
      "capacityused": 1,
      "name": "VLAN",
      "percentused": "5",
      "type": 7,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacitytotal": 0,
      "capacityused": 0,
      "name": "GPU",
      "percentused": "0",
      "type": 19,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    },
    {
      "capacityallocated": 7,
      "capacitytotal": 8,
      "capacityused": 7,
      "name": "CPU_CORE",
      "percentused": "87.5",
      "type": 90,
      "zoneid": "e0fdc65b-a0b1-4bad-ace4-0037a33b0d81",
      "zonename": "ref-trl-6148-k-Mol9-rositsa-kyuchukova"
    }
  ],
  "count": 10
}

@DaanHoogland DaanHoogland merged commit 5c1f931 into apache:4.20 Jan 14, 2026
31 of 33 checks passed
@DaanHoogland DaanHoogland deleted the reacalculate-host-capacity branch January 14, 2026 15:12
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.

listCapacity with fetchlatest parameter is causing RuntimeException

5 participants