Author: mreutegg
Date: Mon Jan 22 12:41:37 2018
New Revision: 1821856
URL: http://svn.apache.org/viewvc?rev=1821856&view=rev
Log:
OAK-7176: Reduce cache misses on local diff-cache
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractJournalTest.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1821856&r1=1821855&r2=1821856&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
Mon Jan 22 12:41:37 2018
@@ -600,7 +600,7 @@ public final class DocumentNodeStore
nodeChildrenCacheStats = new CacheStats(nodeChildrenCache,
"Document-NodeChildren",
builder.getWeigher(), builder.getChildrenCacheSize());
- diffCache = builder.getDiffCache();
+ diffCache = builder.getDiffCache(this.clusterId);
checkpoints = new Checkpoints(this);
// check if root node exists
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java?rev=1821856&r1=1821855&r2=1821856&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
Mon Jan 22 12:41:37 2018
@@ -266,9 +266,9 @@ public class DocumentNodeStoreBuilder<T
return documentStoreSupplier.get();
}
- public DiffCache getDiffCache() {
+ public DiffCache getDiffCache(int clusterId) {
if (diffCache == null) {
- diffCache = new TieredDiffCache(this);
+ diffCache = new TieredDiffCache(this, clusterId);
}
return diffCache;
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java?rev=1821856&r1=1821855&r2=1821856&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
Mon Jan 22 12:41:37 2018
@@ -19,9 +19,14 @@ package org.apache.jackrabbit.oak.plugin
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Iterables;
import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
+
+import static
org.apache.jackrabbit.oak.plugins.document.util.Utils.isLocalChange;
/**
* Implements a tiered diff cache which consists of a {@link LocalDiffCache}
and
@@ -29,10 +34,19 @@ import org.apache.jackrabbit.oak.cache.C
*/
class TieredDiffCache extends DiffCache {
+ /**
+ * A small cache of local diff cache misses to prevent repeated calls with
+ * the same revision vector range.
+ */
+ private Cache<RevisionsKey, RevisionsKey> localDiffMisses
+ = CacheBuilder.newBuilder().maximumSize(128).build();
+
+ private final int clusterId;
private final DiffCache localCache;
private final DiffCache memoryCache;
- TieredDiffCache(DocumentNodeStoreBuilder<?> builder) {
+ TieredDiffCache(DocumentNodeStoreBuilder<?> builder, int clusterId) {
+ this.clusterId = clusterId;
this.localCache = new LocalDiffCache(builder);
this.memoryCache = new MemoryDiffCache(builder);
}
@@ -42,10 +56,21 @@ class TieredDiffCache extends DiffCache
@Nonnull RevisionVector to,
@Nonnull String path,
@Nullable Loader loader) {
- // check local first without loader
- String changes = localCache.getChanges(from, to, path, null);
- if (changes != null) {
- return changes;
+ // do not check local cache when changes are external
+ if (isLocalChange(from, to, clusterId)) {
+ // do not read from the localCache when there was a previous miss
+ // with the same key
+ RevisionsKey k = new RevisionsKey(from, to);
+ if (localDiffMisses.getIfPresent(k) == null) {
+ // check local without loader and fallback to
+ // memory cache when there is a cache miss
+ String changes = localCache.getChanges(from, to, path, null);
+ if (changes != null) {
+ return changes;
+ }
+ // remember cache miss
+ localDiffMisses.put(k, k);
+ }
}
return memoryCache.getChanges(from, to, path, loader);
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractJournalTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractJournalTest.java?rev=1821856&r1=1821855&r2=1821856&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractJournalTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractJournalTest.java
Mon Jan 22 12:41:37 2018
@@ -203,7 +203,7 @@ public abstract class AbstractJournalTes
}
@Override
- public DiffCache getDiffCache() {
+ public DiffCache getDiffCache(int clusterId) {
if (actualDiffCache==null) {
actualDiffCache = new CountingDiffCache(this);
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java?rev=1821856&r1=1821855&r2=1821856&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreIT.java
Mon Jan 22 12:41:37 2018
@@ -118,7 +118,7 @@ public class DocumentNodeStoreIT extends
private class TestBuilder extends DocumentNodeStoreBuilder<TestBuilder> {
@Override
- public DiffCache getDiffCache() {
+ public DiffCache getDiffCache(int clusterId) {
return AmnesiaDiffCache.INSTANCE;
}
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java?rev=1821856&r1=1821855&r2=1821856&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
Mon Jan 22 12:41:37 2018
@@ -51,7 +51,6 @@ import org.apache.jackrabbit.oak.stats.M
import org.apache.jackrabbit.oak.stats.StatisticsProvider;
import org.apache.jackrabbit.oak.stats.StatsOptions;
import org.junit.After;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -181,7 +180,6 @@ public class NodeCacheTest {
assertEquals(requests, stats.getCount());
}
- @Ignore
@Test
public void localDiffCache() throws Exception {
initializeNodeStore(false);