Yair Zaslavsky has uploaded a new change for review. Change subject: core: Extracting methods of decrease pending VMs synchronization ......................................................................
core: Extracting methods of decrease pending VMs synchronization Extracting the blocking queue offer and poll methods. On the way reducing the try catch block to wrap only the poll method. Change-Id: Ic463bd0a1fe60fd4d491fe0b2e7e75c9b61a6cbc Signed-off-by: Yair Zaslavsky <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java 1 file changed, 17 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/13817/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java index d4137c5..a714d77 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; + import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.bll.job.ExecutionContext; import org.ovirt.engine.core.bll.job.ExecutionContext.ExecutionMethod; @@ -34,7 +35,6 @@ import org.ovirt.engine.core.common.vdscommands.UpdateVmDynamicDataVDSCommandParameters; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; @@ -324,7 +324,7 @@ DbFacade.getInstance() .getVdsDynamicDao() .updatePartialVdsDynamicCalc(vdsId, 0, -getVm().getNumOfCpus(), -getVm().getMinAllocatedMem(), 0, 0); - getBlockingQueue(vdsId).offer(Boolean.TRUE); + notifyDecreasePendingVms(vdsId); if (log.isDebugEnabled()) { log.debugFormat("DecreasePendingVms::Decreasing vds {0} pending vcpu count, in {1}. Vm: {2}", @@ -332,6 +332,10 @@ log.debugFormat("DecreasePendingVms::Decreasing vds {0} pending vmem size, in {1}. Vm: {2}", vdsId, getVm().getMinAllocatedMem(), getVm().getName()); } + } + + private void notifyDecreasePendingVms(Guid vdsId) { + getBlockingQueue(vdsId).offer(Boolean.TRUE); } /** @@ -343,16 +347,18 @@ @Override public void delay(Guid vdsId) { log.debug("try to wait for te engine update the host memory and cpu stats"); - - try { - // time out waiting for an update is the highest between the refresh rate and the last update elapsed time - // but still no higher than a configurable max to prevent very long updates to stall command. - long t = Math.max( - ResourceManager.getInstance().GetVdsManager(vdsId).getLastUpdateElapsed(), - TimeUnit.SECONDS.toMillis(Config.<Integer> GetValue(VdsRefreshRate))); - t = Math.max(Config.<Integer> GetValue(ConfigValues.ThrottlerMaxWaitForVdsUpdateInMillis), t); - + // time out waiting for an update is the highest between the refresh rate and the last update elapsed time + // but still no higher than a configurable max to prevent very long updates to stall command. + long t = Math.max( + ResourceManager.getInstance().GetVdsManager(vdsId).getLastUpdateElapsed(), + TimeUnit.SECONDS.toMillis(Config.<Integer> GetValue(VdsRefreshRate))); + t = Math.max(Config.<Integer> GetValue(ConfigValues.ThrottlerMaxWaitForVdsUpdateInMillis), t); // wait for the run-time refresh to decrease any current powering-up VMs + waitForDecreasePendingVms(vdsId, t); + } + + private void waitForDecreasePendingVms(Guid vdsId, long t) throws InterruptedException { + try { getBlockingQueue(vdsId).poll(t, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { // ignore -- To view, visit http://gerrit.ovirt.org/13817 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic463bd0a1fe60fd4d491fe0b2e7e75c9b61a6cbc Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Yair Zaslavsky <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
