Skip to content

Reject creating a snapshot with a duplicate name for the same volume - #14089

Open
nagaboinaramgopal wants to merge 2 commits into
apache:4.20from
nagaboinaramgopal:pr/fix-duplicate-snapshot-name
Open

nagaboinaramgopal wants to merge 2 commits into
apache:4.20from
nagaboinaramgopal:pr/fix-duplicate-snapshot-name

Conversation

@nagaboinaramgopal

@nagaboinaramgopal nagaboinaramgopal commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Description

CloudStack lets you create more than one snapshot of the same volume with the same name. Since a snapshot's name is used to build its file name on the store, two snapshots of a volume with the same name map to the same file. Creating the second overwrites the first, and later deleting either one removes the shared file and leaves the other snapshot record pointing at a file that no longer exists.

This rejects creating a snapshot when an active (non-destroyed) snapshot with the same name already exists for the volume. Auto-generated snapshot names already include a timestamp, so they are not affected.

Fixes: #13051

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

N/A

How Has This Been Tested?

Added a unit test that creates a snapshot with a name that already exists for the volume and checks it is rejected with an InvalidParameterValueException. Before this change that test fails because the create proceeds; after it, it is rejected. The existing snapshot manager tests still pass.

Also verified on a live 4.23 environment: before the change, two snapshots of the same volume with the same name both complete and end up BackedUp; after it, the second same-name snapshot is rejected while a differently named snapshot on the same volume still completes.

How did you try to break this feature and the system with this change?

The check only compares against active snapshots (not Destroyed or Error), so re-using the name of a deleted snapshot still works. Auto-generated names carry a timestamp, so scheduled and default-named snapshots are not blocked.

@DaanHoogland

Copy link
Copy Markdown
Contributor

thanks @nagaboinaramgopal makes sense, but I think it can go on branch 4.20

Two snapshots of the same volume with the same name map to the same file on the
snapshot store, so creating the second overwrites the first, and later deleting
either one removes the shared file and leaves the other snapshot pointing at
nothing. Reject creating a snapshot when an active (non-destroyed) snapshot with
the same name already exists for the volume. Auto-generated names already carry
a timestamp so they are unaffected.

Fixes: apache#13051
@nagaboinaramgopal
nagaboinaramgopal force-pushed the pr/fix-duplicate-snapshot-name branch from c0df0d6 to b229715 Compare September 9, 2026 16:50
@nagaboinaramgopal
nagaboinaramgopal changed the base branch from main to 4.20 September 9, 2026 16:50
@nagaboinaramgopal

Copy link
Copy Markdown
Contributor Author

thanks @nagaboinaramgopal makes sense, but I think it can go on branch 4.20

Thanks. Moved it to 4.20.

Comment thread server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java Outdated
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.36%. Comparing base (3a79799) to head (b229715).
⚠️ Report is 9 commits behind head on 4.20.

Files with missing lines Patch % Lines
...om/cloud/storage/snapshot/SnapshotManagerImpl.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #14089      +/-   ##
============================================
+ Coverage     16.34%   16.36%   +0.01%     
- Complexity    13576    13597      +21     
============================================
  Files          5669     5669              
  Lines        501405   501478      +73     
  Branches      60907    60915       +8     
============================================
+ Hits          81975    82071      +96     
+ Misses       410246   410219      -27     
- Partials       9184     9188       +4     
Flag Coverage Δ
uitests 4.14% <ø> (-0.01%) ⬇️
unittests 17.22% <50.00%> (+0.01%) ⬆️

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.

Query for an active snapshot with the given name on the volume instead of
listing every snapshot of the volume and comparing names, as asked in review.
@nagaboinaramgopal

Copy link
Copy Markdown
Contributor Author

@DaanHoogland @sureshanaparti I've also verified on a live 4.23 KVM environment (NFS primary storage), creating snapshots of the same ROOT volume through the API.

Before the change, both snapshots with the same name are accepted and end up BackedUp:

20:46:48 GET command=createSnapshot&volumeid=79f03a4d-...&name=dup14089  HTTP/1.1 200 {"createsnapshotresponse":{"id":"f9df84d7-...
20:46:51 Complete async job-1519, jobStatus: SUCCEEDED ... SnapshotResponse/snapshot/{"id":"f9df84d7-20ab-48e5-a843-b5c45e16ca5e", ...
20:46:54 GET command=createSnapshot&volumeid=79f03a4d-...&name=dup14089  HTTP/1.1 200 {"createsnapshotresponse":{"id":"999155e6-...
20:46:55 Complete async job-1521, jobStatus: SUCCEEDED ... SnapshotResponse/snapshot/{"id":"999155e6-f9a4-4879-88fc-feb42a620678", ...

With the change, the second one is rejected, a different name still works, and the name can be reused once the first snapshot is deleted:

20:49:36 GET command=createSnapshot&volumeid=79f03a4d-...&name=dup14089    HTTP/1.1 200 {"createsnapshotresponse":{"id":"90e59767-...
20:49:38 Complete async job-1525, jobStatus: SUCCEEDED
20:49:41 GET command=createSnapshot&volumeid=79f03a4d-...&name=dup14089    HTTP/1.1 431 A snapshot with name [dup14089] already exists for volume ...
20:49:41 GET command=createSnapshot&volumeid=79f03a4d-...&name=other14089  HTTP/1.1 200 {"createsnapshotresponse":{"id":"7193286b-...
20:49:42 Complete async job-1527, jobStatus: SUCCEEDED
20:49:47 GET command=deleteSnapshot&id=90e59767-7aaa-470d-9077-26920547b523  HTTP/1.1 200
20:49:52 GET command=createSnapshot&volumeid=79f03a4d-...&name=dup14089    HTTP/1.1 200 {"createsnapshotresponse":{"id":"d531ec5b-...
20:49:54 Complete async job-1530, jobStatus: SUCCEEDED

No SQL errors or exceptions in the management server log during the run.

@nagaboinaramgopal

Copy link
Copy Markdown
Contributor Author

@sureshanaparti updated as suggested: the duplicate-name check now looks up by volume and snapshot name (ca6075e), verified on a live KVM environment. Could you take another look?

This branch has not been deployed

No deployments
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.

Cloudstack allows you to create snapshots with the same name for the same volume

3 participants