Author: mreutegg
Date: Thu Feb 26 14:12:55 2015
New Revision: 1662450

URL: http://svn.apache.org/r1662450
Log:
OAK-2546: allow configuring subcaches of documentnodestore individually

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
    
jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1662450&r1=1662449&r2=1662450&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
 Thu Feb 26 14:12:55 2015
@@ -59,6 +59,8 @@ import org.apache.jackrabbit.oak.stats.C
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static com.google.common.base.Preconditions.checkArgument;
+
 /**
  * A MicroKernel implementation that stores the data in a {@link 
DocumentStore}.
  */
@@ -490,6 +492,10 @@ public class DocumentMK implements Micro
      */
     public static class Builder {
         private static final long DEFAULT_MEMORY_CACHE_SIZE = 256 * 1024 * 
1024;
+        public static final int DEFAULT_NODE_CACHE_PERCENTAGE = 25;
+        public static final int DEFAULT_CHILDREN_CACHE_PERCENTAGE = 10;
+        public static final int DEFAULT_DIFF_CACHE_PERCENTAGE = 5;
+        public static final int DEFAULT_DOC_CHILDREN_CACHE_PERCENTAGE = 3;
         private DocumentNodeStore nodeStore;
         private DocumentStore documentStore;
         private DiffCache diffCache;
@@ -499,11 +505,11 @@ public class DocumentMK implements Micro
         private boolean timing;
         private boolean logging;
         private Weigher<CacheValue, CacheValue> weigher = new 
EmpiricalWeigher();
-        private long nodeCacheSize;
-        private long childrenCacheSize;
-        private long diffCacheSize;
-        private long documentCacheSize;
-        private long docChildrenCacheSize;
+        private long memoryCacheSize = DEFAULT_MEMORY_CACHE_SIZE;
+        private int nodeCachePercentage = DEFAULT_NODE_CACHE_PERCENTAGE;
+        private int childrenCachePercentage = 
DEFAULT_CHILDREN_CACHE_PERCENTAGE;
+        private int diffCachePercentage = DEFAULT_DIFF_CACHE_PERCENTAGE;
+        private int docChildrenCachePercentage = 
DEFAULT_DOC_CHILDREN_CACHE_PERCENTAGE;
         private boolean useSimpleRevision;
         private long splitDocumentAgeMillis = 5 * 60 * 1000;
         private long offHeapCacheSize = -1;
@@ -515,7 +521,6 @@ public class DocumentMK implements Micro
         private PersistentCache persistentCache;
 
         public Builder() {
-            memoryCacheSize(DEFAULT_MEMORY_CACHE_SIZE);
         }
 
         /**
@@ -729,32 +734,46 @@ public class DocumentMK implements Micro
         }
 
         public Builder memoryCacheSize(long memoryCacheSize) {
-            this.nodeCacheSize = memoryCacheSize * 25 / 100;
-            this.childrenCacheSize = memoryCacheSize * 10 / 100;
-            this.diffCacheSize = memoryCacheSize * 5 / 100;
-            this.docChildrenCacheSize = memoryCacheSize * 3 / 100;
-            this.documentCacheSize = memoryCacheSize - nodeCacheSize - 
childrenCacheSize - diffCacheSize - docChildrenCacheSize;
+            this.memoryCacheSize = memoryCacheSize;
+            return this;
+        }
+        
+        public Builder memoryCacheDistribution(int nodeCachePercentage,
+                                               int childrenCachePercentage,
+                                               int docChildrenCachePercentage,
+                                               int diffCachePercentage) {
+            checkArgument(nodeCachePercentage >= 0);
+            checkArgument(childrenCachePercentage>= 0);
+            checkArgument(docChildrenCachePercentage >= 0);
+            checkArgument(diffCachePercentage >= 0);
+            checkArgument(nodeCachePercentage + childrenCachePercentage + 
+                    docChildrenCachePercentage + diffCachePercentage < 100);
+            this.nodeCachePercentage = nodeCachePercentage;
+            this.childrenCachePercentage = childrenCachePercentage;
+            this.docChildrenCachePercentage = docChildrenCachePercentage;
+            this.diffCachePercentage = diffCachePercentage;
             return this;
         }
 
         public long getNodeCacheSize() {
-            return nodeCacheSize;
+            return memoryCacheSize * nodeCachePercentage / 100;
         }
 
         public long getChildrenCacheSize() {
-            return childrenCacheSize;
+            return memoryCacheSize * childrenCachePercentage / 100;
         }
 
         public long getDocumentCacheSize() {
-            return documentCacheSize;
+            return memoryCacheSize - getNodeCacheSize() - 
getChildrenCacheSize() 
+                    - getDiffCacheSize() - getDocChildrenCacheSize();
         }
 
         public long getDocChildrenCacheSize() {
-            return docChildrenCacheSize;
+            return memoryCacheSize * docChildrenCachePercentage / 100;
         }
 
         public long getDiffCacheSize() {
-            return diffCacheSize;
+            return memoryCacheSize * diffCachePercentage / 100;
         }
 
         public Builder setUseSimpleRevision(boolean useSimpleRevision) {

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1662450&r1=1662449&r2=1662450&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
 Thu Feb 26 14:12:55 2015
@@ -22,6 +22,10 @@ import static com.google.common.base.Pre
 import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toBoolean;
 import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toInteger;
 import static org.apache.jackrabbit.oak.commons.PropertiesUtil.toLong;
+import static 
org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_CHILDREN_CACHE_PERCENTAGE;
+import static 
org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_DIFF_CACHE_PERCENTAGE;
+import static 
org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_DOC_CHILDREN_CACHE_PERCENTAGE;
+import static 
org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder.DEFAULT_NODE_CACHE_PERCENTAGE;
 import static 
org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean;
 
 import java.io.ByteArrayInputStream;
@@ -108,6 +112,18 @@ public class DocumentNodeStoreService {
 
     @Property(intValue = DEFAULT_CACHE)
     private static final String PROP_CACHE = "cache";
+    
+    @Property(intValue = DEFAULT_NODE_CACHE_PERCENTAGE)
+    private static final String PROP_NODE_CACHE_PERCENTAGE = 
"nodeCachePercentage";
+    
+    @Property(intValue = DocumentMK.Builder.DEFAULT_CHILDREN_CACHE_PERCENTAGE)
+    private static final String PROP_CHILDREN_CACHE_PERCENTAGE = 
"childrenCachePercentage";
+    
+    @Property(intValue = DocumentMK.Builder.DEFAULT_DIFF_CACHE_PERCENTAGE)
+    private static final String PROP_DIFF_CACHE_PERCENTAGE = 
"diffCachePercentage";
+    
+    @Property(intValue = 
DocumentMK.Builder.DEFAULT_DOC_CHILDREN_CACHE_PERCENTAGE)
+    private static final String PROP_DOC_CHILDREN_CACHE_PERCENTAGE = 
"docChildrenCachePercentage";
 
     @Property(intValue = DEFAULT_OFF_HEAP_CACHE)
     private static final String PROP_OFF_HEAP_CACHE = "offHeapCache";
@@ -238,6 +254,10 @@ public class DocumentNodeStoreService {
 
         int offHeapCache = toInteger(prop(PROP_OFF_HEAP_CACHE), 
DEFAULT_OFF_HEAP_CACHE);
         int cacheSize = toInteger(prop(PROP_CACHE), DEFAULT_CACHE);
+        int nodeCachePercentage = toInteger(prop(PROP_NODE_CACHE_PERCENTAGE), 
DEFAULT_NODE_CACHE_PERCENTAGE);
+        int childrenCachePercentage = 
toInteger(prop(PROP_CHILDREN_CACHE_PERCENTAGE), 
DEFAULT_CHILDREN_CACHE_PERCENTAGE);
+        int docChildrenCachePercentage = 
toInteger(prop(PROP_DOC_CHILDREN_CACHE_PERCENTAGE), 
DEFAULT_DOC_CHILDREN_CACHE_PERCENTAGE);
+        int diffCachePercentage = toInteger(prop(PROP_DIFF_CACHE_PERCENTAGE), 
DEFAULT_DIFF_CACHE_PERCENTAGE);
         int changesSize = toInteger(prop(PROP_CHANGES_SIZE), 
DEFAULT_CHANGES_SIZE);
         int blobCacheSize = toInteger(prop(PROP_BLOB_CACHE_SIZE), 
DEFAULT_BLOB_CACHE_SIZE);
         String persistentCache = 
PropertiesUtil.toString(prop(PROP_PERSISTENT_CACHE), DEFAULT_PERSISTENT_CACHE);
@@ -245,6 +265,11 @@ public class DocumentNodeStoreService {
         DocumentMK.Builder mkBuilder =
                 new DocumentMK.Builder().
                 memoryCacheSize(cacheSize * MB).
+                memoryCacheDistribution(
+                        nodeCachePercentage, 
+                        childrenCachePercentage, 
+                        docChildrenCachePercentage, 
+                        diffCachePercentage).
                 offHeapCacheSize(offHeapCache * MB);
         
         if (persistentCache != null && persistentCache.length() > 0) {

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1662450&r1=1662449&r2=1662450&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/resources/OSGI-INF/metatype/metatype.properties
 Thu Feb 26 14:12:55 2015
@@ -40,4 +40,16 @@ mongouri.name = Mongo URI
 mongouri.description = Represents a URI which can be used to create a 
MongoClient instance. \
   The URI describes the hosts to be used and options. Refer to \
   http://www.mongodb.org/display/DOCS/Connections for more details on format 
and options. It \
-  can be overridden through framework property 'oak.mongo.uri'
\ No newline at end of file
+  can be overridden through framework property 'oak.mongo.uri'
+
+nodeCachePercentage.name = Percentage of cache reserved for nodeCache.
+nodeCachePercentage.description = Percentage of cache reserved for nodeCache.
+
+childrenCachePercentage.name = Percentage of cache reserved for childrenCache.
+childrenCachePercentage.description = Percentage of cache reserved for 
childrenCache.
+
+diffCachePercentage.name = Percentage of cache reserved for diffCache.
+diffCachePercentage.description = Percentage of cache reserved for diffCache.
+
+docChildrenCachePercentage.name = Percentage of cache reserved for 
docChildrenCachePercentage.
+docChildrenCachePercentage.description = Percentage of cache reserved for 
docChildrenCachePercentage.
\ No newline at end of file


Reply via email to