Skip to content

server: create a missing domain resource count during recalculation - #14964

Open
rootnomad wants to merge 1 commit into
apache:4.20from
rootnomad:fix/domain-tagged-resource-count-npe
Open

rootnomad wants to merge 1 commit into
apache:4.20from
rootnomad:fix/domain-tagged-resource-count-npe

Conversation

@rootnomad

Copy link
Copy Markdown
Collaborator

Description

When a domain has no count row for a tagged resource (for example volume with a storage tag) but its accounts have usage, recalculateDomainResourceCount() dereferenced the missing row. updateResourceCount failed with a NullPointerException (HTTP 530), and the periodic ResourceCountChecker failed the same way on every run, so the count never recovered. There was a TODO in the code for exactly this.

This creates the missing domain count with the recalculated value, the same way recalculateAccountResourceCount() already does for accounts.

Fixes: #14729

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):

N/A

How Has This Been Tested?

Unit tests for a missing and an existing domain count. The missing count test fails without the fix with the same NullPointerException as the issue, and passes with it.

Reproduced on a KVM lab (main, the method is the same as on 4.20): set resource.limit.storage.tags, created a volume with a disk offering carrying that tag, deleted the root domain's volume count row for the tag and ran updateResourceCount.

Before:

updateResourceCount  530  Cannot invoke "com.cloud.configuration.ResourceCountVO.setCount(long)" because "domainRC" is null
the domain volume count row for the tag is still missing

After:

updateResourceCount  OK, volume count 1 for the tag
the domain volume count row is recreated with count 1

Running it again keeps the count correct.

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

A domain with an existing count row still goes through the update path (covered by the second unit test). A domain whose recalculated count is 0 and has no row is left as it is, same as before.

recalculateDomainResourceCount() assumed the domain already has a count
row for the type and tag. When a tagged domain count is missing and the
recalculated usage is not zero, it dereferenced null, so updateResourceCount
failed with a NullPointerException and the periodic ResourceCountChecker
failed the same way on every run. Create the missing domain count with the
recalculated value, the same way recalculateAccountResourceCount() does for
accounts.

Fixes apache#14729
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 16.46%. Comparing base (5d4a376) to head (c7d6374).

Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #14964   +/-   ##
=========================================
  Coverage     16.46%   16.46%           
+ Complexity    13713    13712    -1     
=========================================
  Files          5670     5670           
  Lines        501771   501773    +2     
  Branches      60965    60966    +1     
=========================================
+ Hits          82610    82629   +19     
+ Misses       409906   409883   -23     
- Partials       9255     9261    +6     
Flag Coverage Δ
uitests 4.16% <ø> (ø)
unittests 17.33% <100.00%> (+<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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant