ofri masad has uploaded a new change for review.

Change subject: core: Fix QuotaManager internal rollback
......................................................................

core: Fix QuotaManager internal rollback

When two or more VDSGroup quota request were sent to the QuotaManager
together and one consumption request failed - the QuotaMAnager didnot
roll back the requests that already passed.

Added a rollback for the VDSGroup quotas if one request failed.

Change-Id: I3cee6810900c17f64d6ae47056969e656b1a4840
Bug-Url: https://bugzilla.redhat.com/950926
Signed-off-by: Ofri Masad <oma...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
1 file changed, 40 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/82/13982/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
index 3a2c316..d332bc7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
@@ -401,6 +401,8 @@
     private boolean 
validateAndSetClusterQuota(QuotaConsumptionParametersWrapper parameters,
             Pair<AuditLogType, AuditLogableBase> auditLogPair) {
         boolean result = true;
+
+        List<QuotaVdsGroupConsumptionParameter> executed = new 
ArrayList<QuotaVdsGroupConsumptionParameter>();
         for (QuotaConsumptionParameter parameter : parameters.getParameters()) 
{
             QuotaVdsGroupConsumptionParameter vdsGroupConsumptionParameter;
             if (parameter.getParameterType() != 
QuotaConsumptionParameter.ParameterType.VDS_GROUP) {
@@ -435,7 +437,7 @@
                     vdsGroupConsumptionParameter.getQuotaAction() == 
QuotaConsumptionParameter.QuotaAction.CONSUME ?
                     vdsGroupConsumptionParameter.getRequestedCpu() : 
-vdsGroupConsumptionParameter.getRequestedCpu();
 
-            if (!checkQuotaClusterLimits(
+            if (checkQuotaClusterLimits(
                     
parameters.getAuditLogable().getStoragePool().getQuotaEnforcementType(),
                     quota,
                     quotaVdsGroup,
@@ -443,13 +445,50 @@
                     requestedCpu,
                     parameters.getCanDoActionMessages(),
                     auditLogPair)) {
+                executed.add(vdsGroupConsumptionParameter);
+            } else {
                 result = false;
                 break;
             }
         }
+
+        //if result is false (one or more parameters did not pass) - roll back 
the parameters that did pass
+        if(!result) {
+            rollBackVdsGroupConsumptionParameters(executed);
+        }
+
         return result;
     }
 
+    private void 
rollBackVdsGroupConsumptionParameters(List<QuotaVdsGroupConsumptionParameter> 
executed) {
+        for (QuotaVdsGroupConsumptionParameter parameter : executed) {
+            long requestedMemory =
+                    parameter.getQuotaAction() == 
QuotaConsumptionParameter.QuotaAction.CONSUME ?
+                            -parameter.getRequestedMemory() : 
parameter.getRequestedMemory();
+            int requestedCpu =
+                    parameter.getQuotaAction() == 
QuotaConsumptionParameter.QuotaAction.CONSUME ?
+                            -parameter.getRequestedCpu() : 
parameter.getRequestedCpu();
+
+            QuotaVdsGroup quotaVdsGroup = null;
+            Quota quota = parameter.getQuota();
+            if (quota.getGlobalQuotaVdsGroup() != null) { // global cluster 
quota
+                quotaVdsGroup = quota.getGlobalQuotaVdsGroup();
+            } else {
+                for (QuotaVdsGroup vdsGroup : quota.getQuotaVdsGroups()) {
+                    if 
(vdsGroup.getVdsGroupId().equals(parameter.getVdsGroupId())) {
+                        quotaVdsGroup = vdsGroup;
+                        break;
+                    }
+                }
+            }
+
+            // quotaVdsGroup cannot be null - otherwise the parameter could 
not have been executed
+            long newMemory = requestedMemory + 
quotaVdsGroup.getMemSizeMBUsage();
+            int newVcpu = requestedCpu + quotaVdsGroup.getVirtualCpuUsage();
+            cacheNewValues(quotaVdsGroup, newMemory, newVcpu);
+        }
+    }
+
     /**
      * Roll back quota by VM id. the VM is fetched from DB and the quota is 
rolled back
      * @param vmId - id for the vm


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

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

Reply via email to