FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Clean up primary-only snapshot DB records on volume expunge by Damans227 · Pull Request #12813 · apache/cloudstack · GitHub

Clean up primary-only snapshot DB records on volume expunge - #12813

Open
Damans227 wants to merge 6 commits into
apache:4.22from
Damans227:fix/12002-cleanup-orphaned-ceph-snapshots
Open

Clean up primary-only snapshot DB records on volume expunge#12813
Damans227 wants to merge 6 commits into
apache:4.22from
Damans227:fix/12002-cleanup-orphaned-ceph-snapshots

Conversation

Damans227 commented Mar 13, 2026
edited
Loading

Copy link
Copy Markdown
Collaborator

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

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

Tested on KVM + Ceph (RBD) with snapshot.backup.to.secondary=false:

  1. Deployed VM on Ceph, took volume snapshot, destroyed+expunged VM
  2. Verified snapshot DB records cleaned up after storage scavenger cycle
  3. Confirmed NFS snapshots (with secondary copies) are unaffected
  4. Unit tests cover: primary-only cleanup, skip when secondary exists, skip destroyed snapshots

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.

codecov Bot commented Mar 13, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 79.31034% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.68%. Comparing base (7048944) to head (28548b2).
⚠️ Report is 270 commits behind head on 4.22.

Files with missing lines Patch % Lines
...ain/java/com/cloud/storage/StorageManagerImpl.java 79.31% 3 Missing and 3 partials ⚠️
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     
Flag Coverage Δ
uitests 3.69% <ø> (-0.01%) ⬇️
unittests 18.76% <79.31%> (+0.07%) ⬆️

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

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

DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

GaOrtiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

lgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Comment on lines +2318 to +2319
snapshot.setState(Snapshot.State.Destroyed);
_snapshotDao.update(snapshot.getId(), snapshot);

Copy link
Copy Markdown
Collaborator Author

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.

Good catch @DaanHoogland fixed. Cleanup now routes through _snapshotService.deleteSnapshot(...) so the storage driver actually removes the data, and the parent snapshots row only flips to Destroyed after confirming no live store refs remain.

Copy link
Copy Markdown
Collaborator Author

@blueorangutan package

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

@blueorangutan test

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Copy link
Copy Markdown

[SF] Trillian Build Failed (tid-16129)

Copy link
Copy Markdown
Contributor

@blueorangutan test

Copy link
Copy Markdown

@vladimirpetrov a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

Copy link
Copy Markdown

[SF] Trillian test result (tid-16783)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 52714 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12813-t16783-kvm-ol8.zip
Smoke tests completed. 147 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_02_enableHumanReadableLogs Error 0.35 test_human_readable_logs.py
test_01_ssl_offloading_isolated_network Failure 716.09 test_ssl_offloading.py
test_02_ssl_offloading_project_vpc Failure 692.53 test_ssl_offloading.py

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 as Abnormal residue on rbd

7 participants


Back | FazBrowse Home | New Git URL