Partition Validation Cache to improve loading time of cartridges' subscribe page
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/965cd25a Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/965cd25a Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/965cd25a Branch: refs/heads/4.0.0-grouping Commit: 965cd25adcad1c94497267a6303c9fdaf3d8942c Parents: bd3715d Author: Udara Liyanage <[email protected]> Authored: Mon Aug 18 14:58:11 2014 +0530 Committer: Udara Liyanage <[email protected]> Committed: Mon Aug 18 14:58:11 2014 +0530 ---------------------------------------------------------------------- .../impl/CloudControllerServiceImpl.java | 32 +++++++++++++++++++- .../runtime/FasterLookUpDataHolder.java | 31 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/965cd25a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java index 444440f..cfd18ca 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java @@ -200,6 +200,13 @@ public class CloudControllerServiceImpl implements CloudControllerService { Cartridge cartridge = null; if((cartridge = dataHolder.getCartridge(cartridgeType)) != null) { if (dataHolder.getCartridges().remove(cartridge)) { + // invalidate partition validation cache + dataHolder.removeFromCartridgeTypeToPartitionIds(cartridgeType); + + if (log.isDebugEnabled()) { + log.debug("Partition cache invalidated for cartridge "+cartridgeType); + } + persist(); // sends the service removed event @@ -1134,6 +1141,19 @@ public class CloudControllerServiceImpl implements CloudControllerService { public boolean validateDeploymentPolicy(String cartridgeType, Partition[] partitions) throws InvalidPartitionException, InvalidCartridgeTypeException { + Map<String, List<String>> validatedCache = dataHolder.getCartridgeTypeToPartitionIds(); + List<String> validatedPartitions = new ArrayList<String>(); + + if (validatedCache.containsKey(cartridgeType)) { + // cache hit for this cartridge + // get list of partitions + validatedPartitions = validatedCache.get(cartridgeType); + if (log.isDebugEnabled()) { + log.debug("Partition validation cache hit for cartridge type: "+cartridgeType); + } + + } + Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>(); @@ -1152,6 +1172,12 @@ public class CloudControllerServiceImpl implements CloudControllerService { Map<String, Future<IaasProvider>> jobList = new HashMap<String, Future<IaasProvider>>(); for (Partition partition : partitions) { + + if (validatedPartitions.contains(partition.getId())) { + // partition cache hit + continue; + } + Callable<IaasProvider> worker = new PartitionValidatorCallable( partition, cartridge); Future<IaasProvider> job = FasterLookUpDataHolder.getInstance() @@ -1165,8 +1191,12 @@ public class CloudControllerServiceImpl implements CloudControllerService { try { // add to a temporary Map partitionToIaasProviders.put(partitionId, job.get()); + + // add to cache + this.dataHolder.addToCartridgeTypeToPartitionIdMap(cartridgeType, partitionId); + if (log.isDebugEnabled()) { - log.debug("Partition "+partitionId+" added to the map."); + log.debug("Partition "+partitionId+" added to the cache against cartridge type: "+cartridgeType); } } catch (Exception e) { log.error(e.getMessage(), e); http://git-wip-us.apache.org/repos/asf/stratos/blob/965cd25a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java index 9b05b5d..e3162ba 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java @@ -66,6 +66,13 @@ public class FasterLookUpDataHolder implements Serializable{ private Map<String, ClusterContext> clusterIdToContext = new ConcurrentHashMap<String, ClusterContext>(); /** + * This works as a cache to hold already validated partitions against a cartridge type. + * Key - cartridge type + * Value - list of partition ids + */ + private Map<String, List<String>> cartridgeTypeToPartitionIds = new ConcurrentHashMap<String, List<String>>(); + + /** * Thread pool used in this task to execute parallel tasks. */ private transient ExecutorService executor = Executors.newFixedThreadPool(20); @@ -354,4 +361,28 @@ public class FasterLookUpDataHolder implements Serializable{ this.executor = executor; } + public Map<String, List<String>> getCartridgeTypeToPartitionIds() { + return cartridgeTypeToPartitionIds; + } + + public void setCartridgeTypeToPartitionIds( + Map<String, List<String>> cartridgeTypeToPartitionIds) { + this.cartridgeTypeToPartitionIds = cartridgeTypeToPartitionIds; + } + + public void addToCartridgeTypeToPartitionIdMap(String cartridgeType, String partitionId) { + List<String> list = this.cartridgeTypeToPartitionIds.get(cartridgeType); + + if(list == null) { + list = new ArrayList<String>(); + } + + list.add(partitionId); + this.cartridgeTypeToPartitionIds.put(cartridgeType, list); + } + + public void removeFromCartridgeTypeToPartitionIds(String cartridgeType) { + this.cartridgeTypeToPartitionIds.remove(cartridgeType); + } + } \ No newline at end of file
