@@ -1633,11 +1633,17 @@ public SnapshotInfo takeSnapshot(VolumeInfo volume) throws ResourceAllocationExc
16331633 boolean backupSnapToSecondary = isBackupSnapshotToSecondaryForZone (volume .getDataCenterId ());
16341634
16351635 if (isKvmAndFileBasedStorage && backupSnapToSecondary ) {
1636- DataStore imageStore = snapshotSrv .findSnapshotImageStore (snapshot );
1637- if (imageStore == null ) {
1638- throw new CloudRuntimeException (String .format ("Could not find any secondary storage to allocate snapshot [%s]." , snapshot ));
1636+ try {
1637+ DataStore imageStore = snapshotSrv .findSnapshotImageStore (snapshot );
1638+ if (imageStore == null ) {
1639+ throw new CloudRuntimeException (String .format ("Could not find any secondary storage to allocate snapshot [%s]." , snapshot ));
1640+ }
1641+ snapshot .setImageStore (imageStore );
1642+ } catch (CloudRuntimeException ex ) {
1643+ logger .error ("There was an error while selecting image store for snapshot: {}" , ex .getMessage ());
1644+ handleErrorInUncreatedSnapshot (snapshotId );
1645+ throw new CloudRuntimeException (ex .getMessage ());
16391646 }
1640- snapshot .setImageStore (imageStore );
16411647 }
16421648
16431649 updateSnapshotPayload (volume .getPoolId (), payload , isKvmAndFileBasedStorage , clusterId );
@@ -1738,6 +1744,12 @@ private void postSnapshotDirectlyToSecondary(SnapshotInfo snapshot, SnapshotInfo
17381744 snapshotDetailsDao .removeDetail (snapshotOnPrimary .getId (), AsyncJob .Constants .MS_ID );
17391745 }
17401746
1747+ private void handleErrorInUncreatedSnapshot (Long snapshotId ) {
1748+ SnapshotVO snapshot = _snapshotDao .findById (snapshotId );
1749+ snapshot .setState (Snapshot .State .Error );
1750+ _snapshotDao .persist (snapshot );
1751+ }
1752+
17411753 @ Override
17421754 public boolean isHypervisorKvmAndFileBasedStorage (VolumeInfo volumeInfo , StoragePool storagePool ) {
17431755 Set <StoragePoolType > fileBasedStores = Set .of (Storage .StoragePoolType .SharedMountPoint , Storage .StoragePoolType .NetworkFilesystem , Storage .StoragePoolType .Filesystem );
0 commit comments