lock only domains that have finite limits for checked reservation - #14169
sb-abhish3k wants to merge 2 commits into
Conversation
…itance listRowsToLockForLimitCheck previously only locked ancestor domains that owned an explicit finite resource_limit row for the exact tag, so it missed domains that inherit a finite limit from an ancestor's row, and domains that fall back to the untagged limit when no tag-specific limit is configured (per findCorrectResourceLimitForDomain). Either gap let concurrent reservations bypass domain-level serialization. Replace the set-based approximation with an in-memory walk of the account's domain chain that replicates findCorrectResourceLimitForDomain's nearest-row-with-fallback semantics, using bulk queries (covered by existing indexes) to fetch the chain's resource_limit rows and to resolve the final resource_count rows to lock.
|
@blueorangutan package |
|
@sb-abhish3k 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. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19243 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.20 #14169 +/- ##
============================================
+ Coverage 16.38% 16.39% +0.01%
- Complexity 13614 13635 +21
============================================
Files 5669 5669
Lines 501532 501619 +87
Branches 60922 60939 +17
============================================
+ Hits 82153 82242 +89
+ Misses 410172 410163 -9
- Partials 9207 9214 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@sb-abhish3k coincidentally I hit exactly that bug today when deploying VMs with terraform. On 4.22. "2026-09-15 14:02:10,066 ERROR [c.c.a.ApiServer] (qtp1816522350-51060:[ctx-a7d48c12, ctx-ca20d110, ctx-e49907f9]) (logid:a743aceb) unhandled exception executing api command: [Ljava.lang.String;@4f72b376 com.cloud.utils.exception.CloudRuntimeException: Unable to find by id on DB, due to: Deadlock found when trying to get lock; try restarting transaction |
Description
We are observing high failures from
CheckedReservationtimeouts and elsewhere seeingMySQLTransactionRollbackException: Lock wait timeout exceededfrom a similar bottleneck with quota transaction timeouts.During VM creation 5-7
CheckedReservationare constructed, which acquire aGlobalLockand go check resource limits and create/persist a reservation.During the "check resource limits" portion, in
ResourceLimitManager#checkResourceLimitWithTagwithin the context of a DB transaction which has InnoDB timeout implications, it attempts before proceeding and releasing theGlobalLockto:The issue with step 3 is that it:
a. skips the
ROOTdomain explicitly after locking it in step 1 andb. short circuits and doesn't even do the validation if the domain limits are unlimited (
-1)We are currently configuring limits at the account's domain level only, and have intermediate domain levels mapping to availability zones.
Effectively what the current unchanged code means for us is if we have thousands of concurrent requests to create a VM, even if they are segmented by accounts/domains in different zone domain hierarchies, they will all try and wait on other processes to lock on the same rows for the ROOT domain and the zone domains (configured with -1), never throwing an exception and generally bypassing the checks altogether.
It seems like an inefficiency to lock rows that will never be checked.
Fixing it should decrease the time it takes to provision a VM and reduce transaction load on the DB, especially during create surges. It seems like it could also apply to other users of CloudStack upstream.
Changes
This PR eliminates unnecessary
CheckedReservationcontention by removing quota limit checks for cases where a tagged resource limit is-1(unlimited) on a parent domain.Summary of changes:
fallbacks to listAllRowsToUpdate for finite global default and tagged-account-row create-on-miss.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?