Clean up primary-only snapshot DB records on volume expunge - #12813
Clean up primary-only snapshot DB records on volume expunge#12813Damans227 wants to merge 6 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 4.22 #12813 +/- ##
============================================
+ Coverage 17.61% 17.68% +0.07%
- Complexity 15662 15795 +133
============================================
Files 5917 5922 +5
Lines 531415 533149 +1734
Branches 64973 65208 +235
============================================
+ Hits 93588 94283 +695
- Misses 427271 428214 +943
- Partials 10556 10652 +96
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:
|
DaanHoogland
left a comment
There was a problem hiding this comment.
clgtm, but a concern remains (might be mute): Are we sure, when marking the snapshots records, there are really no data files left on primary for those?
I do not see any code ensuring that.
There was a problem hiding this comment.
Pull request overview
This PR addresses orphaned primary-only snapshot database records during volume expunge, especially for KVM + Ceph/RBD when snapshots are not backed up to secondary storage.
Changes:
- Adds snapshot cleanup before volume expunge in
StorageManagerImpl.cleanupStorage(). - Introduces helper logic to expunge primary-only snapshot store refs and mark snapshots destroyed.
- Adds unit tests for cleanup, secondary-copy skip, and destroyed-snapshot skip cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
server/src/main/java/com/cloud/storage/StorageManagerImpl.java |
Adds primary-only snapshot record cleanup during storage garbage collection. |
server/src/test/java/com/cloud/storage/StorageManagerImplTest.java |
Adds unit tests covering the new cleanup helper behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| snapshot.setState(Snapshot.State.Destroyed); | ||
| _snapshotDao.update(snapshot.getId(), snapshot); |
Good catch @DaanHoogland fixed. Cleanup now routes through |
…nd improve error handling
… limits, and removing annotations
|
@blueorangutan package |
|
@Damans227 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 17917 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian Build Failed (tid-16129) |
|
@blueorangutan test |
|
@vladimirpetrov a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-16783)
|
|
I confirmed that a primary-only snapshot (KVM+Ceph, snapshot.backup.to.secondary=false) is now cleaned up in-band. snapshot marked Destroyed, store-ref marked Destroyed, resource count decremented, RBD snapshot removed, before the volume itself is expunged. Before the fix, this same snapshot was permanently orphaned (BackedUp/Ready forever, deleteSnapshot failing). However, the method sits in the generic StorageManagerImpl.cleanupStorage(), which runs for every volume being expunged regardless of storage type, it now runs unconditionally on every volume-expunge pass rather than being gated by pool type. Could you please verify whether snapshots on primary storage are working for volumes on NFS, with snapshot.backup.to.secondary set to false? When the VM or volume has been expunged, can we still create a template, volume, or VM from its snapshot? |
Description
When
snapshot.backup.to.secondary=false(KVM + Ceph) and a VM is expunged, Ceph destroys the RBD snapshots along with the volume image, but the DB records (snapshots, snapshot_store_ref) are left behind as undeletable orphans.Fix
In
StorageManagerImpl.cleanupStorage(), clean up primary-only snapshot records before the volume is expunged from storage.Fixes: #12002
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Tested on KVM + Ceph (RBD) with
snapshot.backup.to.secondary=false:How did you try to break this feature and the system with this change?
Tested with snapshots having both primary and secondary refs, and with already-destroyed snapshots, both worked correctly skipped.