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
This commit is contained in:
Harikrishna 2024-09-04 12:14:50 +05:30 committed by GitHub
parent e06f80e899
commit 601e9b67ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -103,15 +103,21 @@ public class SnapshotHelper {
return;
}
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]"
+ " has the value [%s].", snapInfo.getId(), SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key(), backupSnapshotAfterTakingSnapshot));
if (!DataStoreRole.Image.equals(snapInfo.getDataStore().getRole())) {
logger.debug(String.format("Expunge template for Snapshot [%s] is called for primary storage role. Not expunging it, " +
"but we will still expunge the database reference of the snapshot for image storage role if any", snapInfo.getId()));
} else {
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]"
+ " has the value [%s].", snapInfo.getId(), SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key(), backupSnapshotAfterTakingSnapshot));
try {
snapshotService.deleteSnapshot(snapInfo);
} catch (CloudRuntimeException ex) {
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"
+ " manually deleting the file [%s].", snapInfo.getId(), ex.getMessage(), snapInfo.getPath()), ex);
try {
snapshotService.deleteSnapshot(snapInfo);
} catch (CloudRuntimeException ex) {
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"
+ " manually deleting the file [%s].", snapInfo.getId(), ex.getMessage(), snapInfo.getPath()), ex);
}
}
long storeId = snapInfo.getDataStore().getId();
if (!DataStoreRole.Image.equals(snapInfo.getDataStore().getRole())) {
long zoneId = dataStorageManager.getStoreZoneId(storeId, snapInfo.getDataStore().getRole());