Skip to content

Conversation

@sureshanaparti
Copy link
Contributor

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

  • 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?

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?

@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 29.41176% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.24%. Comparing base (42f1e19) to head (77073a3).
⚠️ Report is 6 commits behind head on 4.20.

Files with missing lines Patch % Lines
...storage/datastore/db/SnapshotDataStoreDaoImpl.java 0.00% 13 Missing ⚠️
...om/cloud/storage/snapshot/SnapshotManagerImpl.java 46.66% 6 Missing and 2 partials ⚠️
.../cloud/resourcelimit/ResourceLimitManagerImpl.java 60.00% 2 Missing ⚠️
...k/api/command/user/snapshot/CreateSnapshotCmd.java 0.00% 0 Missing and 1 partial ⚠️
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           
Flag Coverage Δ
uitests 4.03% <ø> (ø)
unittests 17.09% <29.41%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a 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.

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

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

@blueorangutan
Copy link

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

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

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

Comment on lines +81 to +88
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')";
Copy link
Collaborator

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?

Suggested change
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' ";

Copy link
Collaborator

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);

Copy link
Contributor Author

@sureshanaparti sureshanaparti Jan 21, 2026

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.

@blueorangutan
Copy link

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

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.

Snapshot Size Not Counted in Primary Storage Quota

4 participants