Author: mduerig
Date: Wed Jul 27 10:43:33 2016
New Revision: 1754240
URL: http://svn.apache.org/viewvc?rev=1754240&view=rev
Log:
OAK-4277: Finalise de-duplication caches
Configurable setting for NodeCache
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/NodeCache.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/NodeCache.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/NodeCache.java?rev=1754240&r1=1754239&r2=1754240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/NodeCache.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/NodeCache.java
Wed Jul 27 10:43:33 2016
@@ -36,8 +36,6 @@ import com.google.common.cache.CacheStat
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-// FIXME OAK-4277: Finalise de-duplication caches
-// implement configuration
/**
* Partial mapping of string keys to values of type {@link RecordId}. This is
* typically used for de-duplicating nodes that have already been persisted
and thus
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java?rev=1754240&r1=1754239&r2=1754240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreService.java
Wed Jul 27 10:43:33 2016
@@ -158,19 +158,33 @@ public class SegmentNodeStoreService ext
@Property(
intValue = 15000,
- label = "String deduplication cache size",
+ label = "String deduplication cache size (#items)",
description = "Maximum number of strings to keep in the
deduplication cache"
)
public static final String STRING_DEDUPLICATION_CACHE_SIZE =
"stringDeduplicationCache.size";
@Property(
intValue = 3000,
- label = "Template deduplication cache size",
+ label = "Template deduplication cache size (#items)",
description = "Maximum number of templates to keep in the
deduplication cache"
)
public static final String TEMPLATE_DEDUPLICATION_CACHE_SIZE =
"templateDeduplicationCache.size";
@Property(
+ intValue = 10000000,
+ label = "Node deduplication cache size (#items)",
+ description = "Maximum number of nodes to keep in the
deduplication cache"
+ )
+ public static final String NODE_DEDUPLICATION_CACHE_SIZE =
"nodeDeduplicationCache.size";
+
+ @Property(
+ intValue = 20,
+ label = "Node deduplication cache depth (#levels)",
+ description = "Maximum number of levels to keep in the node
deduplication cache"
+ )
+ public static final String NODE_DEDUPLICATION_CACHE_DEPTH =
"nodeDeduplicationCache.depth";
+
+ @Property(
byteValue = MEMORY_THRESHOLD_DEFAULT,
label = "Memory Multiplier",
description = "TarMK compaction available memory multiplier needed
to run compaction"
@@ -360,6 +374,8 @@ public class SegmentNodeStoreService ext
.withTemplateCacheSize(getTemplateCacheSize())
.withStringDeduplicationCacheSize(getStringDeduplicationCacheSize())
.withTemplateDeduplicationCacheSize(getTemplateDeduplicationCacheSize())
+
.withNodeDeduplicationCacheSize(getNodeDeduplicationCacheSize())
+ .withNodeDeduplicationDepth(getNodeDeduplicationDepth())
.withMaxFileSize(getMaxFileSize())
.withMemoryMapping(getMode().equals("64"))
.withGCMonitor(gcMonitor)
@@ -650,6 +666,14 @@ public class SegmentNodeStoreService ext
return
Integer.parseInt(getCacheSize(TEMPLATE_DEDUPLICATION_CACHE_SIZE));
}
+ private int getNodeDeduplicationCacheSize() {
+ return Integer.parseInt(getCacheSize(NODE_DEDUPLICATION_CACHE_SIZE));
+ }
+
+ private int getNodeDeduplicationDepth() {
+ return Integer.parseInt(getCacheSize(NODE_DEDUPLICATION_CACHE_DEPTH));
+ }
+
private String getMaxFileSizeProperty() {
String size = property(SIZE);
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java?rev=1754240&r1=1754239&r2=1754240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/WriterCacheManager.java
Wed Jul 27 10:43:33 2016
@@ -39,8 +39,6 @@ import com.google.common.base.Supplier;
import com.google.common.cache.CacheStats;
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
-// FIXME OAK-4277: Finalise de-duplication caches
-// implement configuration
/**
* Instances of this class manage the deduplication caches used
* by the {@link SegmentWriter} to avoid writing multiple copies
@@ -65,6 +63,20 @@ public abstract class WriterCacheManager
"oak.tar.templatesCacheSize", 3000);
/**
+ * Default capacity of the node cache.
+ * @see #getNodeCache(int)
+ */
+ public static final int DEFAULT_NODE_CACHE_CAPACITY = getInteger(
+ "oak.tar.nodeCacheCapacity", 1000000);
+
+ /**
+ * Default maximal depth of the node cache.
+ * @see #getNodeCache(int)
+ */
+ public static final int DEFAULT_NODE_CACHE_DEPTH = getInteger(
+ "oak.tar.nodeCacheDepth", 20);
+
+ /**
* @param generation
* @return cache for string records of the given {@code generation}.
*/
@@ -202,7 +214,7 @@ public abstract class WriterCacheManager
public Default() {
this(RecordCache.<String>factory(DEFAULT_STRING_CACHE_SIZE),
RecordCache.<Template>factory(DEFAULT_TEMPLATE_CACHE_SIZE),
- NodeCache.factory(1000000, 20));
+ NodeCache.factory(DEFAULT_NODE_CACHE_CAPACITY,
DEFAULT_NODE_CACHE_DEPTH));
}
private static class Generations<T> implements Iterable<T> {
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java?rev=1754240&r1=1754239&r2=1754240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/file/FileStoreBuilder.java
Wed Jul 27 10:43:33 2016
@@ -24,6 +24,8 @@ import static com.google.common.base.Pre
import static
org.apache.jackrabbit.oak.segment.CachingSegmentReader.DEFAULT_STRING_CACHE_MB;
import static
org.apache.jackrabbit.oak.segment.CachingSegmentReader.DEFAULT_TEMPLATE_CACHE_MB;
import static
org.apache.jackrabbit.oak.segment.SegmentCache.DEFAULT_SEGMENT_CACHE_MB;
+import static
org.apache.jackrabbit.oak.segment.WriterCacheManager.DEFAULT_NODE_CACHE_CAPACITY;
+import static
org.apache.jackrabbit.oak.segment.WriterCacheManager.DEFAULT_NODE_CACHE_DEPTH;
import static
org.apache.jackrabbit.oak.segment.WriterCacheManager.DEFAULT_STRING_CACHE_SIZE;
import static
org.apache.jackrabbit.oak.segment.WriterCacheManager.DEFAULT_TEMPLATE_CACHE_SIZE;
import static
org.apache.jackrabbit.oak.segment.compaction.SegmentGCOptions.defaultGCOptions;
@@ -73,6 +75,10 @@ public class FileStoreBuilder {
private int templateDeduplicationCacheSize = DEFAULT_TEMPLATE_CACHE_SIZE;
+ private int nodeDeduplicationCacheSize = DEFAULT_NODE_CACHE_CAPACITY;
+
+ private int nodeDeduplicationCacheDepth = DEFAULT_NODE_CACHE_DEPTH;
+
private boolean memoryMapping;
@Nonnull
@@ -83,7 +89,8 @@ public class FileStoreBuilder {
@Nonnull
private final EvictingWriteCacheManager cacheManager = new
EvictingWriteCacheManager(
- stringDeduplicationCacheSize, templateDeduplicationCacheSize);
+ stringDeduplicationCacheSize, templateDeduplicationCacheSize,
+ nodeDeduplicationCacheSize, nodeDeduplicationCacheDepth);
@Nonnull
private final DelegatingGCMonitor gcMonitor = new DelegatingGCMonitor();
@@ -234,6 +241,28 @@ public class FileStoreBuilder {
}
/**
+ * Number of items to keep in the node deduplication cache
+ * @param nodeDeduplicationCacheSize None negative cache size
+ * @return this instance
+ */
+ @Nonnull
+ public FileStoreBuilder withNodeDeduplicationCacheSize(int
nodeDeduplicationCacheSize) {
+ this.nodeDeduplicationCacheSize = nodeDeduplicationCacheSize;
+ return this;
+ }
+
+ /**
+ * Maximal depth of the node deduplication cache
+ * @param nodeDeduplicationCacheDepth
+ * @return this instance
+ */
+ @Nonnull
+ public FileStoreBuilder withNodeDeduplicationDepth(int
nodeDeduplicationCacheDepth) {
+ this.nodeDeduplicationCacheDepth = nodeDeduplicationCacheDepth;
+ return this;
+ }
+
+ /**
* Turn memory mapping on or off
* @param memoryMapping
* @return this instance
@@ -406,16 +435,19 @@ public class FileStoreBuilder {
", templateCacheSize=" + templateCacheSize +
", stringDeduplicationCacheSize=" +
stringDeduplicationCacheSize +
", templateDeduplicationCacheSize=" +
templateDeduplicationCacheSize +
+ ", nodeDeduplicationCacheSize=" + nodeDeduplicationCacheSize +
+ ", nodeDeduplicationCacheDepth=" + nodeDeduplicationCacheDepth
+
", memoryMapping=" + memoryMapping +
", gcOptions=" + gcOptions +
'}';
}
private static class EvictingWriteCacheManager extends
WriterCacheManager.Default {
- public EvictingWriteCacheManager( int stringCacheSize, int
templateCacheSize) {
+ public EvictingWriteCacheManager(int stringCacheSize, int
templateCacheSize,
+ int nodeCacheCapacity, int
nodeCacheDepth) {
super(RecordCache.<String>factory(stringCacheSize),
RecordCache.<Template>factory(templateCacheSize),
- NodeCache.factory(1000000, 20));
+ NodeCache.factory(nodeCacheCapacity, nodeCacheDepth));
}
void evictOldGeneration(final int newGeneration) {