-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update the snapshot physical size for the primary storage resource after snapshot creation and during resource count recalculation #12481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.20
Are you sure you want to change the base?
Conversation
…creation and during resource count recalculation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.20 #12481 +/- ##
=========================================
Coverage 16.23% 16.24%
- Complexity 13380 13394 +14
=========================================
Files 5657 5657
Lines 499039 499128 +89
Branches 60567 60577 +10
=========================================
+ Hits 81024 81074 +50
- Misses 408978 409017 +39
Partials 9037 9037
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an issue where snapshot physical size for primary storage resources was not being properly tracked during snapshot creation and resource count recalculation. The changes ensure that snapshots stored on primary storage are correctly accounted for in resource limits.
Changes:
- Added a new DAO method to calculate the total physical size of snapshots on primary storage for an account
- Updated resource count calculation to include snapshot sizes on primary storage
- Refactored snapshot resource type determination logic to use a common helper method
- Fixed resource cleanup in error scenarios to use the correct storage resource type
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| SnapshotDataStoreDao.java | Added interface method to get snapshots physical size on primary storage by account ID |
| SnapshotDataStoreDaoImpl.java | Implemented SQL query to calculate total physical size of snapshots on primary storage, excluding those backed up to secondary storage |
| ResourceLimitManagerImpl.java | Updated primary storage calculation to include snapshot sizes; fixed spelling error in log message |
| SnapshotManagerImpl.java | Added helper method getStoreResourceType() and updated resource cleanup logic to use correct resource type in success and failure paths |
| ResourceLimitManagerImplTest.java | Updated test expectations to include snapshot sizes in primary storage calculations |
| CreateSnapshotCmd.java | Removed redundant null check on enum values() method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...chema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java
Show resolved
Hide resolved
api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java
Outdated
Show resolved
Hide resolved
...chema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java
Show resolved
Hide resolved
...ne/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java
Show resolved
Hide resolved
...chema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java
Show resolved
Hide resolved
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
Show resolved
Hide resolved
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
Show resolved
Hide resolved
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java
Show resolved
Hide resolved
|
@blueorangutan package |
|
@sureshanaparti 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. |
...chema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java
Outdated
Show resolved
Hide resolved
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16457 |
|
@blueorangutan package |
|
@sureshanaparti 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. |
| private static final String GET_PHYSICAL_SIZE_OF_SNAPSHOTS_ON_PRIMARY_BY_ACCOUNT = "SELECT SUM(s.physical_size) " + | ||
| "FROM cloud.snapshot_store_ref s " + | ||
| "LEFT JOIN cloud.snapshots ON s.snapshot_id = snapshots.id " + | ||
| "WHERE snapshots.account_id = ? " + | ||
| "AND snapshots.removed IS NULL " + | ||
| "AND s.state = 'Ready' " + | ||
| "AND s.store_role = 'Primary' " + | ||
| "AND NOT EXISTS (SELECT 1 FROM cloud.snapshot_store_ref i WHERE i.snapshot_id = s.snapshot_id AND i.store_role = 'Image')"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we include the size of the snapshot in primary which is present on secondary as well?
| private static final String GET_PHYSICAL_SIZE_OF_SNAPSHOTS_ON_PRIMARY_BY_ACCOUNT = "SELECT SUM(s.physical_size) " + | |
| "FROM cloud.snapshot_store_ref s " + | |
| "LEFT JOIN cloud.snapshots ON s.snapshot_id = snapshots.id " + | |
| "WHERE snapshots.account_id = ? " + | |
| "AND snapshots.removed IS NULL " + | |
| "AND s.state = 'Ready' " + | |
| "AND s.store_role = 'Primary' " + | |
| "AND NOT EXISTS (SELECT 1 FROM cloud.snapshot_store_ref i WHERE i.snapshot_id = s.snapshot_id AND i.store_role = 'Image')"; | |
| private static final String GET_PHYSICAL_SIZE_OF_SNAPSHOTS_ON_PRIMARY_BY_ACCOUNT = "SELECT SUM(s.physical_size) " + | |
| "FROM cloud.snapshot_store_ref s " + | |
| "LEFT JOIN cloud.snapshots ON s.snapshot_id = snapshots.id " + | |
| "WHERE snapshots.account_id = ? " + | |
| "AND snapshots.removed IS NULL " + | |
| "AND s.state = 'Ready' " + | |
| "AND s.store_role = 'Primary' "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, if we are going this way we can just use snapshotSizeSearch in ResourceLimitManagerImpl directly similar to calculateSecondaryStorageForAccount()
SearchCriteria<SumCount> sc2 = snapshotSizeSearch.create();
sc2.setParameters("state", ObjectInDataStoreStateMachine.State.Ready);
sc2.setParameters("storeRole", DataStoreRole.Primary);
sc2.setJoinParameters("snapshots", "accountId", accountId);
List<SumCount> snapshots = _snapshotDataStoreDao.customSearch(sc2, null);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we include the size of the snapshot in primary which is present on secondary as well?
@abh1sar no, the snapshots in primary are deleted when they are backed up on secondary, but the store_ref record still exists (with 'Ready' state as I noticed - this record needs to removed or state should be updated to 'Destroyed'. Also, location_type column in snapshots table is not populated, which should indicate location of the snapshot - 'Primary' or 'Image'. - these need more testing and can break any existing func, so I'll raise separate PR with these fixes/improvements).
the sql would consider the snapshots in primary and not exists in secondary storage.
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16466 |
Description
This PR updates the snapshot physical size for the primary storage resource after snapshot creation and during resource count recalculation.
The snapshot size incremented for the primary storage resource in the resource count while allocating snapshot (here: #11558), is reverted during resource count recalculation for primary storage resource. Also, post snapshot creation, the decrement resource count not performed for primary storage resource when snapshot created on primary.
Fixes #11441
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Created snapshots with user, admin accounts for some volumes and checked the resource count of 'primary_storage' resource.
How did you try to break this feature and the system with this change?