Michael Kublin has uploaded a new change for review. Change subject: engine: Replaced quartz job to thread job at MigrateVDSCommand ......................................................................
engine: Replaced quartz job to thread job at MigrateVDSCommand Because of we have more threads at the system and it is more covinient to open a thread instead of quarzt job with zero delay Change-Id: I7699a8d8e931ff336335d476fc4fc9251715b4fd Signed-off-by: Michael Kublin <[email protected]> --- M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MigrateVDSCommand.java 1 file changed, 41 insertions(+), 52 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/16/9416/1 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 7ebd584..dbc3f25 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 @@ -1,19 +1,15 @@ package org.ovirt.engine.core.vdsbroker; -import java.util.concurrent.TimeUnit; - import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; import org.ovirt.engine.core.common.vdscommands.MigrateVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.compat.TransactionScopeOption; 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.timer.OnTimerMethodAnnotation; -import org.ovirt.engine.core.utils.timer.SchedulerUtilQuartzImpl; +import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; import org.ovirt.engine.core.vdsbroker.vdsbroker.MigrateBrokerVDSCommand; @@ -58,7 +54,7 @@ }); if (retval == VMStatus.MigratingFrom) { - UpdateDestinationVdsThreaded(parameters.getDstVdsId(), vm); + updateDestinationVdsThreaded(parameters.getDstVdsId(), vm); } getVDSReturnValue().setReturnValue(retval); @@ -67,59 +63,52 @@ } } - private void UpdateDestinationVdsThreaded(Guid dstVdsId, VM vm) { - VdsManager vdsManager = ResourceManager.getInstance().GetVdsManager(dstVdsId); + private void updateDestinationVdsThreaded(Guid dstVdsId, final VM vm) { + final VdsManager vdsManager = ResourceManager.getInstance().GetVdsManager(dstVdsId); if (vdsManager != null) { - // TODO use thread pool - Class<?>[] inputTypes = new Class[] { VdsManager.class, VM.class }; - Object[] inputParams = new Object[] { vdsManager, vm }; - SchedulerUtilQuartzImpl.getInstance().scheduleAOneTimeJob(this, "UpdateDestinationVdsOnTimer", inputTypes, - inputParams, 0, TimeUnit.MILLISECONDS); + ThreadPoolUtil.execute(new Runnable() { + @Override + public void run() { + updateDestinationVdsOnTimer(vdsManager, vm); + } + }); } } - @OnTimerMethodAnnotation("UpdateDestinationVdsOnTimer") - public void UpdateDestinationVdsOnTimer(final VdsManager vdsManager, final VM vm) { + private void updateDestinationVdsOnTimer(final VdsManager vdsManager, final VM vm) { synchronized (vdsManager.getLockObj()) { - TransactionSupport.executeInScope(TransactionScopeOption.Suppress, new TransactionMethod<Object>() { - @Override - public Object runInTransaction() { - VDS vds = null; - try { - vds = DbFacade.getInstance().getVdsDao().get(vdsManager.getVdsId()); - vds.setvm_count(vds.getvm_count() + 1); - vds.setpending_vcpus_count(vds.getpending_vcpus_count() + vm.getnum_of_cpus()); - vds.setpending_vmem_size(vds.getpending_vmem_size() + vm.getMinAllocatedMem()); - if (log.isDebugEnabled()) { - log.debugFormat( - "IncreasePendingVms::MigrateVm Increasing vds {0} pending vcpu count, now {1}, and pending vmem size, now {2}. Vm: {3}", - vds.getvds_name(), - vds.getpending_vcpus_count(), - vds.getpending_vmem_size(), - vm.getvm_name()); - } - vdsManager.UpdateDynamicData(vds.getDynamicData()); - } catch (RuntimeException ex) { - if (vds == null) { - log.fatalFormat( - "VDS::migrate:: Could not update destination vds commited memory to db. vds {0} : was not find, error: {1}, {2}", - vdsManager.getVdsId(), - ex.toString(), - ex.getStackTrace()[0]); - } else { - log.fatalFormat( - "VDS::migrate:: Could not update destination vds commited memory to db. vds {0} : {1}, error: {2}, {3}", - vds.getId(), - vds.getvds_name(), - ex.toString(), - ex.getStackTrace()[0]); - } - } - - return null; + VDS vds = DbFacade.getInstance().getVdsDao().get(vdsManager.getVdsId()); + try { + vds.setvm_count(vds.getvm_count() + 1); + vds.setpending_vcpus_count(vds.getpending_vcpus_count() + vm.getnum_of_cpus()); + vds.setpending_vmem_size(vds.getpending_vmem_size() + vm.getMinAllocatedMem()); + if (log.isDebugEnabled()) { + log.debugFormat( + "IncreasePendingVms::MigrateVm Increasing vds {0} pending vcpu count, now {1}, and pending vmem size, now {2}. Vm: {3}", + vds.getvds_name(), + vds.getpending_vcpus_count(), + vds.getpending_vmem_size(), + vm.getvm_name()); } - }); + vdsManager.UpdateDynamicData(vds.getDynamicData()); + } catch (RuntimeException ex) { + if (vds == null) { + log.fatalFormat( + "VDS::migrate:: Could not update destination vds commited memory to db. vds {0} : was not find, error: {1}, {2}", + vdsManager.getVdsId(), + ex.toString(), + ex.getStackTrace()[0]); + } else { + log.fatalFormat( + "VDS::migrate:: Could not update destination vds commited memory to db. vds {0} : {1}, error: {2}, {3}", + vds.getId(), + vds.getvds_name(), + ex.toString(), + ex.getStackTrace()[0]); + } + } + } } -- To view, visit http://gerrit.ovirt.org/9416 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7699a8d8e931ff336335d476fc4fc9251715b4fd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Michael Kublin <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
