-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix rollback disk snapshots on instance snapshot failure #12949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.22
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,7 +111,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { | |
| FreezeThawVMAnswer freezeAnswer = null; | ||
| FreezeThawVMCommand thawCmd = null; | ||
| FreezeThawVMAnswer thawAnswer = null; | ||
| List<SnapshotInfo> forRollback = new ArrayList<>(); | ||
| List<SnapshotInfo> snapshotInfoListForRollback = new ArrayList<>(); | ||
| long startFreeze = 0; | ||
| try { | ||
| vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.CreateRequested); | ||
|
|
@@ -165,7 +165,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { | |
| logger.info("The virtual machine is frozen"); | ||
| for (VolumeInfo vol : vinfos) { | ||
| long startSnapshtot = System.nanoTime(); | ||
| SnapshotInfo snapInfo = createDiskSnapshot(vmSnapshot, forRollback, vol); | ||
| SnapshotInfo snapInfo = createDiskSnapshot(vmSnapshot, snapshotInfoListForRollback, vol); | ||
|
|
||
| if (snapInfo == null) { | ||
| thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); | ||
|
|
@@ -222,7 +222,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { | |
| } | ||
| } | ||
| if (!result) { | ||
| for (SnapshotInfo snapshotInfo : forRollback) { | ||
| for (SnapshotInfo snapshotInfo : snapshotInfoListForRollback) { | ||
| rollbackDiskSnapshot(snapshotInfo); | ||
| } | ||
| try { | ||
|
|
@@ -388,10 +388,16 @@ private long elapsedTime(long startTime) { | |
|
|
||
| //Rollback if one of disks snapshot fails | ||
| protected void rollbackDiskSnapshot(SnapshotInfo snapshotInfo) { | ||
| if (snapshotInfo == null) { | ||
| return; | ||
| } | ||
| Long snapshotID = snapshotInfo.getId(); | ||
| SnapshotVO snapshot = snapshotDao.findById(snapshotID); | ||
| if (snapshot == null) { | ||
| return; | ||
| } | ||
| deleteSnapshotByStrategy(snapshot); | ||
| logger.debug("Rollback is executed: deleting snapshot with id:" + snapshotID); | ||
| logger.debug("Rollback is executed: deleting snapshot with id: {}", snapshotID); | ||
| } | ||
|
|
||
| protected void deleteSnapshotByStrategy(SnapshotVO snapshot) { | ||
|
|
@@ -434,7 +440,7 @@ protected void revertDiskSnapshot(VMSnapshot vmSnapshot) { | |
| } | ||
| } | ||
|
|
||
| protected SnapshotInfo createDiskSnapshot(VMSnapshot vmSnapshot, List<SnapshotInfo> forRollback, VolumeInfo vol) { | ||
| protected SnapshotInfo createDiskSnapshot(VMSnapshot vmSnapshot, List<SnapshotInfo> snapshotInfoListForRollback, VolumeInfo vol) { | ||
| String snapshotName = vmSnapshot.getId() + "_" + vol.getUuid(); | ||
| SnapshotVO snapshot = new SnapshotVO(vol.getDataCenterId(), vol.getAccountId(), vol.getDomainId(), vol.getId(), vol.getDiskOfferingId(), | ||
| snapshotName, (short) Snapshot.Type.GROUP.ordinal(), Snapshot.Type.GROUP.name(), vol.getSize(), vol.getMinIops(), vol.getMaxIops(), Hypervisor.HypervisorType.KVM, null); | ||
|
|
@@ -448,15 +454,14 @@ protected SnapshotInfo createDiskSnapshot(VMSnapshot vmSnapshot, List<SnapshotIn | |
| vol.addPayload(setPayload(vol, snapshot, quiescevm)); | ||
| SnapshotInfo snapshotInfo = snapshotDataFactory.getSnapshot(snapshot.getId(), vol.getDataStore()); | ||
| snapshotInfo.addPayload(vol.getpayload()); | ||
| snapshotInfoListForRollback.add(snapshotInfo); | ||
| SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshotInfo, SnapshotOperation.TAKE); | ||
|
Comment on lines
454
to
458
|
||
| if (snapshotStrategy == null) { | ||
| throw new CloudRuntimeException("Could not find strategy for snapshot uuid:" + snapshotInfo.getUuid()); | ||
| } | ||
| snapshotInfo = snapshotStrategy.takeSnapshot(snapshotInfo); | ||
| if (snapshotInfo == null) { | ||
| throw new CloudRuntimeException("Failed to create snapshot"); | ||
| } else { | ||
| forRollback.add(snapshotInfo); | ||
| } | ||
| vmSnapshotDetailsDao.persist(new VMSnapshotDetailsVO(vmSnapshot.getId(), STORAGE_SNAPSHOT, String.valueOf(snapshot.getId()), true)); | ||
| snapshotInfo.markBackedUp(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snapshotInfoListForRollbackis very verbose and repeats the generic type (SnapshotInfo) already conveyed byList<SnapshotInfo>. Consider renaming to something shorter and intention-revealing likerollbackSnapshots/snapshotsForRollbackto improve readability (optional).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snapshotsForRollbackseems appropriate, @sureshanaparti ? (or close/ignore)