Skip to content

Commit 92f7a57

Browse files
committed
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 <[email protected]>
1 parent 8756be5 commit 92f7a57

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/src/main/java/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public class VMSnapshotManagerImpl extends MutualExclusiveIdsManagerBase impleme
134134

135135
public static final String VM_WORK_JOB_HANDLER = VMSnapshotManagerImpl.class.getSimpleName();
136136

137+
private static final String ERROR_STRATEGY_NOT_FOUND = "can't find vm snapshot strategy for instance snapshot";
138+
137139
@Inject
138140
VMInstanceDao _vmInstanceDao;
139141
@Inject ServiceOfferingDetailsDao _serviceOfferingDetailsDao;
@@ -500,7 +502,7 @@ private VMSnapshotStrategy findVMSnapshotStrategy(VMSnapshot vmSnapshot) {
500502
VMSnapshotStrategy snapshotStrategy = storageStrategyFactory.getVmSnapshotStrategy(vmSnapshot);
501503

502504
if (snapshotStrategy == null) {
503-
throw new CloudRuntimeException(String.format("can't find vm snapshot strategy for vmsnapshot: %s", vmSnapshot));
505+
throw new CloudRuntimeException(String.format("%s: %s", ERROR_STRATEGY_NOT_FOUND, vmSnapshot));
504506
}
505507

506508
return snapshotStrategy;
@@ -595,6 +597,13 @@ private VMSnapshot orchestrateCreateVMSnapshot(Long vmId, Long vmSnapshotId, Boo
595597
} catch (Exception e) {
596598
String errMsg = String.format("Failed to create vm snapshot: [%s] due to: %s", vmSnapshot, e.getMessage());
597599
logger.debug(errMsg, e);
600+
if (e instanceof CloudRuntimeException) {
601+
CloudRuntimeException cre = (CloudRuntimeException)e;
602+
if (cre.getMessage().startsWith(ERROR_STRATEGY_NOT_FOUND) && VMSnapshot.State.Error.equals(vmSnapshot.getState())) {
603+
logger.debug("No instance snapshot strategy found for {}, remove it from DB", vmSnapshot);
604+
_vmSnapshotDao.remove(vmSnapshot.getId());
605+
}
606+
}
598607
throw new CloudRuntimeException(errMsg, e);
599608
}
600609
}

0 commit comments

Comments
 (0)