Arik Hadas has uploaded a new change for review. Change subject: core: make migrate commands non-transactive ......................................................................
core: make migrate commands non-transactive Patch 94e48a02 removed the global transaction during RunVmCommand. Global transactions should also be removed from the migrate commands for the same reasons and because it prevents us from migrating multiple VMs from different hosts to the same host while one of the migrations is in its execute phase or start a VM on a host while another VM is migrating to that host and the migration is in its execute phase. Change-Id: I4894ebd5f062174f9780926a0ce6b499fcc0fc7b Bug-Url: https://bugzilla.redhat.com/1118187 Signed-off-by: Arik Hadas <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MigrateVDSCommand.java 4 files changed, 38 insertions(+), 36 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/93/29893/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java index a453aac..9ca035b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InternalMigrateVmCommand.java @@ -7,6 +7,7 @@ @LockIdNameAttribute(isReleaseAtEndOfExecute = false) @InternalCommandAttribute +@NonTransactiveCommandAttribute public class InternalMigrateVmCommand<T extends InternalMigrateVmParameters> extends MigrateVmCommand<MigrateVmParameters> { public InternalMigrateVmCommand(T parameters) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java index 869d8c5..1e4a74c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmCommand.java @@ -37,6 +37,7 @@ import org.ovirt.engine.core.utils.NetworkUtils; @LockIdNameAttribute(isReleaseAtEndOfExecute = false) +@NonTransactiveCommandAttribute public class MigrateVmCommand<T extends MigrateVmParameters> extends RunVmCommandBase<T> { private Guid vdsDestinationId; @@ -87,7 +88,7 @@ } } - protected void initVdss() { + protected boolean initVdss() { setVdsIdRef(getVm().getRunOnVds()); VDS destVds = getDestinationVds(); Guid vdsToRunOn = @@ -108,45 +109,51 @@ // changed. _destinationVds = null; if (vdsDestinationId != null && vdsDestinationId.equals(Guid.Empty)) { - throw new VdcBLLException(VdcBllErrors.RESOURCE_MANAGER_CANT_ALLOC_VDS_MIGRATION); + return false; } if (getDestinationVds() == null || getVds() == null) { - throw new VdcBLLException(VdcBllErrors.RESOURCE_MANAGER_VDS_NOT_FOUND); + return false; } + + return true; } @Override protected void executeVmCommand() { - initVdss(); - perform(); - setSucceeded(true); + setSucceeded(initVdss() && perform()); } - private void perform() { + private boolean perform() { getVm().setMigratingToVds(vdsDestinationId); getParameters().setStartTime(new Date()); - // Starting migration at src VDS - boolean connectToLunDiskSuccess = connectLunDisks(vdsDestinationId); - if (connectToLunDiskSuccess) { - setActionReturnValue(Backend - .getInstance() - .getResourceManager() - .RunAsyncVdsCommand( - VDSCommandType.Migrate, - createMigrateVDSCommandParameters(), - this) - .getReturnValue()); + try { + // Starting migration at src VDS + boolean connectToLunDiskSuccess = connectLunDisks(vdsDestinationId); + if (connectToLunDiskSuccess) { + setActionReturnValue(Backend + .getInstance() + .getResourceManager() + .RunAsyncVdsCommand( + VDSCommandType.Migrate, + createMigrateVDSCommandParameters(), + this) + .getReturnValue()); + } + if (!connectToLunDiskSuccess || getActionReturnValue() != VMStatus.MigratingFrom) { + getVm().setMigreatingToPort(0); + getVm().setMigreatingFromPort(0); + getVm().setMigratingToVds(null); + return false; + } + ExecutionHandler.setAsyncJob(getExecutionContext(), true); + return true; } - if (!connectToLunDiskSuccess || getActionReturnValue() != VMStatus.MigratingFrom) { - getVm().setMigreatingToPort(0); - getVm().setMigreatingFromPort(0); - getVm().setMigratingToVds(null); - throw new VdcBLLException(VdcBllErrors.RESOURCE_MANAGER_MIGRATION_FAILED_AT_DST); + catch (VdcBLLException e) { + return false; } - ExecutionHandler.setAsyncJob(getExecutionContext(), true); } private MigrateVDSCommandParameters createMigrateVDSCommandParameters() { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java index eff6960..6de533c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MigrateVmToServerCommand.java @@ -12,6 +12,7 @@ import org.ovirt.engine.core.compat.Guid; @LockIdNameAttribute(isReleaseAtEndOfExecute = false) +@NonTransactiveCommandAttribute public class MigrateVmToServerCommand<T extends MigrateVmToServerParameters> extends MigrateVmCommand<T> { public MigrateVmToServerCommand(T parameters) { super(parameters); diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MigrateVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MigrateVDSCommand.java index 924544d..5de29f1 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MigrateVDSCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MigrateVDSCommand.java @@ -9,8 +9,6 @@ import org.ovirt.engine.core.dao.VmDynamicDAO; 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; import org.ovirt.engine.core.vdsbroker.vdsbroker.MigrateBrokerVDSCommand; public class MigrateVDSCommand<P extends MigrateVDSCommandParameters> extends VdsIdVDSCommandBase<P> { @@ -29,12 +27,15 @@ command.execute(); VDSReturnValue vdsReturnValue = command.getVDSReturnValue(); - final VM vm = getVmDao().get(getParameters().getVmId()); + VM vm = getVmDao().get(getParameters().getVmId()); if (vdsReturnValue.getSucceeded()) { + ResourceManager.getInstance().AddAsyncRunningVm(getParameters().getVmId()); + ResourceManager.getInstance().InternalSetVmStatus(vm, VMStatus.MigratingFrom); vm.setMigratingToVds(getParameters().getDstVdsId()); - ResourceManager.getInstance().AddAsyncRunningVm(getParameters().getVmId()); + getVmDynamicDAO().update(vm.getDynamicData()); + getVDSReturnValue().setReturnValue(VMStatus.MigratingFrom); } else { log.error("Failed Vm migration"); @@ -44,14 +45,6 @@ getVDSReturnValue().setExceptionString(vdsReturnValue.getExceptionString()); getVDSReturnValue().setExceptionObject(vdsReturnValue.getExceptionObject()); } - - TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { - @Override - public Void runInTransaction() { - getVmDynamicDAO().update(vm.getDynamicData()); - return null; - } - }); } private VmDynamicDAO getVmDynamicDAO() { -- To view, visit http://gerrit.ovirt.org/29893 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4894ebd5f062174f9780926a0ce6b499fcc0fc7b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4.3 Gerrit-Owner: Arik Hadas <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
