JoaoJandre commented on code in PR #13411:
URL: https://github.com/apache/cloudstack/pull/13411#discussion_r4723210421


##########
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java:
##########
@@ -1632,18 +1632,25 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) 
throws ResourceAllocationExc
         boolean isKvmAndFileBasedStorage = 
isHypervisorKvmAndFileBasedStorage(volume, storagePool);
         boolean backupSnapToSecondary = 
isBackupSnapshotToSecondaryForZone(volume.getDataCenterId());
 
-        if (isKvmAndFileBasedStorage && backupSnapToSecondary) {
-            DataStore imageStore = 
snapshotSrv.findSnapshotImageStore(snapshot);
-            if (imageStore == null) {
-                throw new CloudRuntimeException(String.format("Could not find 
any secondary storage to allocate snapshot [%s].", snapshot));
-            }
-            snapshot.setImageStore(imageStore);
-        }
-
         updateSnapshotPayload(volume.getPoolId(), payload, 
isKvmAndFileBasedStorage, clusterId);
 
         snapshot.addPayload(payload);
+
         try {
+            if (isKvmAndFileBasedStorage && backupSnapToSecondary) {
+                try {
+                    DataStore imageStore = 
snapshotSrv.findSnapshotImageStore(snapshot);
+                    if (imageStore == null) {
+                        throw new CloudRuntimeException(String.format("Could 
not find any secondary storage to allocate snapshot [%s].", snapshot));
+                    }
+                    snapshot.setImageStore(imageStore);
+                } catch (CloudRuntimeException ex) {
+                    logger.error("There was an error while selecting image 
store for snapshot: {}", ex.getMessage());
+                    handleErrorInUncreatedSnapshot(snapshotId);
+                    throw new CloudRuntimeException(ex.getMessage());
+                }
+            }

Review Comment:
   do we need two tries here? the outer one seems not needed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to