From 92f7a5754f0dfa6f3673433cc3868242fb1b8dc3 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 1 Sep 2025 15:10:33 +0530 Subject: [PATCH] server: delete errored instance snapshot from db when no strategy DB entries for instance snapshot are created when no strategy is found. When deleting such entries later, again error is seen. Therefore, it is better to remove the entry immediately. Signed-off-by: Abhishek Kumar --- .../com/cloud/vm/snapshot/VMSnapshotManagerImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java index 907182edc2ab..ad2437ca6e06 100644 --- a/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java @@ -134,6 +134,8 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme public static final String VM_WORK_JOB_HANDLER = VMSnapshotManagerImpl.class.getSimpleName(); + private static final String ERROR_STRATEGY_NOT_FOUND = "can't find vm snapshot strategy for instance snapshot"; + @Inject VMInstanceDao _vmInstanceDao; @Inject ServiceOfferingDetailsDao _serviceOfferingDetailsDao; @@ -500,7 +502,7 @@ private VMSnapshotStrategy findVMSnapshotStrategy(VMSnapshot vmSnapshot) { VMSnapshotStrategy snapshotStrategy = storageStrategyFactory.getVmSnapshotStrategy(vmSnapshot); if (snapshotStrategy == null) { - throw new CloudRuntimeException(String.format("can't find vm snapshot strategy for vmsnapshot: %s", vmSnapshot)); + throw new CloudRuntimeException(String.format("%s: %s", ERROR_STRATEGY_NOT_FOUND, vmSnapshot)); } return snapshotStrategy; @@ -595,6 +597,13 @@ private VMSnapshot orchestrateCreateVMSnapshot(Long vmId, Long vmSnapshotId, Boo } catch (Exception e) { String errMsg = String.format("Failed to create vm snapshot: [%s] due to: %s", vmSnapshot, e.getMessage()); logger.debug(errMsg, e); + if (e instanceof CloudRuntimeException) { + CloudRuntimeException cre = (CloudRuntimeException)e; + if (cre.getMessage().startsWith(ERROR_STRATEGY_NOT_FOUND) && VMSnapshot.State.Error.equals(vmSnapshot.getState())) { + logger.debug("No instance snapshot strategy found for {}, remove it from DB", vmSnapshot); + _vmSnapshotDao.remove(vmSnapshot.getId()); + } + } throw new CloudRuntimeException(errMsg, e); } }