Skip to content

Commit a64ad9d

Browse files
Pearl1594Pearl Dsilva
andauthored
server: Prevent vm snapshots being indefinitely stuck in Expunging state on deletion failure (#4898)
Fixes #4201 This PR addresses the issue of a vm snapshot being indefinitely stuck is Expunging state in case deletion fails. Co-authored-by: Pearl Dsilva <pearl.dsilva@shapeblue.com>
1 parent e824fdb commit a64ad9d

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

api/src/main/java/com/cloud/vm/snapshot/VMSnapshot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public String getDescription() {
5959
s_fsm.addTransition(Error, Event.ExpungeRequested, Expunging);
6060
s_fsm.addTransition(Expunging, Event.ExpungeRequested, Expunging);
6161
s_fsm.addTransition(Expunging, Event.OperationSucceeded, Removed);
62+
s_fsm.addTransition(Expunging, Event.OperationFailed, Error);
6263
}
6364
}
6465

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,10 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
230230
} else {
231231
String errMsg = (answer == null) ? null : answer.getDetails();
232232
s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
233+
processAnswer(vmSnapshotVO, userVm, answer, hostId);
233234
throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
234235
}
235-
} catch (OperationTimedoutException e) {
236-
throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + e.getMessage());
237-
} catch (AgentUnavailableException e) {
236+
} catch (OperationTimedoutException | AgentUnavailableException e) {
238237
throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + e.getMessage());
239238
}
240239
}
@@ -254,9 +253,13 @@ public void doInTransactionWithoutResult(TransactionStatus status) throws NoTran
254253
finalizeRevert(vmSnapshot, answer.getVolumeTOs());
255254
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded);
256255
} else if (as instanceof DeleteVMSnapshotAnswer) {
257-
DeleteVMSnapshotAnswer answer = (DeleteVMSnapshotAnswer)as;
258-
finalizeDelete(vmSnapshot, answer.getVolumeTOs());
259-
vmSnapshotDao.remove(vmSnapshot.getId());
256+
if (as.getResult()) {
257+
DeleteVMSnapshotAnswer answer = (DeleteVMSnapshotAnswer) as;
258+
finalizeDelete(vmSnapshot, answer.getVolumeTOs());
259+
vmSnapshotDao.remove(vmSnapshot.getId());
260+
} else {
261+
vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
262+
}
260263
}
261264
}
262265
});

0 commit comments

Comments
 (0)