Skip to content

Commit b2a4625

Browse files
harikrishna-patnaladhslove
authored andcommitted
Fix snapshot deletion on template creation failure (apache#9239)
* Don't delete the snapshot itself on the primary storage upon any failure * Change an if condition
1 parent d38de7e commit b2a4625

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
@@ -104,15 +104,21 @@ public void expungeTemporarySnapshot(boolean kvmSnapshotOnlyInPrimaryStorage, Sn
104104
return;
105105
}
106106

107-
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]"
108-
+ " has the value [%s].", snapInfo.getId(), SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key(), backupSnapshotAfterTakingSnapshot));
109-
110-
try {
111-
snapshotService.deleteSnapshot(snapInfo);
112-
} catch (CloudRuntimeException ex) {
113-
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"
114-
+ " manually deleting the file [%s].", snapInfo.getId(), ex.getMessage(), snapInfo.getPath()), ex);
107+
if (!DataStoreRole.Image.equals(snapInfo.getDataStore().getRole())) {
108+
logger.debug(String.format("Expunge template for Snapshot [%s] is called for primary storage role. Not expunging it, " +
109+
"but we will still expunge the database reference of the snapshot for image storage role if any", snapInfo.getId()));
110+
} else {
111+
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]"
112+
+ " has the value [%s].", snapInfo.getId(), SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key(), backupSnapshotAfterTakingSnapshot));
113+
114+
try {
115+
snapshotService.deleteSnapshot(snapInfo);
116+
} catch (CloudRuntimeException ex) {
117+
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"
118+
+ " manually deleting the file [%s].", snapInfo.getId(), ex.getMessage(), snapInfo.getPath()), ex);
119+
}
115120
}
121+
116122
long storeId = snapInfo.getDataStore().getId();
117123
if (!DataStoreRole.Image.equals(snapInfo.getDataStore().getRole())) {
118124
long zoneId = dataStorageManager.getStoreZoneId(storeId, snapInfo.getDataStore().getRole());

0 commit comments

Comments
 (0)