Yair Zaslavsky has uploaded a new change for review.

Change subject: [WIP] core: Handling transactivity at ShutdownVmCommand
......................................................................

[WIP] core: Handling transactivity at ShutdownVmCommand

This patch removes global transactions from
ShutdownVmCommand related flows, and introduces
shorter transaction + compensation where needed.

Change-Id: I373d921fbecbd2fee79c5a430b428f7f20246051
Bug-Url: https://bugzilla.redhat.com865086
Signed-off-by: Yair Zaslavsky <yzasl...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
3 files changed, 54 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/71/8571/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
index 3bb2f9f..c95f7cd 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
@@ -10,10 +10,12 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 
+@NonTransactiveCommandAttribute(forceCompensation=true)
 public class ShutdownVmCommand<T extends ShutdownVmParameters> extends 
StopVmCommandBase<T> {
     public ShutdownVmCommand(T shutdownVmParamsData) {
         super(shutdownVmParamsData);
@@ -28,6 +30,10 @@
         }
     }
 
+    protected ShutdownVmCommand(Guid commandId) {
+        super(commandId);
+    }
+
     @Override
     protected boolean canDoAction() {
         boolean ret = super.canDoAction();
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
index 2520b8a..649efb0 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
@@ -2,13 +2,19 @@
 
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.StopVmParameters;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 
+@NonTransactiveCommandAttribute(forceCompensation=true)
 public class StopVmCommand<T extends StopVmParameters> extends 
StopVmCommandBase<T> {
     public StopVmCommand(T stopVmParams) {
         super(stopVmParams);
     }
 
+    protected StopVmCommand(Guid commandId) {
+        super(commandId);
+    }
+
     @Override
     protected void Perform() {
         Destroy();
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
index 1ae33de..704d5eb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
@@ -25,6 +25,8 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
+import org.ovirt.engine.core.utils.transaction.TransactionMethod;
+import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
 public abstract class StopVmCommandBase<T extends VmOperationParameterBase> 
extends VmOperationCommandBase<T> implements Quotable {
     private boolean privateSuspendedVm;
@@ -39,6 +41,10 @@
 
     private void setSuspendedVm(boolean value) {
         privateSuspendedVm = value;
+    }
+
+    protected StopVmCommandBase(Guid guid) {
+        super(guid);
     }
 
     @Override
@@ -94,16 +100,26 @@
     private void removeStatelessVmUnmanagedDevices() {
         if (getSucceeded() && (getVm().getis_stateless() ||  isRunOnce())) {
             // remove all unmanaged devices of a stateless VM
-            List<VmDevice> vmDevices =
-                DbFacade.getInstance()
-                        .getVmDeviceDao()
-                        .getUnmanagedDevicesByVmId(getVm().getId());
-            for (VmDevice device : vmDevices) {
-                // do not remove device if appears in white list
-                if (! VmDeviceCommonUtils.isInWhiteList(device.getType(), 
device.getDevice())) {
-                    
DbFacade.getInstance().getVmDeviceDao().remove(device.getId());
+
+            final List<VmDevice> vmDevices =
+                    DbFacade.getInstance()
+                            .getVmDeviceDao()
+                            .getUnmanagedDevicesByVmId(getVm().getId());
+
+            TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
+
+                @Override
+                public Void runInTransaction() {
+                    for (VmDevice device : vmDevices) {
+                        // do not remove device if appears in white list
+                        if (! 
VmDeviceCommonUtils.isInWhiteList(device.getType(), device.getDevice())) {
+                            
DbFacade.getInstance().getVmDeviceDao().remove(device.getId());
+                        }
+                    }
+                    return null;
                 }
-            }
+
+            });
         }
     }
 
@@ -139,21 +155,33 @@
         VMStatus vmStatus = getVm().getstatus();
 
         // Check whether stop VM procedure didn't started yet (Status is not 
imageLocked), by another transaction.
+        getVm().setstatus(VMStatus.ImageLocked);
         if (getVm().getstatus() != VMStatus.ImageLocked) {
             // Set the VM to image locked to decrease race condition.
-            getVm().setstatus(VMStatus.ImageLocked);
-            updateVmData(getVm().getDynamicData());
-            if 
(!StringHelper.isNullOrEmpty(getVm().gethibernation_vol_handle())
+            updateVmStatus(VMStatus.ImageLocked);
+             if 
(!StringHelper.isNullOrEmpty(getVm().gethibernation_vol_handle())
                     && handleHibernatedVm(getActionType(), false)) {
                 returnVal = true;
             } else {
-                getVm().setstatus(vmStatus);
-                updateVmData(getVm().getDynamicData());
+                updateVmStatus(vmStatus);
             }
         }
         return returnVal;
     }
 
+    private void updateVmStatus(VMStatus newStatus) {
+        getVm().setstatus(newStatus);
+        TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
+            @Override
+            public Void runInTransaction() {
+                
getCompensationContext().snapshotEntity(getVm().getDynamicData());
+                updateVmData(getVm().getDynamicData());
+                getCompensationContext().stateChanged();
+                return null;
+            }
+        });
+    }
+
     /**
      * Update Vm dynamic data in the DB.<BR/>
      * If VM is active in the VDSM (not suspended/stop), we will use 
UpdateVmDynamicData VDS command, for preventing


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I373d921fbecbd2fee79c5a430b428f7f20246051
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Yair Zaslavsky <yzasl...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to