weizhouapache commented on a change in pull request #5373:
URL: https://github.com/apache/cloudstack/pull/5373#discussion_r699271425



##########
File path: server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
##########
@@ -1407,29 +1407,36 @@ protected void destroyVolumeIfPossible(VolumeVO volume) 
{
      * If the volume is not in the primary storage, we do nothing here.
      */
     protected void expungeVolumesInPrimaryStorageIfNeeded(VolumeVO volume) 
throws InterruptedException, ExecutionException {
-        VolumeInfo volOnPrimary = volFactory.getVolume(volume.getId(), 
DataStoreRole.Primary);
-        if (volOnPrimary != null) {
-            s_logger.info("Expunging volume " + volume.getId() + " from 
primary data store");
-            AsyncCallFuture<VolumeApiResult> future = 
volService.expungeVolumeAsync(volOnPrimary);
-            future.get();
-        }
+        expungeVolumesInPrimaryOrSecondary(volume, DataStoreRole.Primary);
     }
 
     /**
      * We will check if the given volume is in the secondary storage. If the 
volume is not in the primary storage, we do nothing here.
      * If it is, we will execute an asynchronous call to delete it there. 
Then, we decrement the {@link ResourceType#secondary_storage} for the account 
that owns the volume.
      */
     protected void expungeVolumesInSecondaryStorageIfNeeded(VolumeVO volume) 
throws InterruptedException, ExecutionException {
-        VolumeInfo volOnSecondary = volFactory.getVolume(volume.getId(), 
DataStoreRole.Image);
-        if (volOnSecondary != null) {
-            s_logger.info("Expunging volume " + volume.getId() + " from 
secondary data store");
-            AsyncCallFuture<VolumeApiResult> future2 = 
volService.expungeVolumeAsync(volOnSecondary);
-            future2.get();
+        expungeVolumesInPrimaryOrSecondary(volume, DataStoreRole.Image);
+    }
 
-            
_resourceLimitMgr.decrementResourceCount(volOnSecondary.getAccountId(), 
ResourceType.secondary_storage, volOnSecondary.getSize());
+    private void expungeVolumesInPrimaryOrSecondary(VolumeVO volume, 
DataStoreRole role) throws InterruptedException, ExecutionException {
+        VolumeInfo volOnStorage = volFactory.getVolume(volume.getId(), role);
+        if (volOnStorage != null) {
+            s_logger.info("Expunging volume " + volume.getId() + " from " + 
role + " data store");
+            AsyncCallFuture<VolumeApiResult> future = 
volService.expungeVolumeAsync(volOnStorage);
+            VolumeApiResult result = future.get();
+            if (result.isFailed()) {
+                s_logger.warn("Failed to expunge the volume " + volume + " in 
" + role + " data store");
+                String details = "";
+                if (result.getResult() != null && 
!result.getResult().isEmpty()) {
+                    details = result.getResult();
+                }
+                throw new CloudRuntimeException(details);

Review comment:
       @nvazquez done, thanks.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to