sureshanaparti opened a new pull request, #8555:
URL: https://github.com/apache/cloudstack/pull/8555
### Description
restoreVirtualMachine resulted in two ROOT disks due to resource count
increment error. Resource count increment is performed after ROOT volume is
duplicated/allocated, and the failure here leaves VM with two ROOT volumes, and
there is no cleanup of it after that.
This PR allocates new ROOT volume (on restore virtual machine operation)
only when resource count increment succeeds.
Log:
```
2023-12-07 20:15:01,460 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl]
(API-Job-Executor-18:ctx-6b2d5fb9 job-5403241 ctx-f3e2e390) (logid:4e54320f)
Sync job-5403242 execution on object VmWorkJobQueue.525393
2023-12-07 20:15:02,198 INFO [o.a.c.f.j.i.AsyncJobMonitor]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242) (logid:3d510e9e)
Add job-5403242 into job monitoring
2023-12-07 20:15:02,202 DEBUG [o.a.c.f.j.i.AsyncJobManagerImpl]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242) (logid:4e54320f)
Executing AsyncJobVO: {id:5403242, userId: 2, accountId: 2, instanceType: null,
instanceId: null, cmd: com.cloud.vm.VmWorkRestore, cmdInfo:
rO0ABXNyABpjb20uY2xvdWQudm0uVm1Xb3JrUmVzdG9yZQK3-6IUa1sTAgABTAAKdGVtcGxhdGVJZHQAEExqYXZhL2xhbmcvTG9uZzt4cgATY29tLmNsb3VkLnZtLlZtV29ya5-ZtlbwJWdrAgAESgAJYWNjb3VudElkSgAGdXNlcklkSgAEdm1JZEwAC2hhbmRsZXJOYW1ldAASTGphdmEvbGFuZy9TdHJpbmc7eHAAAAAAAAAAAgAAAAAAAAACAAAAAAAIBFF0ABlWaXJ0dWFsTWFjaGluZU1hbmFnZXJJbXBsc3IADmphdmEubGFuZy5Mb25nO4vkkMyPI98CAAFKAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAAAAAVt,
cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result:
null, initMsid: 9624671580934, completeMsid: null, lastUpdated: null,
lastPolled: null, created: Thu Dec 07 20:15:01 UTC 2023, removed: null}
2023-12-07 20:15:02,203 DEBUG [c.c.v.VmWorkJobDispatcher]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242) (logid:4e54320f)
Run VM work job: com.cloud.vm.VmWorkRestore for VM 525393, job origin: 5403241
2023-12-07 20:15:02,204 DEBUG [c.c.v.VmWorkJobHandlerProxy]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Execute VM work job:
com.cloud.vm.VmWorkRestore{"templateId":1389,"userId":2,"accountId":2,"vmId":525393,"handlerName":"VirtualMachineManagerImpl"}
2023-12-07 20:15:02,206 DEBUG [c.c.v.VirtualMachineManagerImpl]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Restoring vm 525393 with new templateId 1389
2023-12-07 20:15:02,224 INFO [c.c.v.UserVmManagerImpl]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) VM cannot be configured to be dynamically scalable if any of
the service offering's dynamic scaling property, template's dynamic scaling
property or global setting is false
2023-12-07 20:15:02,229 DEBUG [c.c.r.ResourceLimitManagerImpl]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Updating resource Type = volume count for Account = 3203
Operation = increasing Amount = 1
2023-12-07 20:15:02,236 DEBUG [c.c.r.ResourceLimitManagerImpl]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Updating resource Type = primary_storage count for Account =
3203 Operation = increasing Amount = (30.00 GB) 32212254720
2023-12-07 20:16:02,505 DEBUG [c.c.u.d.T.Transaction]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Rolling back the transaction: Time = 60269 Name =
Work-Job-Executor-103; called by
-TransactionLegacy.rollback:888-TransactionLegacy.removeUpTo:831-TransactionLegacy.close:655-Transaction.execute:38-Transaction.execute:47-ResourceLimitManagerImpl.updateResourceCountForAccount:872-ResourceLimitManagerImpl$1.doInTransactionWithoutResult:185-TransactionCallbackWithExceptionNoReturn.doInTransaction:25-TransactionCallbackWithExceptionNoReturn.doInTransaction:21-Transaction.execute:40-ResourceLimitManagerImpl.removeResourceReservationIfNeededAndIncrementResourceCount:177-ResourceLimitManagerImpl.incrementResourceCount:291
2023-12-07 20:16:02,506 ERROR [c.c.r.ResourceLimitManagerImpl]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Failed to update resource count for account id=3203
2023-12-07 20:16:02,506 ERROR [c.c.v.VmWorkJobHandlerProxy]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Invocation exception, caused by:
com.cloud.utils.exception.CloudRuntimeException: Failed to increment resource
count of type primary_storage for account id=3203
2023-12-07 20:16:02,506 INFO [c.c.v.VmWorkJobHandlerProxy]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242 ctx-a27ad837)
(logid:4e54320f) Rethrow exception
com.cloud.utils.exception.CloudRuntimeException: Failed to increment resource
count of type primary_storage for account id=3203
2023-12-07 20:16:02,506 DEBUG [c.c.v.VmWorkJobDispatcher]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242) (logid:4e54320f)
Done with run of VM work job: com.cloud.vm.VmWorkRestore for VM 525393, job
origin: 5403241
2023-12-07 20:16:02,506 ERROR [c.c.v.VmWorkJobDispatcher]
(Work-Job-Executor-103:ctx-755903a6 job-5403241/job-5403242) (logid:4e54320f)
Unable to complete AsyncJobVO: {id:5403242, userId: 2, accountId: 2,
instanceType: null, instanceId: null, cmd: com.cloud.vm.VmWorkRestore, cmdInfo:
rO0ABXNyABpjb20uY2xvdWQudm0uVm1Xb3JrUmVzdG9yZQK3-6IUa1sTAgABTAAKdGVtcGxhdGVJZHQAEExqYXZhL2xhbmcvTG9uZzt4cgATY29tLmNsb3VkLnZtLlZtV29ya5-ZtlbwJWdrAgAESgAJYWNjb3VudElkSgAGdXNlcklkSgAEdm1JZEwAC2hhbmRsZXJOYW1ldAASTGphdmEvbGFuZy9TdHJpbmc7eHAAAAAAAAAAAgAAAAAAAAACAAAAAAAIBFF0ABlWaXJ0dWFsTWFjaGluZU1hbmFnZXJJbXBsc3IADmphdmEubGFuZy5Mb25nO4vkkMyPI98CAAFKAAV2YWx1ZXhyABBqYXZhLmxhbmcuTnVtYmVyhqyVHQuU4IsCAAB4cAAAAAAAAAVt,
cmdVersion: 0, status: IN_PROGRESS, processStatus: 0, resultCode: 0, result:
null, initMsid: 9624671580934, completeMsid: null, lastUpdated: null,
lastPolled: null, created: Thu Dec 07 20:15:01 UTC 2023, removed: null}, job
origin:5403241
```
<!--- Describe your changes in DETAIL - And how has behaviour functionally
changed. -->
<!-- For new features, provide link to FS, dev ML discussion etc. -->
<!-- In case of bug fix, the expected and actual behaviours, steps to
reproduce. -->
<!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be
closed when this PR gets merged -->
<!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" -->
<!-- Fixes: # -->
<!---
*******************************************************************************
-->
<!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE
DOCUMENTATION. -->
<!--- PLEASE PUT AN 'X' in only **ONE** box -->
<!---
*******************************************************************************
-->
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [x] 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
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [ ] Major
- [ ] Minor
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [x] Major
- [ ] Minor
- [ ] Trivial
### Screenshots (if appropriate):
### How Has This Been Tested?
<!-- Please describe in detail how you tested your changes. -->
<!-- Include details of your testing environment, and the tests you ran to
-->
It's a rare case/difficult to reproduce, to test
Manually tested restore operation for stopped / running VMs, by adding an
exception (at line#192 in ResourceLimitManagerImpl, for testing) in the
resource increment call. Didn't notice multiple ROOT disks for the VM.
https://github.com/apache/cloudstack/blob/19250403e645c76f60b17aa4aeb4dc915f5ca206/server/src/main/java/com/cloud/resourcelimit/ResourceLimitManagerImpl.java#L192-L195
#### How did you try to break this feature and the system with this change?
<!-- see how your change affects other areas of the code, etc. -->
<!-- Please read the
[CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
document -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]