Skip to content

Commit

Permalink
OAK-4277: Finalise de-duplication caches
Browse files Browse the repository at this point in the history
Configurable setting for NodeCache

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1754240 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mduerig committed Jul 27, 2016
1 parent 32ee70f commit fe014bf
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
Expand Up @@ -36,8 +36,6 @@
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
Expand Down
Expand Up @@ -158,18 +158,32 @@ public class SegmentNodeStoreService extends ProxyNodeStore

@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",
Expand Down Expand Up @@ -360,6 +374,8 @@ private boolean registerSegmentStore() throws IOException {
.withTemplateCacheSize(getTemplateCacheSize())
.withStringDeduplicationCacheSize(getStringDeduplicationCacheSize())
.withTemplateDeduplicationCacheSize(getTemplateDeduplicationCacheSize())
.withNodeDeduplicationCacheSize(getNodeDeduplicationCacheSize())
.withNodeDeduplicationDepth(getNodeDeduplicationDepth())
.withMaxFileSize(getMaxFileSize())
.withMemoryMapping(getMode().equals("64"))
.withGCMonitor(gcMonitor)
Expand Down Expand Up @@ -650,6 +666,14 @@ private int getTemplateDeduplicationCacheSize() {
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);

Expand Down
Expand Up @@ -39,8 +39,6 @@
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
Expand All @@ -64,6 +62,20 @@ public abstract class WriterCacheManager {
public static final int DEFAULT_TEMPLATE_CACHE_SIZE = getInteger(
"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}.
Expand Down Expand Up @@ -202,7 +214,7 @@ public Default(
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> {
Expand Down
Expand Up @@ -24,6 +24,8 @@
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;
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -233,6 +240,28 @@ public FileStoreBuilder withTemplateDeduplicationCacheSize(int templateDeduplica
return this;
}

/**
* 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
Expand Down Expand Up @@ -406,16 +435,19 @@ public String toString() {
", 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) {
Expand Down

0 comments on commit fe014bf

Please sign in to comment.