ofri masad has posted comments on this change.

Change subject: core: Fast init cache
......................................................................


Patch Set 6: (11 inline comments)

Gilad, Current design uses Quartz to call the cache update every x minutes. the 
"factor" helps us determine if cache update is needed (for example: if the 
cache only covers about 60% of the quotas available in the DB, a massive cache 
update is needed).

....................................................
File backend/manager/dbscripts/create_functions.sql
Line 610: 
Line 611: -- Summarize the VCPU usage and the RAM usage for all the VMs in the 
quota which are not down or suspended
Line 612: -- If vds group id is null, then returns the global usage of the 
quota, otherwise returns only the sum of all VMs in the specific cluster.
Line 613: -- NOTE: VmDynamic status (0/13/14/15) must be persistent with 
UpdateVmCommand
Line 614: CREATE OR REPLACE FUNCTION CalculateAllVdsGroupUsage()
Done
Line 615: RETURNS SETOF all_vds_group_usage_rs
Line 616: AS $function$
Line 617: BEGIN
Line 618:     RETURN QUERY SELECT


Line 641: CREATE TYPE all_storage_usage_rs AS
Line 642:     (quota_storage_id UUID,quota_id UUID,storage_id UUID,storage_name 
character varying(250),storage_size_gb BIGINT,storage_size_gb_usage double 
precision);
Line 643: 
Line 644: 
Line 645: CREATE OR REPLACE FUNCTION CalculateAllStorageUsage()
Done
Line 646: RETURNS SETOF all_storage_usage_rs
Line 647: AS $function$
Line 648: BEGIN
Line 649:     -- Summarize size of all disks that are active.


....................................................
File backend/manager/dbscripts/quota_sp.sql
Line 70: Create or replace FUNCTION GetQuotaCount()
Line 71: RETURNS SETOF INTEGER
Line 72:    AS $procedure$
Line 73: BEGIN
Line 74:     RETURN QUERY SELECT cast(count(*) as INTEGER) as num_quota
Done
Line 75:     FROM quota;
Line 76: END; $procedure$
Line 77: LANGUAGE plpgsql;
Line 78: 


Line 73: BEGIN
Line 74:     RETURN QUERY SELECT cast(count(*) as INTEGER) as num_quota
Line 75:     FROM quota;
Line 76: END; $procedure$
Line 77: LANGUAGE plpgsql;
Yes but only if (cache size/GetQuotaCount()) > threshold
Line 78: 
Line 79: Create or replace FUNCTION GetQuotaStorageByQuotaGuid(v_id UUID)
Line 80: RETURNS SETOF quota_storage_view
Line 81:    AS $procedure$


....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Backend.java
Line 228:                 vmPoolMonitorIntervalInMinutes, TimeUnit.MINUTES);
Line 229: 
Line 230:         int quotaCacheIntervalInMinutes = Config.<Integer> 
GetValue(ConfigValues.QuotaCacheIntervalInMinutes);
Line 231:         
SchedulerUtilQuartzImpl.getInstance().scheduleAFixedDelayJob(QuotaManager.getInstance(),
Line 232:                 "initializeCache",  new Class[] {}, new Object[] {},
Done
Line 233:                 1, quotaCacheIntervalInMinutes, TimeUnit.MINUTES);
Line 234: 
Line 235:         try {
Line 236:             File fLock = new File(Config.<String> 
GetValue(ConfigValues.SignLockFile));


....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
Line 30: 
Line 31:     private static final QuotaManagerAuditLogger 
quotaManagerAuditLogger = new QuotaManagerAuditLogger();
Line 32:     private List<QuotaConsumptionParameter> corruptedParameters = new 
ArrayList<QuotaConsumptionParameter>();
Line 33:     private static final double MINIMUM_CACHE_FACTOR =
Line 34:             (double) Config.<Integer> 
GetValue(ConfigValues.MinimumPercentageToUpdateQuotaCache) / 100;
Done
Line 35: 
Line 36:     public static QuotaManager getInstance() {
Line 37:         return INSTANCE;
Line 38:     }


Line 986: 
Line 987:     /**
Line 988:      * InitializeCache is called by SchedulerUtilQuartzImpl.
Line 989:      */
Line 990:     @OnTimerMethodAnnotation("initializeCache")
Done
Line 991:     public void initializeCache() {
Line 992:         if (!isNeedToInitializeCache()) {
Line 993:             return;
Line 994:         }


Line 992:         if (!isNeedToInitializeCache()) {
Line 993:             return;
Line 994:         }
Line 995: 
Line 996:         log.info("Updating Quota Cache...");
Done
Line 997:         long timeStart = System.currentTimeMillis();
Line 998:         List<Quota> allQuotaIncludingConsumption = 
getQuotaDAO().getAllQuotaIncludingConsumption();
Line 999: 
Line 1000:         if (allQuotaIncludingConsumption.isEmpty()) {


Line 1015:         long timeEnd = System.currentTimeMillis();
Line 1016:         log.infoFormat("Quota Cache updated. ({0} msec)", 
timeEnd-timeStart);
Line 1017:     }
Line 1018: 
Line 1019:     public boolean isNeedToInitializeCache() {
Done
Line 1020:         int quotaCount = getQuotaDAO().getQuotaCount();
Line 1021:         int cacheCount = 0;
Line 1022: 
Line 1023:         lock.readLock().lock();


....................................................
File 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/QuotaDAODbFacadeImpl.java
Line 185: 
Line 186:     @Override
Line 187:     public int getQuotaCount() {
Line 188:         MapSqlParameterSource parameterSource = new 
MapSqlParameterSource();
Line 189:         return getCallsHandler().executeRead("GetQuotaCount", new 
ParameterizedRowMapper<Integer>() {
Done
Line 190:             @Override
Line 191:             public Integer mapRow(ResultSet resultSet, int i) throws 
SQLException {
Line 192:                 return (Integer) resultSet.getObject(1);
Line 193:             }


Line 212:                 allQuotaMap.put(quota.getId(), quota);
Line 213:             }
Line 214: 
Line 215:             List<QuotaStorage> quotaStorageList = 
getAllQuotaStorageIncludingConsumption();
Line 216:             List<QuotaVdsGroup> quotaVdsGroupList = 
getALLQuotaVdsGroupIncludingConsumption();
Done
Line 217: 
Line 218:             if (quotaStorageList != null) {
Line 219:                 for (QuotaStorage quotaStorage : quotaStorageList) {
Line 220:                     Quota quota = 
allQuotaMap.get(quotaStorage.getQuotaId());


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

Gerrit-MessageType: comment
Gerrit-Change-Id: Id3db08957e413d2f1e0480b764334dd7268c8221
Gerrit-PatchSet: 6
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: ofri masad <oma...@redhat.com>
Gerrit-Reviewer: Doron Fediuck <dfedi...@redhat.com>
Gerrit-Reviewer: Eli Mesika <emes...@redhat.com>
Gerrit-Reviewer: Gilad Chaplik <gchap...@redhat.com>
Gerrit-Reviewer: Michael Kublin <mkub...@redhat.com>
Gerrit-Reviewer: Yair Zaslavsky <yzasl...@redhat.com>
Gerrit-Reviewer: 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