Michael Kublin has uploaded a new change for review.

Change subject: engine: Introducing "cache" for ActionGroupDAO
......................................................................

engine: Introducing "cache" for ActionGroupDAO

The following patch is introducing a simle cache for ActionGroupDAO.
The following Dao only perfrom select operation from DB and never update 
operation.
The following query is running during each engine bll comand, so introducing a 
cache will decrease
dramaticly quries to DB.
In general I would prefer to use some third-party cache solution which can be 
integrated inside dao,
but because of it can some time, I just wrote something simple that should be 
good for now

Change-Id: I292ed3cba6075064e13ba8cee73c47a018fa568a
Signed-off-by: Michael Kublin <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ActionVersionMap.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ActionGroupDAODbFacadeImpl.java
2 files changed, 40 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/11546/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ActionVersionMap.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ActionVersionMap.java
index 803cfb2..f738c73 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ActionVersionMap.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/ActionVersionMap.java
@@ -22,6 +22,10 @@
     public ActionVersionMap() {
     }
 
+    public ActionVersionMap(boolean nullValue) {
+        this.nullValue = nullValue;
+    }
+
     public ActionVersionMap(VdcActionType actionType, String 
clusterMinimalVersion, String storagePoolMinimalVersion) {
         setaction_type(actionType);
         setcluster_minimal_version(clusterMinimalVersion);
@@ -66,6 +70,16 @@
         storagePoolMinimalVersion = value;
     }
 
+    private transient boolean nullValue;
+
+    public boolean isNullValue() {
+        return nullValue;
+    }
+
+    public void setNullValue(boolean nullValue) {
+        this.nullValue = nullValue;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ActionGroupDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ActionGroupDAODbFacadeImpl.java
index 5a7c7a2..8308da3 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ActionGroupDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/ActionGroupDAODbFacadeImpl.java
@@ -3,6 +3,8 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
@@ -17,6 +19,11 @@
  * The initial implementation came from  {@link 
org.ovirt.engine.core.dal.dbbroker.DbFacade}.
  */
 public class ActionGroupDAODbFacadeImpl extends BaseDAODbFacade implements 
ActionGroupDAO {
+
+    private static final ConcurrentMap<VdcActionType, ActionVersionMap> cache =
+            new ConcurrentHashMap<VdcActionType, ActionVersionMap>();
+    private static final ActionVersionMap nullActionVersionMap = new 
ActionVersionMap(true);
+
     @Override
     public List<ActionGroup> getAllForRole(Guid id) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
@@ -29,11 +36,28 @@
 
     @Override
     public ActionVersionMap getActionVersionMapByActionType(VdcActionType 
action_type) {
+        ActionVersionMap result = cache.get(action_type);
+        if (result != null) {
+            if (result.isNullValue()) {
+                return null;
+            }
+            return result;
+        }
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource().addValue("action_type", action_type);
 
-        return 
getCallsHandler().executeRead("Getaction_version_mapByaction_type",
+        result = 
getCallsHandler().executeRead("Getaction_version_mapByaction_type",
                 ActionVersionMapMapper.instance,
                 parameterSource);
+        if (result == null) {
+            cache.putIfAbsent(action_type, nullActionVersionMap);
+        } else {
+            cache.putIfAbsent(action_type, result);
+        }
+        result = cache.get(action_type);
+        if (result.isNullValue()) {
+            return null;
+        }
+        return result;
     }
 
     @Override
@@ -48,6 +72,7 @@
 
     @Override
     public void removeActionVersionMap(VdcActionType action_type) {
+        cache.remove(action_type);
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource().addValue("action_type", action_type);
         getCallsHandler().executeModification("Deleteaction_version_map", 
parameterSource);
     }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I292ed3cba6075064e13ba8cee73c47a018fa568a
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

Reply via email to