-
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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||||
| package org.apache.cloudstack.storage.vmsnapshot; | ||||||||
|
|
||||||||
| import java.util.ArrayList; | ||||||||
| import java.util.HashMap; | ||||||||
| import java.util.List; | ||||||||
| import java.util.Map; | ||||||||
| import java.util.concurrent.TimeUnit; | ||||||||
|
|
@@ -111,7 +112,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { | |||||||
| FreezeThawVMAnswer freezeAnswer = null; | ||||||||
| FreezeThawVMCommand thawCmd = null; | ||||||||
| FreezeThawVMAnswer thawAnswer = null; | ||||||||
| List<SnapshotInfo> forRollback = new ArrayList<>(); | ||||||||
| Map<Long, SnapshotInfo> volumeToSnapshotInfoMapForRollback = new HashMap<>(); | ||||||||
| long startFreeze = 0; | ||||||||
| try { | ||||||||
| vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.CreateRequested); | ||||||||
|
|
@@ -165,7 +166,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, volumeToSnapshotInfoMapForRollback, vol); | ||||||||
|
|
||||||||
| if (snapInfo == null) { | ||||||||
| thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); | ||||||||
|
|
@@ -222,7 +223,7 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) { | |||||||
| } | ||||||||
| } | ||||||||
| if (!result) { | ||||||||
| for (SnapshotInfo snapshotInfo : forRollback) { | ||||||||
| for (SnapshotInfo snapshotInfo : volumeToSnapshotInfoMapForRollback.values()) { | ||||||||
| rollbackDiskSnapshot(snapshotInfo); | ||||||||
| } | ||||||||
| try { | ||||||||
|
|
@@ -388,10 +389,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 +441,7 @@ protected void revertDiskSnapshot(VMSnapshot vmSnapshot) { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| protected SnapshotInfo createDiskSnapshot(VMSnapshot vmSnapshot, List<SnapshotInfo> forRollback, VolumeInfo vol) { | ||||||||
| protected SnapshotInfo createDiskSnapshot(VMSnapshot vmSnapshot, Map<Long, SnapshotInfo> volumeToSnapshotInfoMapForRollback, 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,6 +455,7 @@ 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()); | ||||||||
| volumeToSnapshotInfoMapForRollback.put(vol.getId(), snapshotInfo); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so it might be added twice right? so why the else at line 466? |
||||||||
| SnapshotStrategy snapshotStrategy = storageStrategyFactory.getSnapshotStrategy(snapshotInfo, SnapshotOperation.TAKE); | ||||||||
| if (snapshotStrategy == null) { | ||||||||
| throw new CloudRuntimeException("Could not find strategy for snapshot uuid:" + snapshotInfo.getUuid()); | ||||||||
|
|
@@ -456,7 +464,7 @@ protected SnapshotInfo createDiskSnapshot(VMSnapshot vmSnapshot, List<SnapshotIn | |||||||
| if (snapshotInfo == null) { | ||||||||
| throw new CloudRuntimeException("Failed to create snapshot"); | ||||||||
| } else { | ||||||||
|
||||||||
| } else { | |
| } | |
| if (snapshotInfo != volumeToSnapshotInfoMapForRollback.get(vol.getId())) { |
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.
this seems the only usage, why not a HashSet?