Skip to content

Conversation

@sureshanaparti
Copy link
Contributor

@sureshanaparti sureshanaparti commented Dec 29, 2025

Description

This PR addresses cleanup of the snapshot files in datastores for Error-ed snapshots, and has some code improvements.

The removed date is set for the snapshot records after backup failed [1], and the storage garbage collector ignores cleaning up the files as getSnapshot [2] always returns null, leaving the orphaned snapshot files in the primary storage and error records in snapshots and snapshot_store_ref tables.

[1] https://github.com/apache/cloudstack/blob/4.20/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java#L408

https://github.com/apache/cloudstack/blob/4.20/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java#L719

[2] https://github.com/apache/cloudstack/blob/4.20/server/src/main/java/com/cloud/storage/StorageManagerImpl.java#L1889

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?

Failed snapshots after created in primary (before copy to secondary storage) by adding the below code, and verified the cleanup before and after changes.

diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
index 0b0065361d0..66ad50270a8 100644
--- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
@@ -606,6 +606,10 @@ public class AncientDataMotionStrategy implements DataMotionStrategy {
 
         Answer answer = null;
         try {
+            if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.SNAPSHOT) {
+                throw new CloudRuntimeException("*** FAIL COPY SNAPSHOT ***");
+            }
+
             if (needCacheStorage(srcData, destData)) {
                 Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
                 cacheData = cacheMgr.getCacheObject(srcData, selectedScope);

BEFORE CHANGES:

Logs:

[root@mgmt1 ~]# grep "copy snasphot failed" /var/log/cloudstack/management/management-server.log
2025-12-29 07:55:33,741 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-1:[ctx-e1e63336, job-383/job-384, ctx-d5307dd2]) (logid:eee170fc) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 07:56:40,862 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-2:[ctx-23052f31, job-385/job-386, ctx-2ae57c30]) (logid:c8826374) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 08:48:46,174 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-3:[ctx-62f08aef, job-387/job-388, ctx-8d527b2a]) (logid:9ffd7643) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 09:48:43,056 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-4:[ctx-4148adbb, job-389/job-390, ctx-ed1dc303]) (logid:e2a3192f) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 10:48:41,956 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-5:[ctx-844b61a8, job-391/job-392, ctx-7a894e61]) (logid:8ad0e711) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 11:35:25,124 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-1:[ctx-5585d9a9, job-395/job-396, ctx-be6b1bff]) (logid:4d367e53) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 11:48:49,195 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-2:[ctx-0ae9bdea, job-397/job-398, ctx-5d0cbc49]) (logid:ed5b9de8) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 12:48:47,689 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-3:[ctx-deaf5254, job-399/job-400, ctx-c48773b2]) (logid:03ac9fda) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***
2025-12-29 12:48:58,623 DEBUG [o.a.c.s.m.AncientDataMotionStrategy] (Work-Job-Executor-4:[ctx-be293b7e, job-401/job-402, ctx-6d3ce524]) (logid:fdc87173) copy snasphot failed: com.cloud.utils.exception.CloudRuntimeException: *** FAIL COPY SNAPSHOT ***

DB:

mysql> SELECT id, uuid, name, volume_id, status, path, snapshot_type, type_description, size, created, removed FROM cloud.snapshots WHERE status = 'Error';
+-----+--------------------------------------+--------------------------------+-----------+--------+------+---------------+------------------+------------+---------------------+---------------------+
| id  | uuid                                 | name                           | volume_id | status | path | snapshot_type | type_description | size       | created             | removed             |
+-----+--------------------------------------+--------------------------------+-----------+--------+------+---------------+------------------+------------+---------------------+---------------------+
| 127 | e7c5ec0e-a179-4ed5-a1bf-cd4cf1d03f5d | ROOT-3-Snap04_ERROR            |         3 | Error  | NULL |             0 | MANUAL           | 8589934592 | 2025-12-29 07:55:21 | 2025-12-29 07:55:33 |
| 128 | 350a90af-d0f4-4474-b10b-befac336cbd3 | ROOT-3-Snap05_ERROR            |         3 | Error  | NULL |             0 | MANUAL           | 8589934592 | 2025-12-29 07:56:30 | 2025-12-29 07:56:40 |
| 129 | 8a07c40f-d09d-4ced-b959-382ac6cc93ca | testvm01_ROOT-3_20251229084828 |         3 | Error  | NULL |             3 | HOURLY           | 8589934592 | 2025-12-29 08:48:28 | 2025-12-29 08:48:46 |
| 130 | d84186e6-3e26-432b-95d0-67f6883cea6a | testvm01_ROOT-3_20251229094828 |         3 | Error  | NULL |             3 | HOURLY           | 8589934592 | 2025-12-29 09:48:28 | 2025-12-29 09:48:43 |
| 131 | b586c299-d46f-4599-ae60-6852c3e913b1 | testvm01_ROOT-3_20251229104828 |         3 | Error  | NULL |             3 | HOURLY           | 8589934592 | 2025-12-29 10:48:28 | 2025-12-29 10:48:41 |
| 132 | e068e33d-4139-4a21-bdd3-a1e1a7423c57 | ROOT-3-Snap06_ERROR            |         3 | Error  | NULL |             0 | MANUAL           | 8589934592 | 2025-12-29 11:35:10 | 2025-12-29 11:35:25 |
| 133 | 921ac9cb-ab3e-4d29-9b67-d31a0bcb313a | testvm01_ROOT-3_20251229114834 |         3 | Error  | NULL |             3 | HOURLY           | 8589934592 | 2025-12-29 11:48:34 | 2025-12-29 11:48:49 |
| 134 | fc462ef5-48b5-46d8-8d2c-301db0653d5e | testvm01_ROOT-3_20251229124834 |         3 | Error  | NULL |             3 | HOURLY           | 8589934592 | 2025-12-29 12:48:34 | 2025-12-29 12:48:47 |
| 135 | 3e575604-2d32-4a3e-802e-e0209267c508 | testvm01_ROOT-3_20251229124834 |         3 | Error  | NULL |             4 | DAILY            | 8589934592 | 2025-12-29 12:48:34 | 2025-12-29 12:48:58 |
+-----+--------------------------------------+--------------------------------+-----------+--------+------+---------------+------------------+------------+---------------------+---------------------+
9 rows in set (0.00 sec)

mysql> SELECT id, snapshot_id, store_id, store_role, size, physical_size, install_path, local_path, state, volume_id, download_state, download_pct, error_str, created, last_updated FROM cloud.snapshot_store_ref WHERE snapshot_id IN (SELECT id FROM cloud.snapshots WHERE status = 'Error');
+-----+-------------+----------+------------+------------+---------------+------------------------------------------------------------------------------------------+------------+-----------+-----------+----------------+--------------+-----------+---------------------+--------------+
| id  | snapshot_id | store_id | store_role | size       | physical_size | install_path                                                                             | local_path | state     | volume_id | download_state | download_pct | error_str | created             | last_updated |
+-----+-------------+----------+------------+------------+---------------+------------------------------------------------------------------------------------------+------------+-----------+-----------+----------------+--------------+-----------+---------------------+--------------+
| 253 |         127 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/ac022550-1d39-4e01-8b10-d18634abbc71 | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 07:55:22 | NULL         |
| 255 |         128 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/b5b8e306-c015-4c21-b9da-7abf0536797f | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 07:56:30 | NULL         |
| 257 |         129 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/649c946a-7520-4838-945e-e229e4fd187b | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 08:48:30 | NULL         |
| 259 |         130 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/ce440897-bf02-450e-914e-3ed4f4b5c05d | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 09:48:30 | NULL         |
| 261 |         131 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/81f9ee83-9de3-4a75-9082-9e27fe844151 | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 10:48:30 | NULL         |
| 263 |         132 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/8638a61a-ca2a-46ca-a166-8ae16275ec6a | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 11:35:11 | NULL         |
| 265 |         133 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/705ddb09-0f23-411a-a529-50545440fe28 | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 11:48:35 | NULL         |
| 267 |         134 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/81ff1ba0-08ab-4ea3-9206-fde27b5ce53d | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 12:48:35 | NULL         |
| 269 |         135 |        1 | Primary    | 8589934592 |    8589934592 | /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/4e402bf0-1e47-4e23-bb5e-c20da9c94135 | NULL       | Destroyed |         3 | NULL           |            0 | NULL      | 2025-12-29 12:48:47 | NULL         |
+-----+-------------+----------+------------+------------+---------------+------------------------------------------------------------------------------------------+------------+-----------+-----------+----------------+--------------+-----------+---------------------+--------------+
9 rows in set (0.00 sec)

Files in Primary Storage:

[root@kvm1 ~]# ls -lrt /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/
total 14611728
-rw-r--r--. 1 root root 1659240448 Dec 29 07:55 ac022550-1d39-4e01-8b10-d18634abbc71
-rw-r--r--. 1 root root 1659240448 Dec 29 07:56 b5b8e306-c015-4c21-b9da-7abf0536797f
-rw-r--r--. 1 root root 1659240448 Dec 29 08:48 649c946a-7520-4838-945e-e229e4fd187b
-rw-r--r--. 1 root root 1659240448 Dec 29 09:48 ce440897-bf02-450e-914e-3ed4f4b5c05d
-rw-r--r--. 1 root root 1659240448 Dec 29 10:48 81f9ee83-9de3-4a75-9082-9e27fe844151
-rw-r--r--. 1 root root 1659240448 Dec 29 11:35 8638a61a-ca2a-46ca-a166-8ae16275ec6a
-rw-r--r--. 1 root root 1659240448 Dec 29 11:48 705ddb09-0f23-411a-a529-50545440fe28
-rw-r--r--. 1 root root 1659240448 Dec 29 12:48 81ff1ba0-08ab-4ea3-9206-fde27b5ce53d
-rw-r--r--. 1 root root 1659240448 Dec 29 12:48 4e402bf0-1e47-4e23-bb5e-c20da9c94135

AFTER CHANGES:

Logs:

[root@mgmt1 ~]# grep "state found on" /var/log/cloudstack/management/management-server.log
2025-12-29 13:40:28,262 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [e7c5ec0e-a179-4ed5-a1bf-cd4cf1d03f5d] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:28,467 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [350a90af-d0f4-4474-b10b-befac336cbd3] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:28,607 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [8a07c40f-d09d-4ced-b959-382ac6cc93ca] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:28,752 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [d84186e6-3e26-432b-95d0-67f6883cea6a] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:28,942 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [b586c299-d46f-4599-ae60-6852c3e913b1] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:29,094 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [e068e33d-4139-4a21-bdd3-a1e1a7423c57] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:29,271 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [921ac9cb-ab3e-4d29-9b67-d31a0bcb313a] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:29,482 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [fc462ef5-48b5-46d8-8d2c-301db0653d5e] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.
2025-12-29 13:40:29,760 DEBUG [c.c.s.StorageManagerImpl] (StorageManager-Scavenger-1:[ctx-40654b77]) (logid:09807cbb) Snapshot [3e575604-2d32-4a3e-802e-e0209267c508] in Destroyed state found on primary data store [4d215758-18a9-335e-8c9d-ecb4d19c9d94]; therefore, it will be destroyed.

DB:

mysql> SELECT id, uuid, name, volume_id, status, path, snapshot_type, type_description, size, created, removed FROM cloud.snapshots WHERE status = 'Error';
Empty set (0.00 sec)

mysql> SELECT id, snapshot_id, store_id, store_role, size, physical_size, install_path, local_path, state, volume_id, download_state, download_pct, error_str, created, last_updated FROM cloud.snapshot_store_ref WHERE snapshot_id IN (SELECT id FROM cloud.snapshots WHERE status = 'Error');
Empty set (0.00 sec)

Files in Primary Storage:

[root@kvm1 ~]# ls -lrt /mnt/4d215758-18a9-335e-8c9d-ecb4d19c9d94/snapshots/
total 0

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

@sureshanaparti sureshanaparti changed the title Cleanup snapshots in datastores for Error-ed snapshots, and some code improvements Cleanup snapshot files in datastores for Error-ed snapshots, and some code improvements Dec 29, 2025
@codecov
Copy link

codecov bot commented Dec 29, 2025

Codecov Report

❌ Patch coverage is 2.06186% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.23%. Comparing base (56a39e6) to head (7efe8fb).

Files with missing lines Patch % Lines
...ain/java/com/cloud/storage/StorageManagerImpl.java 0.00% 49 Missing ⚠️
...tack/storage/snapshot/SnapshotDataFactoryImpl.java 0.00% 14 Missing ⚠️
...om/cloud/storage/snapshot/SnapshotManagerImpl.java 7.14% 13 Missing ⚠️
...in/java/com/cloud/storage/dao/SnapshotDaoImpl.java 0.00% 5 Missing ⚠️
...storage/datastore/db/SnapshotDataStoreDaoImpl.java 0.00% 5 Missing ⚠️
...torage/datastore/ObjectInDataStoreManagerImpl.java 0.00% 3 Missing ⚠️
...oudstack/storage/snapshot/SnapshotServiceImpl.java 0.00% 2 Missing ⚠️
...ack/storage/snapshot/StorPoolSnapshotStrategy.java 0.00% 2 Missing ⚠️
...tack/storage/snapshot/DefaultSnapshotStrategy.java 50.00% 1 Missing ⚠️
...udstack/storage/datastore/util/StorPoolHelper.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #12347      +/-   ##
============================================
- Coverage     16.23%   16.23%   -0.01%     
+ Complexity    13378    13377       -1     
============================================
  Files          5657     5657              
  Lines        498866   498898      +32     
  Branches      60545    60545              
============================================
  Hits          81011    81011              
- Misses       408821   408854      +33     
+ Partials       9034     9033       -1     
Flag Coverage Δ
uitests 4.00% <ø> (ø)
unittests 17.09% <2.06%> (-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 addresses the cleanup of orphaned snapshot files in datastores when snapshots fail and enter Error state. Previously, when snapshots failed during backup to secondary storage, the removed date was set for snapshot records, causing the storage garbage collector to skip cleanup since getSnapshot() always returned null for removed snapshots. This left orphaned files in primary storage and error records in the database tables.

Key changes include:

  • Added cleanup logic for snapshots in Error state including those marked as removed
  • Introduced new DAO methods to handle removed snapshots and filter by state
  • Added state transitions to handle Destroyed state more gracefully
  • Refactored variable names for clarity and extracted methods to reduce duplication

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
server/src/main/java/com/cloud/storage/StorageManagerImpl.java Refactored snapshot cleanup logic into separate methods, added support for cleaning up error-ed snapshots including removed ones, and now uses getSnapshotIncludingRemoved for cleanup operations
engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java Added getSnapshotIncludingRemoved method and extracted common logic into getSnapshotOnStore helper method
engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java Modified findBySnapshotId to return all references regardless of state, added findBySnapshotIdWithNonDestroyedState to filter out destroyed state references
engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java Added interface method findBySnapshotIdWithNonDestroyedState
engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDaoImpl.java Added listAllByStatusIncludingRemoved method to query snapshots including removed ones
engine/schema/src/main/java/com/cloud/storage/dao/SnapshotDao.java Added interface method listAllByStatusIncludingRemoved
engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java Added state transitions for Destroyed state to handle repeated destroy operations gracefully
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java Renamed variable from backupedSnapshot to backedUpSnapshot and from snapshot to snapshotOnPrimary for clarity, updated calls to use findBySnapshotIdWithNonDestroyedState
engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java Removed redundant variable assignment, removed unnecessary blank lines
engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java Updated to use findBySnapshotIdWithNonDestroyedState
engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java Removed unnecessary blank line
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java Updated to use findBySnapshotIdWithNonDestroyedState
plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/datastore/util/StorPoolHelper.java Updated to use findBySnapshotIdWithNonDestroyedState
engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java Added interface method getSnapshotIncludingRemoved
server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerImplTest.java Updated test mocks to use findBySnapshotIdWithNonDestroyedState
Comments suppressed due to low confidence (1)

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java:354

  • The new method findBySnapshotIdWithNonDestroyedState() and the modified implementation of findBySnapshotId() lack test coverage. Consider adding tests to verify that:
  1. findBySnapshotId returns all snapshot store references regardless of state
  2. findBySnapshotIdWithNonDestroyedState filters out Destroyed state references
  3. Both methods correctly handle cases where no snapshots exist
    public List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId) {
        SearchCriteria<SnapshotDataStoreVO> sc = searchFilteringStoreIdEqStateEqStoreRoleEqIdEqUpdateCountEqSnapshotIdEqVolumeIdEq.create();
        sc.setParameters(SNAPSHOT_ID, snapshotId);
        return listBy(sc);
    }

    @Override
    public List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId) {
        SearchCriteria<SnapshotDataStoreVO> sc = idStateNeqSearch.create();
        sc.setParameters(SNAPSHOT_ID, snapshotId);
        sc.setParameters(STATE, State.Destroyed);
        return listBy(sc);
    }

💡 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 16195

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm, some remarks about logging

Comment on lines +2036 to +2038
if (logger.isDebugEnabled()) {
logger.debug("Snapshot [{}] in {} state found on {} data store [{}], it will be deleted.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotInfo.getDataStore().getUuid());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the condition is not needed for the simple getters. Else lambdas can work as well.

Suggested change
if (logger.isDebugEnabled()) {
logger.debug("Snapshot [{}] in {} state found on {} data store [{}], it will be deleted.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotInfo.getDataStore().getUuid());
}
logger.debug("Snapshot [{}] in {} state found on {} data store [{}], it will be deleted.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotInfo.getDataStore().getUuid());

Comment on lines +2040 to +2042
} else if (logger.isDebugEnabled()) {
logger.debug("Did not find snapshot [{}] in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} else if (logger.isDebugEnabled()) {
logger.debug("Did not find snapshot [{}] in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
}
} else {
logger.debug("Did not find snapshot [{}] in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
}

Comment on lines +2045 to +2047
if (logger.isDebugEnabled()) {
logger.debug("Failed to delete snapshot [{}] from storage.", snapshot, e);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (logger.isDebugEnabled()) {
logger.debug("Failed to delete snapshot [{}] from storage.", snapshot, e);
}
logger.debug("Failed to delete snapshot [{}] from storage.", snapshot, e);

Comment on lines +2031 to +2033
if (logger.isDebugEnabled()) {
logger.debug("Snapshot [{}] is in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (logger.isDebugEnabled()) {
logger.debug("Snapshot [{}] is in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
}
logger.debug("Snapshot [{}] is in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());

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.

3 participants