Skip to content

Commit 601e9b6

Browse files
Fix snapshot deletion on template creation failure (#9239)
* Don't delete the snapshot itself on the primary storage upon any failure * Change an if condition
1 parent e06f80e commit 601e9b6

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

server/src/main/java/org/apache/cloudstack/snapshot/SnapshotHelper.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,21 @@ public void expungeTemporarySnapshot(boolean kvmSnapshotOnlyInPrimaryStorage, Sn
103103
return;
104104
}
105105

106-
logger.debug(String.format("Expunging snapshot [%s] due to it is a temporary backup to create a volume from snapshot. It is occurring because the global setting [%s]"
107-
+ " has the value [%s].", snapInfo.getId(), SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key(), backupSnapshotAfterTakingSnapshot));
108-
109-
try {
110-
snapshotService.deleteSnapshot(snapInfo);
111-
} catch (CloudRuntimeException ex) {
112-
logger.warn(String.format("Unable to delete the temporary snapshot [%s] on secondary storage due to [%s]. We still will expunge the database reference, consider"
113-
+ " manually deleting the file [%s].", snapInfo.getId(), ex.getMessage(), snapInfo.getPath()), ex);
106+
if (!DataStoreRole.Image.equals(snapInfo.getDataStore().getRole())) {
107+
logger.debug(String.format("Expunge template for Snapshot [%s] is called for primary storage role. Not expunging it, " +
108+
"but we will still expunge the database reference of the snapshot for image storage role if any", snapInfo.getId()));
109+
} else {
110+
logger.debug(String.format("Expunging snapshot [%s] due to it is a temporary backup to create a volume from snapshot. It is occurring because the global setting [%s]"
111+
+ " has the value [%s].", snapInfo.getId(), SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key(), backupSnapshotAfterTakingSnapshot));
112+
113+
try {
114+
snapshotService.deleteSnapshot(snapInfo);
115+
} catch (CloudRuntimeException ex) {
116+
logger.warn(String.format("Unable to delete the temporary snapshot [%s] on secondary storage due to [%s]. We still will expunge the database reference, consider"
117+
+ " manually deleting the file [%s].", snapInfo.getId(), ex.getMessage(), snapInfo.getPath()), ex);
118+
}
114119
}
120+
115121
long storeId = snapInfo.getDataStore().getId();
116122
if (!DataStoreRole.Image.equals(snapInfo.getDataStore().getRole())) {
117123
long zoneId = dataStorageManager.getStoreZoneId(storeId, snapInfo.getDataStore().getRole());

0 commit comments

Comments
 (0)