Sergey Gotliv has uploaded a new change for review.

Change subject: engine: Engine has to delete image from DB after VDSM removed it
......................................................................

engine: Engine has to delete image from DB after VDSM removed it

Engine has to delete image from DB after VDSM removed it from storage,
but thrown an error in the process. What is really matter in this case
is whether the image still exists on the storage or not.
VDSM renames the image as a first step to removal. After renaming the
image doesn't exist, so if the error is thrown at this point the garbage
will stay on the storage, but its safe to remove image from DB.

Change-Id: If6e6922b153145de6d4515812c1cfede687544bc
Signed-off-by: Sergey Gotliv <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java
1 file changed, 30 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/61/19161/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java
index 2dbb35c..e26523b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java
@@ -25,6 +25,7 @@
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
 import 
org.ovirt.engine.core.common.vdscommands.DeleteImageGroupVDSCommandParameters;
+import 
org.ovirt.engine.core.common.vdscommands.GetImagesListVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import org.ovirt.engine.core.compat.Guid;
@@ -87,12 +88,18 @@
                                 VdcObjectType.Storage,
                                 getStorageDomainId()));
             } catch (VdcBLLException e) {
-                if (e.getErrorCode() != 
VdcBllErrors.ImageDoesNotExistInDomainError) {
+                if (e.getErrorCode() == 
VdcBllErrors.ImageDoesNotExistInDomainError) {
+                    log.warnFormat("The image group with id {0} wasn't 
actually deleted from the storage domain {1} " +
+                            "because it didn't exist in it", 
getDiskImage().getId(), getStorageDomainId());
+                }
+                // in case of any error other than 
ImageDoesNotExistInDomainError, Engine has to check
+                // if the image still exists on the storage, because VDSM 
renames the image before deleting it,
+                // so technically the image doesn't exist after renaming but 
the actual delete can still fail.
+                else if (isImageRemovedFromStorage()) {
+                    log.infoFormat("The image group with id {0} was deleted 
from storage");
+                } else {
                     throw e;
                 }
-                log.warnFormat("The image group with id {0} wasn't actually 
deleted from the storage domain {1} because it didn't exist in it",
-                        getDiskImage().getId(),
-                        getStorageDomainId());
             }
 
             if (getParameters().getParentCommand() != 
VdcActionType.RemoveVmFromImportExport
@@ -105,6 +112,25 @@
         setSucceeded(true);
     }
 
+    protected boolean isImageRemovedFromStorage() {
+        VDSReturnValue retValue = 
getBackend().getResourceManager().RunVdsCommand(VDSCommandType.GetImagesList,
+            new GetImagesListVDSCommandParameters(getStorageDomainId(), 
getDiskImage().getStoragePoolId()));
+
+        if (retValue.getSucceeded()) {
+            List<Guid> ids = (List<Guid>) retValue.getReturnValue();
+            for (Guid id : ids) {
+                if (id.equals(getDiskImage().getId())) {
+                    return false;
+                }
+            }
+            return true;
+        } else {
+            log.warnFormat("Failed to retrieve list of images from storage 
domain '" + getStorageDomainId() + "', " +
+                    "therefore there is no proof that image was deleted!");
+            return false;
+        }
+    }
+
     @Override
     protected AsyncTaskType getTaskType() {
         return AsyncTaskType.deleteImage;


-- 
To view, visit http://gerrit.ovirt.org/19161
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If6e6922b153145de6d4515812c1cfede687544bc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Sergey Gotliv <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to