abh1sar opened a new pull request, #11522:
URL: https://github.com/apache/cloudstack/pull/11522
### Description
- Due to a bug in UsageBackupDaoImpl.removeUsage, entry in the
`cloud_usage.backup_usage` doesn't get removed even after all the backups have
been deleted and backup offering removed.
- Backup usage doesn't get updated to 0 size when all backups are deleted.
<!--- 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
- [ ] test (unit or integration test code)
### Feature/Enhancement Scale or Bug Severity
#### Feature/Enhancement Scale
- [ ] Major
- [ ] Minor
#### Bug Severity
- [ ] BLOCKER
- [x] Critical
- [ ] Major
- [ ] Minor
- [ ] Trivial
### Screenshots (if appropriate):
### How Has This Been Tested?
Before Fix:
```
10:03:37.297 [Usage-Job-1] ERROR
com.cloud.usage.dao.UsageBackupDaoImpl_EnhancerByCloudStack_c6b7eb21 -
Exception caught while removing UsageBackupVO: Remove backup usage exception:
No value specified for parameter 4
com.cloud.exception.CloudException: Remove backup usage exception: No value
specified for parameter 4
at
com.cloud.usage.dao.UsageBackupDaoImpl.removeUsage(UsageBackupDaoImpl.java:76)
~[cloud-engine-schema-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
com.cloud.usage.dao.UsageBackupDaoImpl_EnhancerByCloudStack_c6b7eb21.CGLIB$removeUsage$0(<generated>)
~[cloud-engine-schema-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
com.cloud.usage.dao.UsageBackupDaoImpl_EnhancerByCloudStack_c6b7eb21_FastClassByCloudStack_515fb514.invoke(<generated>)
~[cloud-engine-schema-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
~[cglib-nodep-3.3.0.jar:?]
at
com.cloud.utils.component.ComponentInstantiationPostProcessor$InterceptorDispatcher.intercept(ComponentInstantiationPostProcessor.java:123)
~[cloud-utils-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
com.cloud.usage.dao.UsageBackupDaoImpl_EnhancerByCloudStack_c6b7eb21.removeUsage(<generated>)
~[cloud-engine-schema-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
com.cloud.usage.UsageManagerImpl.createBackupEvent(UsageManagerImpl.java:2077)
~[classes/:?]
at
com.cloud.usage.UsageManagerImpl.createHelperRecord(UsageManagerImpl.java:986)
~[classes/:?]
at com.cloud.usage.UsageManagerImpl.parse(UsageManagerImpl.java:716)
~[classes/:?]
at
com.cloud.usage.UsageManagerImpl.runInContextInternal(UsageManagerImpl.java:432)
~[classes/:?]
at
com.cloud.usage.UsageManagerImpl$1.runInContext(UsageManagerImpl.java:369)
~[classes/:?]
at
org.apache.cloudstack.managed.context.ManagedContextRunnable$1.run(ManagedContextRunnable.java:49)
~[cloud-framework-managed-context-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:56)
~[cloud-framework-managed-context-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:103)
~[cloud-framework-managed-context-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:53)
~[cloud-framework-managed-context-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at
org.apache.cloudstack.managed.context.ManagedContextRunnable.run(ManagedContextRunnable.java:46)
~[cloud-framework-managed-context-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
at com.cloud.usage.UsageManagerImpl.run(UsageManagerImpl.java:371)
~[classes/:?]
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
~[?:?]
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
~[?:?]
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
~[?:?]
at java.lang.Thread.run(Thread.java:829) ~[?:?]
Caused by: java.sql.SQLException: No value specified for parameter 4
at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:555)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:339)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994)
~[mysql-connector-j-8.0.33.jar:8.0.33]
at
com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
~[HikariCP-5.1.0.jar:?]
at
com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
~[HikariCP-5.1.0.jar:?]
at
com.cloud.usage.dao.UsageBackupDaoImpl.removeUsage(UsageBackupDaoImpl.java:72)
~[cloud-engine-schema-4.21.0.0-SNAPSHOT.jar:4.21.0.0-SNAPSHOT]
```
After Fix:
1. Created two backups for a vm (id=8) with a backup_offering (id=1)
(Ignore usage_backup id 20 as it from a previous testing)
<img width="1162" height="172" alt="Screenshot 2025-08-27 at 10 37 00 AM"
src="https://github.com/user-attachments/assets/83e3dd3a-648d-4189-9635-1bc5656ff573"
/>
2. Deleted one backup
<img width="1162" height="172" alt="Screenshot 2025-08-27 at 10 37 40 AM"
src="https://github.com/user-attachments/assets/eb291e4d-0bb9-4a44-bb92-02ac49640ea9"
/>
3. Deleted another backup
<img width="1162" height="172" alt="Screenshot 2025-08-27 at 10 37 58 AM"
src="https://github.com/user-attachments/assets/94a9e134-bb0d-46ed-905b-5fbaec29ce6d"
/>
4. Removed backup offering
<img width="1162" height="172" alt="Screenshot 2025-08-27 at 10 38 25 AM"
src="https://github.com/user-attachments/assets/e2a78f64-bf8a-4334-8b0f-a8a48fd71f18"
/>
<!-- Please describe in detail how you tested your changes. -->
<!-- Include details of your testing environment, and the tests you ran to
-->
#### 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]