Skip to content

Batch resource_count UPDATEs across tags to reduce lock contention - #13915

Open
nvazquez wants to merge 3 commits into
apache:4.22from
shapeblue:422-batch-resourcecount-update-across-tags
Open

Batch resource_count UPDATEs across tags to reduce lock contention#13915
nvazquez wants to merge 3 commits into
apache:4.22from
shapeblue:422-batch-resourcecount-update-across-tags

Conversation

@nvazquez

Copy link
Copy Markdown
Contributor

Description

Concurrent restoreVirtualMachine on KVM clusters that have tagged storage limits configured (resource.limit.storage.tags) was failing at scale with MySQL "Lock wait timeout exceeded" (errcode 1205). On the worst-affected clusters the failure rate for reimage-vm reached ~43%, and >98% of failures during storm windows traced to RestoreVMCmdByAdmin bottoming out at ResourceCountDaoImpl.updateCountByDeltaForIds.

Root cause: the volume and primary_storage resource-count entry points iterated the configured tag list (the untagged sentinel plus each storage tag) and issued one UPDATE cloud.resource_count per (type, tag) pair. Each UPDATE acquired X-locks on the account row and every parent domain row for that pair, all held until the outer restoreVirtualMachine transaction committed. With multiple sequential UPDATEs per restore and concurrent callers serializing on the shared rows, the in-transaction lock-acquire chain exceeded innodb_lock_wait_timeout (50s default).

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?

ganeshmaharaj and others added 3 commits August 18, 2026 20:54
…pache#835)

Concurrent restoreVirtualMachine on KVM clusters that have tagged
storage limits configured (resource.limit.storage.tags) was failing at
scale with MySQL "Lock wait timeout exceeded" (errcode 1205). On the
worst-affected clusters the failure rate for reimage-vm reached ~43%,
and >98% of failures during storm windows traced to RestoreVMCmdByAdmin
bottoming out at ResourceCountDaoImpl.updateCountByDeltaForIds.

Root cause: the volume and primary_storage resource-count entry points
iterated the configured tag list (the untagged sentinel plus each
storage tag) and issued one UPDATE cloud.resource_count per
(type, tag) pair. Each UPDATE acquired X-locks on the account row and
every parent domain row for that pair, all held until the outer
restoreVirtualMachine transaction committed. With multiple sequential
UPDATEs per restore and concurrent callers serializing on the shared
rows, the in-transaction lock-acquire chain exceeded
innodb_lock_wait_timeout (50s default).

Fix: add removeResourceReservationIfNeededAndIncrementResourceCountForTags
and decrementResourceCountForTags helpers that resolve the union of
resource_count row IDs across the full tag list and issue a single
batched UPDATE per ResourceType. Migrate all four affected entry
points onto these helpers:

  - incrementVolumeResourceCount
  - decrementVolumeResourceCount
  - incrementVolumePrimaryStorageResourceCount
  - decrementVolumePrimaryStorageResourceCount

For an N-tag configuration this collapses 2N sequential UPDATEs to 2

Signed-off-by: Ganesh Maharaj Mahalingam <g.mahalingam@apple.com>
Co-authored-by: Ganesh Maharaj Mahalingam <g.mahalingam@apple.com>
(cherry picked from commit a8bcb52cee166e362e4ec2744a322ae2588cfe5b)
@nvazquez nvazquez added this to the 4.22.2 milestone Aug 19, 2026
@nvazquez

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez 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.

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 9.67742% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.77%. Comparing base (7fc063e) to head (eb97e4b).

Files with missing lines Patch % Lines
.../cloud/resourcelimit/ResourceLimitManagerImpl.java 9.67% 54 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #13915      +/-   ##
============================================
- Coverage     17.77%   17.77%   -0.01%     
+ Complexity    15983    15981       -2     
============================================
  Files          5928     5928              
  Lines        534301   534347      +46     
  Branches      65382    65393      +11     
============================================
- Hits          94987    94979       -8     
- Misses       428568   428622      +54     
  Partials      10746    10746              
Flag Coverage Δ
uitests 3.69% <ø> (ø)
unittests 18.85% <9.67%> (-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.

@blueorangutan

Copy link
Copy Markdown

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

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.

4 participants