This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 45e77dd  server: Clean up the duplicate volume when the destination 
managed volume creation failed on migrate volume operation (#4730)
45e77dd is described below

commit 45e77dd6f0b707b7fd087d50aee5c8294e813cc9
Author: sureshanaparti <[email protected]>
AuthorDate: Wed Mar 3 13:30:08 2021 +0530

    server: Clean up the duplicate volume when the destination managed volume 
creation failed on migrate volume operation (#4730)
    
    Duplicated volumes after failed migration in Allocated state
    
    Fix: Clean up the duplicate volume when the destination managed volume 
creation failed on migrate volume operation
---
 .../cloudstack/storage/volume/VolumeServiceImpl.java   | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git 
a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
 
b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 68940d4..348c142 100644
--- 
a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ 
b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -1123,12 +1123,6 @@ public class VolumeServiceImpl implements VolumeService {
             // Refresh the volume info from the DB.
             volumeInfo = volFactory.getVolume(volumeInfo.getId(), 
destPrimaryDataStore);
 
-            volumeInfo.processEvent(Event.CreateRequested);
-            CreateVolumeFromBaseImageContext<VolumeApiResult> context = new 
CreateVolumeFromBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, 
srcTemplateOnPrimary, future, null, null);
-            AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> 
caller = AsyncCallbackDispatcher.create(this);
-            
caller.setCallback(caller.getTarget().createVolumeFromBaseManagedImageCallBack(null,
 null));
-            caller.setContext(context);
-
             Map<String, String> details = new HashMap<String, String>();
             details.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString());
             details.put(PrimaryDataStore.STORAGE_HOST, 
destPrimaryDataStore.getHostAddress());
@@ -1141,6 +1135,13 @@ public class VolumeServiceImpl implements VolumeService {
 
             grantAccess(volumeInfo, destHost, destPrimaryDataStore);
 
+            volumeInfo.processEvent(Event.CreateRequested);
+
+            CreateVolumeFromBaseImageContext<VolumeApiResult> context = new 
CreateVolumeFromBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, 
srcTemplateOnPrimary, future, null, null);
+            AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> 
caller = AsyncCallbackDispatcher.create(this);
+            
caller.setCallback(caller.getTarget().createVolumeFromBaseManagedImageCallBack(null,
 null));
+            caller.setContext(context);
+
             try {
                 motionSrv.copyAsync(srcTemplateOnPrimary, volumeInfo, 
destHost, caller);
             } finally {
@@ -1919,6 +1920,11 @@ public class VolumeServiceImpl implements VolumeService {
             AsyncCallFuture<VolumeApiResult> createVolumeFuture = 
createVolumeAsync(destVolume, destStore);
             VolumeApiResult createVolumeResult = createVolumeFuture.get();
             if (createVolumeResult.isFailed()) {
+                s_logger.debug("Failed to create dest volume " + 
destVolume.getId() + ", volume can be removed");
+                destroyVolume(destVolume.getId());
+                destVolume.processEvent(Event.ExpungeRequested);
+                destVolume.processEvent(Event.OperationSuccessed);
+                volDao.remove(destVolume.getId());
                 throw new CloudRuntimeException("Creation of a dest volume 
failed: " + createVolumeResult.getResult());
             }
 

Reply via email to