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 <sgot...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveImageCommand.java
1 file changed, 32 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/20651/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 fa8f16f..26683af 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,19 @@
                                 VdcObjectType.Storage,
                                 getStorageDomainId()));
             } catch (VdcBLLException e) {
-                if (e.getErrorCode() != 
VdcBllErrors.ImageDoesNotExistInDomainError) {
+                if (e.getErrorCode() == 
VdcBllErrors.ImageDoesNotExistInDomainError) {
+                    log.infoFormat("Disk '{0}' doesn't exist on storage domain 
'{1}', rolling forward",
+                            getDiskImage().getId(), getStorageDomainId());
+                }
+                // VDSM renames the image before deleting it, so technically 
the image doesn't exist after renaming,
+                // but the actual delete can still fail with ImageDeleteError.
+                // In this case, Engine has to check whether image still 
exists on the storage or not.
+                else if (e.getErrorCode() == VdcBllErrors.ImageDeleteError && 
isImageRemovedFromStorage()) {
+                    log.infoFormat("Disk '{0}' was deleted from storage domain 
'{1}'", getDiskImage().getId(),
+                            getStorageDomainId());
+                } 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 +113,26 @@
         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("Could not retrieve image list from storage domain 
'{0}' '{1}', disk '{2}' might " +
+                    "not have been deleted", getStorageDomainId(), 
getStorageDomain().getName(),
+                    getDiskImage().getId());
+            return false;
+        }
+    }
+
     @Override
     protected AsyncTaskType getTaskType() {
         return AsyncTaskType.deleteImage;


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If6e6922b153145de6d4515812c1cfede687544bc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Sergey Gotliv <sgot...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to