incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1565142 - in /sling/trunk/bundles/resourceresolver/src: main/java/org/apache/sling/resourceresolver/impl/ main/java/org/apache/sling/resourceresolver/impl/mapping/ test/java/org/apache/sling/resourceresolver/impl/mapping/
Date Thu, 06 Feb 2014 10:12:47 GMT
Author: asanso
Date: Thu Feb  6 10:12:46 2014
New Revision: 1565142

URL: http://svn.apache.org/r1565142
Log:
SLING-3332 - Long startup time with many sling:alias

* applied patch. The alias optimization introduced in SLING-2521 can be turned off in particular
cases (e.g. huge number of alias entries)

Modified:
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
    sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
    sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java?rev=1565142&r1=1565141&r2=1565142&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/CommonResourceResolverFactoryImpl.java
Thu Feb  6 10:12:46 2014
@@ -192,4 +192,8 @@ public class CommonResourceResolverFacto
     public boolean isVanityPathEnabled() {
         return this.activator.isVanityPathEnabled();
     }
+    
+    public boolean isOptimizeAliasResolutionEnabled() {
+        return this.activator.isOptimizeAliasResolutionEnabled();
+    }
 }
\ No newline at end of file

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java?rev=1565142&r1=1565141&r2=1565142&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryActivator.java
Thu Feb  6 10:12:46 2014
@@ -187,6 +187,14 @@ public class ResourceResolverFactoryActi
               description = "This flag controls whether all resources with a sling:vanityPath
property " +
                             "are processed and added to the mappoing table.")
     private static final String PROP_ENABLE_VANITY_PATH = "resource.resolver.enable.vanitypath";
+    
+    private static final boolean DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION = true;
+    @Property(boolValue = DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION ,
+              label = "Optimize alias resolution",
+              description ="This flag controls whether to optimize" +
+                      " the alias resolution by creating an internal cache of aliases. This
might have an impact on the startup time"+
+                      " and on the alias update time if the number of aliases is huge (over
10000).")
+    private static final String PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION = "resource.resolver.optimize.alias.resolution";
 
     // name of the Features service reference
     private static final String FEATURES_NAME = "features";
@@ -257,6 +265,9 @@ public class ResourceResolverFactoryActi
 
     /** vanityPath enabled? */
     private boolean enableVanityPath = DEFAULT_ENABLE_VANITY_PATH;
+    
+    /** alias resource resolution optimization enabled? */
+    private boolean enableOptimizeAliasResolution = DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION;
 
     private final FactoryPreconditions preconds = new FactoryPreconditions();
 
@@ -326,6 +337,10 @@ public class ResourceResolverFactoryActi
     public boolean isVanityPathEnabled() {
         return this.enableVanityPath;
     }
+    
+    public boolean isOptimizeAliasResolutionEnabled() {
+        return this.enableOptimizeAliasResolution;
+    }
 
     // ---------- SCR Integration ---------------------------------------------
 
@@ -390,6 +405,8 @@ public class ResourceResolverFactoryActi
         defaultVanityPathRedirectStatus = PropertiesUtil.toInteger(properties.get(PROP_DEFAULT_VANITY_PATH_REDIRECT_STATUS),
                                                                    MapEntries.DEFAULT_DEFAULT_VANITY_PATH_REDIRECT_STATUS);
         this.enableVanityPath = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_VANITY_PATH),
DEFAULT_ENABLE_VANITY_PATH);
+        
+        this.enableOptimizeAliasResolution = PropertiesUtil.toBoolean(properties.get(PROP_ENABLE_OPTIMIZE_ALIAS_RESOLUTION),
DEFAULT_ENABLE_OPTIMIZE_ALIAS_RESOLUTION);
 
         final BundleContext bc = componentContext.getBundleContext();
 

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java?rev=1565142&r1=1565141&r2=1565142&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
Thu Feb  6 10:12:46 2014
@@ -882,23 +882,44 @@ public class ResourceResolverImpl extend
 
         // we do not have a child with the exact name, so we look for
         // a child, whose alias matches the childName
-
-        final Map<String, String> aliases = factory.getMapEntries().getAliasMap(parent.getPath());
-        if (aliases != null) {
-            final String aliasName = aliases.get(childName);
-            if (aliasName != null ) {
-                final String aliasPath;
-                if ( aliasName.startsWith("/") ) {
-                    aliasPath = aliasName;
-                } else {
-                    aliasPath = parent.getPath() + '/' + aliasName;
+        if (factory.getMapEntries().isOptimizeAliasResolutionEnabled()){
+            logger.debug("getChildInternal: Optimize Alias Resolution is Enabled");
+            //optimization made in SLING-2521
+            final Map<String, String> aliases = factory.getMapEntries().getAliasMap(parent.getPath());
+            if (aliases != null) {
+                final String aliasName = aliases.get(childName);
+                if (aliasName != null ) {
+                    final String aliasPath;
+                    if ( aliasName.startsWith("/") ) {
+                        aliasPath = aliasName;
+                    } else {
+                        aliasPath = parent.getPath() + '/' + aliasName;
+                    }
+                    final Resource aliasedChild = getResourceInternal( ResourceUtil.normalize(aliasPath)
);
+                    logger.debug("getChildInternal: Found Resource {} with alias {} to use",
aliasedChild, childName);
+                    return aliasedChild;
+                }
+            }
+        } else {
+            logger.debug("getChildInternal: Optimize Alias Resolution is Disabled");
+            final Iterator<Resource> children = listChildren(parent);
+            while (children.hasNext()) {
+                child = children.next();
+                if (!child.getPath().endsWith(JCR_CONTENT_LEAF)) {
+                    final String[] aliases = ResourceResolverContext.getProperty(child, PROP_ALIAS,
String[].class);
+                    if (aliases != null) {
+                        for (final String alias : aliases) {
+                            if (childName.equals(alias)) {
+                                logger.debug("getChildInternal: Found Resource {} with alias
{} to use", child, childName);
+                                final Resource aliasedChild = getResourceInternal( ResourceUtil.normalize(child.getPath())
);
+                                return aliasedChild; 
+                            }
+                        }
+                    }
                 }
-                final Resource aliasedChild = getResourceInternal( ResourceUtil.normalize(aliasPath)
);
-                logger.debug("getChildInternal: Found Resource {} with alias {} to use",
aliasedChild, childName);
-                return aliasedChild;
             }
         }
-
+ 
         // no match for the childName found
         logger.debug("getChildInternal: Resource {} has no child {}", parent, childName);
         return null;

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java?rev=1565142&r1=1565141&r2=1565142&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapConfigurationProvider.java
Thu Feb  6 10:12:46 2014
@@ -38,4 +38,6 @@ public interface MapConfigurationProvide
     int getDefaultVanityPathRedirectStatus();
 
     boolean isVanityPathEnabled();
+    
+    public boolean isOptimizeAliasResolutionEnabled();
 }

Modified: sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java?rev=1565142&r1=1565141&r2=1565142&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java
Thu Feb  6 10:12:46 2014
@@ -109,6 +109,8 @@ public class MapEntries implements Event
     private final ReentrantLock initializing = new ReentrantLock();
 
     private final boolean enabledVanityPaths;
+    
+    private final boolean enableOptimizeAliasResolution;
 
     @SuppressWarnings("unchecked")
     private MapEntries() {
@@ -123,6 +125,7 @@ public class MapEntries implements Event
         this.registration = null;
         this.eventAdmin = null;
         this.enabledVanityPaths = true;
+        this.enableOptimizeAliasResolution = true;
     }
 
     @SuppressWarnings("unchecked")
@@ -132,6 +135,7 @@ public class MapEntries implements Event
         this.factory = factory;
         this.mapRoot = factory.getMapRoot();
         this.enabledVanityPaths = factory.isVanityPathEnabled();
+        this.enableOptimizeAliasResolution = factory.isOptimizeAliasResolutionEnabled();
         this.eventAdmin = eventAdmin;
 
         this.resolveMapsMap = Collections.singletonMap(GLOBAL_LIST_KEY, (List<MapEntry>)Collections.EMPTY_LIST);
@@ -216,14 +220,17 @@ public class MapEntries implements Event
             // sort global list and add to map
             Collections.sort(globalResolveMap);
             newResolveMapsMap.put(GLOBAL_LIST_KEY, globalResolveMap);
-
-            final Map<String, Map<String, String>> aliasMap = this.loadAliases(resolver);
+            
+            //optimization made in SLING-2521
+            if (enableOptimizeAliasResolution){
+                final Map<String, Map<String, String>> aliasMap = this.loadAliases(resolver);
+                this.aliasMap = makeUnmodifiableMap(aliasMap);
+            }            
 
             this.vanityTargets = Collections.unmodifiableCollection(vanityTargets);
             this.resolveMapsMap = Collections.unmodifiableMap(newResolveMapsMap);
             this.mapMaps = Collections.unmodifiableSet(new TreeSet<MapEntry>(newMapMaps.values()));
-            this.aliasMap = makeUnmodifiableMap(aliasMap);
-
+ 
             sendChangeEvent();
 
         } catch (final Exception e) {
@@ -236,6 +243,11 @@ public class MapEntries implements Event
 
         }
     }
+    
+    public boolean isOptimizeAliasResolutionEnabled(){
+        return this.enableOptimizeAliasResolution;
+    }
+    
 
     private <K1, K2, V> Map<K1, Map<K2, V>> makeUnmodifiableMap(final Map<K1,
Map<K2, V>> map) {
         final Map<K1, Map<K2, V>> newMap = new HashMap<K1, Map<K2, V>>();

Modified: sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java?rev=1565142&r1=1565141&r2=1565142&view=diff
==============================================================================
--- sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
(original)
+++ sling/trunk/bundles/resourceresolver/src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntriesTest.java
Thu Feb  6 10:12:46 2014
@@ -68,6 +68,7 @@ public class MapEntriesTest {
 
         when(resourceResolverFactory.getAdministrativeResourceResolver(null)).thenReturn(resourceResolver);
         when(resourceResolverFactory.isVanityPathEnabled()).thenReturn(true);
+        when(resourceResolverFactory.isOptimizeAliasResolutionEnabled()).thenReturn(true);
         when(resourceResolver.findResources(anyString(), eq("sql"))).thenReturn(
                 Collections.<Resource> emptySet().iterator());
 



Mime
View raw message