Skip to content

Commit cfca8f2

Browse files
Don't delete the snapshot itself on the primary storage upon any failure
1 parent 72bef48 commit cfca8f2

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
@@ -101,15 +101,21 @@ public void expungeTemporarySnapshot(boolean kvmSnapshotOnlyInPrimaryStorage, Sn
101101
return;
102102
}
103103

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

0 commit comments

Comments
 (0)