Liran Zelkha has uploaded a new change for review. Change subject: (WIP) Added table for caching duration configuration. Added support for eliminating unneeded updates ......................................................................
(WIP) Added table for caching duration configuration. Added support for eliminating unneeded updates Change-Id: I5d56f04951608a669171f58717bb7f3de6df150f Signed-off-by: Liran Zelkha <[email protected]> --- A backend/manager/dbscripts/upgrade/03_03_0160_add_database_caching_table.sql M backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql M backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDynamicDAODbFacadeImpl.java 6 files changed, 95 insertions(+), 26 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/14972/1 diff --git a/backend/manager/dbscripts/upgrade/03_03_0160_add_database_caching_table.sql b/backend/manager/dbscripts/upgrade/03_03_0160_add_database_caching_table.sql new file mode 100644 index 0000000..8922393 --- /dev/null +++ b/backend/manager/dbscripts/upgrade/03_03_0160_add_database_caching_table.sql @@ -0,0 +1,28 @@ + +CREATE TABLE caching_configuration +( + id SERIAL CONSTRAINT caching_configuration_pk PRIMARY KEY, + name VARCHAR(4000) NOT NULL, + time_to_live_in_cache INTEGER +); + +Create or replace FUNCTION read_all_database_caching() RETURNS SETOF caching_configuration + AS $procedure$ +BEGIN +RETURN QUERY SELECT caching_configuration.* + FROM caching_configuration; +END; $procedure$ +LANGUAGE plpgsql; + +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.ActionGroup',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.ActionVersionMap',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.VDSGroup',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.VdsDynamic',30); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.VdsStatic',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.VmDynamic',30); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.VmStatic',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.VmTemplate',30); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.network.Network',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.network.NetworkCluster',30); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface',3000); +insert into caching_configuration(name,time_to_live_in_cache) values('org.ovirt.engine.core.compat.Guid',3000); diff --git a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql index 14779e6..9e45516 100644 --- a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql +++ b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql @@ -170,6 +170,13 @@ select fn_db_add_config_value('MigrationNetworkEnabled','false','3.2'); select fn_db_add_config_value('MigrationNetworkEnabled','true','3.3'); +-- Caching configuration +select fn_db_add_config_value('DatabaseCachingEnabled','false','3.0'); +select fn_db_add_config_value('DatabaseCachingEnabled','false','3.1'); +select fn_db_add_config_value('DatabaseCachingEnabled','false','3.2'); +select fn_db_add_config_value('DatabaseCachingEnabled','true','3.3'); + + -- by default use no proxy select fn_db_add_config_value('SpiceProxyDefault','','general'); diff --git a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java index f4e8d46..f7762f2 100644 --- a/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java +++ b/backend/manager/modules/compat/src/main/java/org/ovirt/engine/core/compat/NGuid.java @@ -19,6 +19,8 @@ public final static Guid Empty = new Guid(); + private static final UUID EMPTY_UUID = UUID.fromString(EMPTY_GUID_VALUE); + public static Guid NewGuid() { return new Guid(UUID.randomUUID()); } @@ -38,7 +40,8 @@ public NGuid(byte[] guid, boolean keepByteOrder) { String guidAsStr = getStrRepresentationOfGuid(guid, keepByteOrder); if (guidAsStr.isEmpty()) { - uuid = UUID.fromString(EMPTY_GUID_VALUE); + //uuid = UUID.fromString(EMPTY_GUID_VALUE); + uuid = EMPTY_UUID; } else { uuid = UUID.fromString(guidAsStr); } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java index 63e23a1..7c3a55b 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/CacheManager.java @@ -6,12 +6,13 @@ import java.util.Map; import java.util.WeakHashMap; +import org.ovirt.engine.core.common.businessentities.BusinessEntity; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; +import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.utils.log.Log; import org.ovirt.engine.core.utils.log.LogFactory; -//TODO: select fn_db_add_config_value('DatabaseCachingEnabled','true','general'); @SuppressWarnings("rawtypes") public class CacheManager { private static final Log log = LogFactory @@ -20,6 +21,7 @@ private Map<CacheKey, CacheItemWrapper> cache = new WeakHashMap<CacheKey, CacheItemWrapper>(); private Map<Class, List<CacheKey>> typeToKeymapping = new WeakHashMap<Class, List<CacheKey>>(); + private Map<Guid, BusinessEntity<Guid>> updateCache = new WeakHashMap<Guid,BusinessEntity<Guid>>(); private CacheManager() { @@ -141,5 +143,13 @@ typeToKeymapping.remove(updatedType); } } + + public BusinessEntity<Guid> getLastUpdated(Guid key) { + return updateCache.get(key); + } + + public void setLastUpdated(Guid key, BusinessEntity<Guid> value) { + updateCache.put(key, value); + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java index 3f2ff0f..251331f 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/cache/TimeToLiveManager.java @@ -1,39 +1,53 @@ package org.ovirt.engine.core.dal.cache; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.HashMap; +import java.util.List; import java.util.Map; -import org.ovirt.engine.core.common.businessentities.ActionGroup; -import org.ovirt.engine.core.common.businessentities.ActionVersionMap; -import org.ovirt.engine.core.common.businessentities.VDSGroup; -import org.ovirt.engine.core.common.businessentities.VdsDynamic; -import org.ovirt.engine.core.common.businessentities.VdsStatic; -import org.ovirt.engine.core.common.businessentities.VmDynamic; -import org.ovirt.engine.core.common.businessentities.VmStatic; -import org.ovirt.engine.core.common.businessentities.VmTemplate; -import org.ovirt.engine.core.common.businessentities.network.Network; -import org.ovirt.engine.core.common.businessentities.network.NetworkCluster; -import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; -import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.springframework.jdbc.core.RowMapper; public class TimeToLiveManager { + public class TimeToLiveItem { + private String className; + private int timeToLive; + public String getClassName() { + return className; + } + public void setClassName(String className) { + this.className = className; + } + public int getTimeToLive() { + return timeToLive; + } + public void setTimeToLive(int timeToLive) { + this.timeToLive = timeToLive; + } + + } + public static final int NO_CACHE = -1; private static TimeToLiveManager instance = new TimeToLiveManager(); private Map<String, Integer> timeToLiveMap = new HashMap<String, Integer>(); private TimeToLiveManager() { - timeToLiveMap.put(VdsDynamic.class.getName(), 30); - timeToLiveMap.put(VdsStatic.class.getName(), 3000); - timeToLiveMap.put(VDSGroup.class.getName(), 3000); - timeToLiveMap.put(VmStatic.class.getName(), 3000); - timeToLiveMap.put(VmDynamic.class.getName(), 30); - timeToLiveMap.put(VmTemplate.class.getName(), 30); - timeToLiveMap.put(VdsNetworkInterface.class.getName(), 3000); - timeToLiveMap.put(Guid.class.getName(), 3000); - timeToLiveMap.put(ActionGroup.class.getName(), 3000); - timeToLiveMap.put(ActionVersionMap.class.getName(), 3000); - timeToLiveMap.put(Network.class.getName(), 3000); - timeToLiveMap.put(NetworkCluster.class.getName(), 30); + + List<TimeToLiveItem> items = DbFacade.getInstance().getCallsHandler().executeReadList("read_all_database_caching", new RowMapper<TimeToLiveItem >() { + + @Override + public TimeToLiveItem mapRow(ResultSet rs, int rowNum) throws SQLException { + TimeToLiveItem item = new TimeToLiveItem(); + item.setClassName(rs.getString("name")); + item.setTimeToLive(rs.getInt("time_to_live_in_cache")); + return item; + } + }, null); + + for (TimeToLiveItem item : items) { + timeToLiveMap.put(item.getClassName(), item.getTimeToLive()); + } } public static TimeToLiveManager getInstance() { diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDynamicDAODbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDynamicDAODbFacadeImpl.java index f7dc842..9fecdc8 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDynamicDAODbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VdsDynamicDAODbFacadeImpl.java @@ -11,6 +11,7 @@ import org.ovirt.engine.core.common.businessentities.VdsTransparentHugePagesState; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.RpmVersion; +import org.ovirt.engine.core.dal.cache.CacheManager; import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; @@ -154,6 +155,10 @@ @Override public void update(VdsDynamic vds) { + + if (CacheManager.getInstance().getLastUpdated(vds.getId()) == vds) + return; + MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("cpu_cores", vds.getcpu_cores()) .addValue("cpu_threads", vds.getCpuThreads()) @@ -206,6 +211,8 @@ .addValue("hw_family", vds.getHardwareFamily()); getCallsHandler().executeModification("UpdateVdsDynamic", parameterSource); + + CacheManager.getInstance().setLastUpdated(vds.getId(), vds); } @Override -- To view, visit http://gerrit.ovirt.org/14972 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5d56f04951608a669171f58717bb7f3de6df150f Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
