You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by da...@apache.org on 2026/04/14 18:22:42 UTC
(jackrabbit-oak) 01/01: OAK-12156 : removed guava cache from oak-store-document caches
This is an automated email from the ASF dual-hosted git repository.
daim pushed a commit to branch OAK-12156
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 4e9d4bb91eaeb9454e14ba5ab4c6e9317d4df089
Author: rishabhdaim <ri...@gmail.com>
AuthorDate: Tue Apr 14 23:52:22 2026 +0530
OAK-12156 : removed guava cache from oak-store-document caches
---
.../oak/plugins/document/DocumentNodeStore.java | 51 +++++-------
.../plugins/document/DocumentNodeStoreBuilder.java | 97 +++++++++-------------
.../plugins/document/DocumentNodeStoreService.java | 3 +-
.../oak/plugins/document/DocumentStore.java | 4 +-
.../oak/plugins/document/NodeDocument.java | 2 +-
.../plugins/document/cache/NodeDocumentCache.java | 48 ++++-------
.../document/memory/MemoryDocumentStore.java | 4 +-
.../plugins/document/mongo/MongoDocumentStore.java | 19 +----
.../document/persistentCache/NodeCache.java | 57 +++++--------
.../document/persistentCache/PersistentCache.java | 2 +-
.../oak/plugins/document/rdb/RDBDocumentStore.java | 69 +++++++--------
.../util/LeaseCheckDocumentStoreWrapper.java | 4 +-
.../document/util/LoggingDocumentStoreWrapper.java | 8 +-
.../util/SynchronizingDocumentStoreWrapper.java | 4 +-
.../util/ThrottlingDocumentStoreWrapper.java | 4 +-
.../document/util/TimingDocumentStoreWrapper.java | 6 +-
.../oak/plugins/document/AsyncCacheTest.java | 2 +-
.../plugins/document/CountingDocumentStore.java | 4 +-
.../oak/plugins/document/DisableCacheTest.java | 5 +-
.../plugins/document/DocumentMKBuilderTest.java | 8 +-
.../document/DocumentNodeStoreBuilderTest.java | 4 +-
.../oak/plugins/document/DocumentStoreWrapper.java | 4 +-
.../oak/plugins/document/PreviousDocCacheTest.java | 14 ++--
.../oak/plugins/document/Sweep2Test.java | 2 +-
.../document/VersionGarbageCollectorIT.java | 2 +-
.../document/cache/CacheChangesTrackerTest.java | 24 ++----
.../document/cache/NodeDocumentCacheTest.java | 31 +++----
.../oak/plugins/document/mongo/JournalIT.java | 4 +-
.../document/mongo/MongoRevisionGCTest.java | 2 +-
.../document/persistentCache/AsyncQueueTest.java | 12 +--
.../document/persistentCache/BroadcastTest.java | 5 +-
.../document/persistentCache/CacheTest.java | 9 +-
.../PersistentCacheCompatibilityTest.java | 19 ++---
33 files changed, 221 insertions(+), 312 deletions(-)
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
index 2312b52451..e469fddec2 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
@@ -56,10 +56,8 @@ import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -74,12 +72,11 @@ import java.util.function.Supplier;
import javax.jcr.PropertyType;
import org.apache.commons.lang3.StringUtils;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
-import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.commons.PerfLogger;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
@@ -422,7 +419,7 @@ public final class DocumentNodeStore
* Key: PathRev, value: DocumentNodeState
*/
private final Cache<PathRev, DocumentNodeState> nodeCache;
- private final CacheStats nodeCacheStats;
+ private final AbstractCacheStats nodeCacheStats;
/**
* Child node cache.
@@ -430,7 +427,7 @@ public final class DocumentNodeStore
* Key: PathRev, value: Children
*/
private final Cache<NamePathRev, DocumentNodeState.Children> nodeChildrenCache;
- private final CacheStats nodeChildrenCacheStats;
+ private final AbstractCacheStats nodeChildrenCacheStats;
/**
* The change log to keep track of commits for diff operations.
@@ -680,12 +677,10 @@ public final class DocumentNodeStore
//TODO Make stats collection configurable as it add slight overhead
nodeCache = builder.buildNodeCache(this);
- nodeCacheStats = new CacheStats(nodeCache, "Document-NodeState",
- builder.getWeigher(), builder.getNodeCacheSize());
+ nodeCacheStats = builder.newCacheStatsAdapter(nodeCache, "Document-NodeState", builder.getNodeCacheSize());
nodeChildrenCache = builder.buildChildrenCache(this);
- nodeChildrenCacheStats = new CacheStats(nodeChildrenCache, "Document-NodeChildren",
- builder.getWeigher(), builder.getChildrenCacheSize());
+ nodeChildrenCacheStats = builder.newCacheStatsAdapter(nodeChildrenCache, "Document-NodeChildren", builder.getChildrenCacheSize());
diffCache = builder.getDiffCache(this.clusterId);
@@ -1297,11 +1292,11 @@ public final class DocumentNodeStore
return clusterNodeInfo;
}
- public CacheStats getNodeCacheStats() {
+ public AbstractCacheStats getNodeCacheStats() {
return nodeCacheStats;
}
- public CacheStats getNodeChildrenCacheStats() {
+ public AbstractCacheStats getNodeChildrenCacheStats() {
return nodeChildrenCacheStats;
}
@@ -1395,25 +1390,22 @@ public final class DocumentNodeStore
final long start = PERFLOG.start();
try {
PathRev key = new PathRev(path, rev);
- DocumentNodeState node = nodeCache.get(key, new Callable<DocumentNodeState>() {
- @Override
- public DocumentNodeState call() throws Exception {
- boolean nodeDoesNotExist = checkNodeNotExistsFromChildrenCache(path, rev);
- if (nodeDoesNotExist){
- return missing;
- }
- DocumentNodeState n = readNode(path, rev);
- if (n == null) {
- n = missing;
- }
- return n;
+ DocumentNodeState node = nodeCache.get(key, k -> {
+ boolean nodeDoesNotExist = checkNodeNotExistsFromChildrenCache(path, rev);
+ if (nodeDoesNotExist){
+ return missing;
}
+ DocumentNodeState n = readNode(path, rev);
+ if (n == null) {
+ n = missing;
+ }
+ return n;
});
final DocumentNodeState result = node == missing
|| node.equals(missing) ? null : node;
PERFLOG.end(start, 1, "getNode: path={}, rev={}", path, rev);
return result;
- } catch (RuntimeException | ExecutionException e) {
+ } catch (RuntimeException e) {
throw DocumentStoreException.convert(e.getCause());
}
}
@@ -1457,12 +1449,7 @@ public final class DocumentNodeStore
final RevisionVector readRevision = parent.getLastRevision();
try {
NamePathRev key = childNodeCacheKey(path, readRevision, name);
- DocumentNodeState.Children children = nodeChildrenCache.get(key, new Callable<DocumentNodeState.Children>() {
- @Override
- public DocumentNodeState.Children call() throws Exception {
- return readChildren(parent, name, limit);
- }
- });
+ DocumentNodeState.Children children = nodeChildrenCache.get(key, k -> readChildren(parent, name, limit));
if (children.children.size() < limit && children.hasMore) {
// not enough children loaded - load more,
// and put that in the cache
@@ -1472,7 +1459,7 @@ public final class DocumentNodeStore
nodeChildrenCache.put(key, children);
}
return children;
- } catch (RuntimeException | ExecutionException e) {
+ } catch (RuntimeException e) {
throw DocumentStoreException.convert(e.getCause(),
"Error occurred while fetching children for path "
+ path);
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
index 3f5581a4cf..122cc88b38 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilder.java
@@ -35,15 +35,14 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import org.apache.jackrabbit.guava.common.cache.Cache;
-import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
-import org.apache.jackrabbit.guava.common.cache.RemovalCause;
-import org.apache.jackrabbit.guava.common.cache.RemovalListener;
-import org.apache.jackrabbit.guava.common.cache.RemovalNotification;
-import org.apache.jackrabbit.guava.common.cache.Weigher;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
+import org.apache.jackrabbit.oak.cache.api.Cache;
+import org.apache.jackrabbit.oak.cache.api.CacheBuilder;
+import org.apache.jackrabbit.oak.cache.api.CacheStatsAdapter;
import org.apache.jackrabbit.oak.cache.api.EvictionCause;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.api.Weigher;
+import org.apache.jackrabbit.oak.cache.impl.lirs.LirsCacheAdapter;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.cache.EmpiricalWeigher;
import org.apache.jackrabbit.oak.commons.PathUtils;
@@ -159,7 +158,7 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
private LeaseFailureHandler leaseFailureHandler;
private StatisticsProvider statisticsProvider = StatisticsProvider.NOOP;
private BlobStoreStats blobStoreStats;
- private CacheStats blobStoreCacheStats;
+ private AbstractCacheStats blobStoreCacheStats;
private DocumentStoreStatsCollector documentStoreStatsCollector;
private ThrottlingStatsCollector throttlingStatsCollector;
private DocumentNodeStoreStatsCollector nodeStoreStatsCollector;
@@ -817,7 +816,7 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
}
@Nullable
- public CacheStats getBlobStoreCacheStats() {
+ public AbstractCacheStats getBlobStoreCacheStats() {
return blobStoreCacheStats;
}
@@ -1015,14 +1014,19 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
public NodeDocumentCache buildNodeDocumentCache(DocumentStore docStore, NodeDocumentLocks locks) {
Cache<CacheValue, NodeDocument> nodeDocumentsCache = buildDocumentCache(docStore);
- CacheStats nodeDocumentsCacheStats = new CacheStats(nodeDocumentsCache, "Document-Documents", getWeigher(), getDocumentCacheSize());
+ AbstractCacheStats nodeDocumentsCacheStats = newCacheStatsAdapter(nodeDocumentsCache, "Document-Documents", getDocumentCacheSize());
Cache<StringValue, NodeDocument> prevDocumentsCache = buildPrevDocumentsCache(docStore);
- CacheStats prevDocumentsCacheStats = new CacheStats(prevDocumentsCache, "Document-PrevDocuments", getWeigher(), getPrevDocumentCacheSize());
+ AbstractCacheStats prevDocumentsCacheStats = newCacheStatsAdapter(prevDocumentsCache, "Document-PrevDocuments", getPrevDocumentCacheSize());
return new NodeDocumentCache(nodeDocumentsCache, nodeDocumentsCacheStats, prevDocumentsCache, prevDocumentsCacheStats, locks);
}
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ AbstractCacheStats newCacheStatsAdapter(Cache<?, ?> cache, String name, long maxWeight) {
+ return new CacheStatsAdapter((Cache) cache, name, (Weigher) weigher, maxWeight);
+ }
+
/**
* Checks the feature toggle for prevNoProp cache and returns true if that's enabled
* @return true if the prevNoProp feature toggle is enabled, false otherwise
@@ -1139,53 +1143,34 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
final Set<EvictionListener<K, V>> listeners) {
// do not use LIRS cache when maxWeight is zero (OAK-6953)
if (LIRS_CACHE && maxWeight > 0) {
- return CacheLIRS.<K, V>newBuilder().
- module(module).
- weigher(new Weigher<K, V>() {
- @Override
- public int weigh(K key, V value) {
- return weigher.weigh(key, value);
- }
- }).
- averageWeight(2000).
- maximumWeight(maxWeight).
- segmentCount(cacheSegmentCount).
- stackMoveDistance(cacheStackMoveDistance).
- recordStats().
- evictionCallback(new CacheLIRS.EvictionCallback<K, V>() {
- @Override
- public void evicted(K key, V value, RemovalCause cause) {
- for (EvictionListener<K, V> l : listeners) {
- l.evicted(key, value, toEvictionCause(cause));
- }
- }
- }).
- build();
- }
- return CacheBuilder.newBuilder().
- concurrencyLevel(cacheSegmentCount).
- weigher(weigher).
- maximumWeight(maxWeight).
- recordStats().
- removalListener(new RemovalListener<K, V>() {
- @Override
- public void onRemoval(RemovalNotification<K, V> notification) {
+ CacheLIRS<K, V> lirs = CacheLIRS.<K, V>newBuilder()
+ .module(module)
+ .weigher((key, value) -> weigher.weigh(key, value))
+ .averageWeight(2000)
+ .maximumWeight(maxWeight)
+ .segmentCount(cacheSegmentCount)
+ .stackMoveDistance(cacheStackMoveDistance)
+ .recordStats()
+ .evictionCallback((key, value, cause) -> {
for (EvictionListener<K, V> l : listeners) {
- l.evicted(notification.getKey(), notification.getValue(), toEvictionCause(notification.getCause()));
+ l.evicted(key, value, LirsCacheAdapter.toOakCause(cause));
}
- }
- }).
- build();
- }
-
- private static EvictionCause toEvictionCause(RemovalCause cause) {
- return switch (cause) {
- case EXPLICIT -> EvictionCause.EXPLICIT;
- case REPLACED -> EvictionCause.REPLACED;
- case SIZE -> EvictionCause.SIZE;
- case EXPIRED -> EvictionCause.EXPIRED;
- case COLLECTED -> EvictionCause.COLLECTED;
- };
+ })
+ .build();
+ return new LirsCacheAdapter<>(lirs);
+ }
+ CacheBuilder<K, V> builder = CacheBuilder.<K, V>newBuilder()
+ .maximumWeight(maxWeight)
+ .weigher(weigher::weigh)
+ .recordStats();
+ if (!listeners.isEmpty()) {
+ builder = builder.evictionListener((k, v, cause) -> {
+ for (EvictionListener<K, V> l : listeners) {
+ l.evicted(k, v, cause);
+ }
+ });
+ }
+ return builder.build();
}
/**
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
index 6e9f95ecd2..58b78df936 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
@@ -60,7 +60,6 @@ import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
import org.apache.jackrabbit.oak.api.jmx.PersistentCacheStatsMBean;
import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
-import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.commons.pio.Closer;
import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentNodeStoreBuilder;
@@ -879,7 +878,7 @@ public class DocumentNodeStoreService {
}
DocumentStore ds = store.getDocumentStore();
if (ds.getCacheStats() != null) {
- for (CacheStats cacheStats : ds.getCacheStats()) {
+ for (AbstractCacheStats cacheStats : ds.getCacheStats()) {
registerCacheStatsMBean(cacheStats);
}
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
index 889446fdc8..cfb42d65c0 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentStore.java
@@ -22,7 +22,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Condition;
import org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
@@ -431,7 +431,7 @@ public interface DocumentStore {
* @return status information about the cache
*/
@Nullable
- Iterable<CacheStats> getCacheStats();
+ Iterable<AbstractCacheStats> getCacheStats();
/**
* @return description of the underlying storage.
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
index 0ed7a425a2..f00b116705 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/NodeDocument.java
@@ -49,7 +49,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.function.Predicate;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.commons.collections.AbstractIterator;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.commons.PathUtils;
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
index b970434b0a..4ff05d0952 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
@@ -27,14 +27,13 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.locks.Lock;
+import java.util.function.Function;
import java.util.function.Predicate;
-import org.apache.jackrabbit.guava.common.cache.Cache;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.plugins.document.Document;
@@ -51,7 +50,7 @@ public class NodeDocumentCache implements Closeable {
private final Cache<CacheValue, NodeDocument> nodeDocumentsCache;
- private final CacheStats nodeDocumentsCacheStats;
+ private final AbstractCacheStats nodeDocumentsCacheStats;
/**
* The previous documents cache
@@ -59,16 +58,16 @@ public class NodeDocumentCache implements Closeable {
* Key: StringValue, value: NodeDocument
*/
private final Cache<StringValue, NodeDocument> prevDocumentsCache;
- private final CacheStats prevDocumentsCacheStats;
+ private final AbstractCacheStats prevDocumentsCacheStats;
private final NodeDocumentLocks locks;
private final List<CacheChangesTracker> changeTrackers;
public NodeDocumentCache(@NotNull Cache<CacheValue, NodeDocument> nodeDocumentsCache,
- @NotNull CacheStats nodeDocumentsCacheStats,
+ @NotNull AbstractCacheStats nodeDocumentsCacheStats,
@NotNull Cache<StringValue, NodeDocument> prevDocumentsCache,
- @NotNull CacheStats prevDocumentsCacheStats,
+ @NotNull AbstractCacheStats prevDocumentsCacheStats,
@NotNull NodeDocumentLocks locks) {
this.nodeDocumentsCache = nodeDocumentsCache;
this.nodeDocumentsCacheStats = nodeDocumentsCacheStats;
@@ -161,22 +160,18 @@ public class NodeDocumentCache implements Closeable {
* is not synchronized and will be faster if you need to get the cached value
* outside the critical section.
*
- * @see Cache#get(Object, Callable)
+ * @see Cache#get(Object, Function)
* @param key document key
- * @param valueLoader object used to retrieve the document
+ * @param valueLoader function used to retrieve the document when absent from cache
* @return document matching given key
*/
@NotNull
- public NodeDocument get(@NotNull final String key, @NotNull final Callable<NodeDocument> valueLoader)
- throws ExecutionException {
- Callable<NodeDocument> wrappedLoader = new Callable<NodeDocument>() {
- @Override
- public NodeDocument call() throws Exception {
- for (CacheChangesTracker tracker : changeTrackers) {
- tracker.invalidateDocument(key);
- }
- return valueLoader.call();
+ public NodeDocument get(@NotNull final String key, @NotNull final Function<String, NodeDocument> valueLoader) {
+ Function<CacheValue, NodeDocument> wrappedLoader = k -> {
+ for (CacheChangesTracker tracker : changeTrackers) {
+ tracker.invalidateDocument(key);
}
+ return valueLoader.apply(key);
};
Lock lock = locks.acquire(key);
try {
@@ -258,27 +253,18 @@ public class NodeDocumentCache implements Closeable {
// make sure we only cache the document if it wasn't
// changed and cached by some other thread in the
- // meantime. That is, use get() with a Callable,
+ // meantime. That is, use get() with a Function,
// which is only used when the document isn't there
Lock lock = locks.acquire(id);
try {
for (;;) {
- NodeDocument cached = get(id, new Callable<NodeDocument>() {
- @Override
- public NodeDocument call() {
- return doc;
- }
- });
+ NodeDocument cached = get(id, k -> doc);
if (cached != NodeDocument.NULL) {
return cached;
} else {
invalidate(id);
}
}
- } catch (ExecutionException e) {
- // will never happen because call() just returns
- // the already available doc
- throw new IllegalStateException(e);
} finally {
lock.unlock();
}
@@ -333,7 +319,7 @@ public class NodeDocumentCache implements Closeable {
return IterableUtils.chainedIterable(nodeDocumentsCache.asMap().values(), prevDocumentsCache.asMap().values());
}
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return Arrays.asList(nodeDocumentsCacheStats, prevDocumentsCacheStats);
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
index d28d169602..b53fefe041 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/memory/MemoryDocumentStore.java
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
@@ -444,7 +444,7 @@ public class MemoryDocumentStore implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return null;
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
index 312ba26bdb..ba1afcb9c7 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
@@ -32,8 +32,6 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.Objects;
import java.util.Optional;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
@@ -44,7 +42,7 @@ import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import org.apache.commons.io.IOUtils;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.apache.jackrabbit.oak.commons.collections.IteratorUtils;
@@ -628,12 +626,7 @@ public class MongoDocumentStore implements DocumentStore {
collection, key,
getReadPreference(maxCacheAge));
invalidateCache(collection, key);
- doc = nodesCache.get(key, new Callable<NodeDocument>() {
- @Override
- public NodeDocument call() throws Exception {
- return d == null ? NodeDocument.NULL : d;
- }
- });
+ doc = nodesCache.get(key, k -> d == null ? NodeDocument.NULL : d);
} finally {
lock.unlock();
}
@@ -642,8 +635,6 @@ public class MongoDocumentStore implements DocumentStore {
} else {
return (T) doc;
}
- } catch (ExecutionException e) {
- t = e.getCause();
} catch (RuntimeException e) {
t = e;
}
@@ -1829,7 +1820,7 @@ public class MongoDocumentStore implements DocumentStore {
// load NULL document into cache unless it may have
// been affected by another concurrent operation
if (!tracker.mightBeenAffected(id)) {
- nodesCache.get(id, () -> NULL);
+ nodesCache.get(id, k -> NULL);
}
} finally {
lock.unlock();
@@ -1837,8 +1828,6 @@ public class MongoDocumentStore implements DocumentStore {
}
}
return;
- } catch (ExecutionException e) {
- t = e.getCause();
} catch (RuntimeException e) {
t = e;
} finally {
@@ -2092,7 +2081,7 @@ public class MongoDocumentStore implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return nodesCache.getCacheStats();
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
index bfad86741b..20705e4cb9 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCache.java
@@ -23,13 +23,11 @@ import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
+import java.util.function.Function;
-import org.apache.jackrabbit.guava.common.cache.Cache;
-import org.apache.jackrabbit.guava.common.cache.CacheStats;
-import org.apache.jackrabbit.guava.common.collect.ImmutableMap;
+import org.apache.jackrabbit.oak.cache.api.Cache;
+import org.apache.jackrabbit.oak.cache.api.CacheStatsSnapshot;
import org.apache.jackrabbit.oak.cache.api.EvictionCause;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
@@ -68,7 +66,7 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
NodeCache(
PersistentCache cache,
Cache<K, V> memCache,
- DocumentNodeStore docNodeStore,
+ DocumentNodeStore docNodeStore,
DocumentStore docStore,
CacheType type,
CacheActionDispatcher dispatcher,
@@ -184,11 +182,10 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
}
}
- @SuppressWarnings("unchecked")
@Override
@Nullable
- public V getIfPresent(Object key) {
- memCacheMetadata.increment((K) key);
+ public V getIfPresent(K key) {
+ memCacheMetadata.increment(key);
V value = memCache.getIfPresent(key);
if (value == null) {
memCacheMetadata.remove(key);
@@ -205,9 +202,9 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
stats.markRequest();
// it takes care of updating memCacheMetadata
- value = readIfPresent((K) key);
+ value = readIfPresent(key);
if (value != null) {
- memCache.put((K) key, value);
+ memCache.put(key, value);
stats.markHit();
}
return value;
@@ -215,8 +212,7 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
@Override
public V get(K key,
- Callable<? extends V> valueLoader)
- throws ExecutionException {
+ Function<? super K, ? extends V> mappingFunction) {
// Get stats covered in getIfPresent
V value = getIfPresent(key);
@@ -228,25 +224,25 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
TimerStats.Context ctx = stats.startLoaderTimer();
try {
memCacheMetadata.increment(key);
- value = memCache.get(key, valueLoader);
+ value = memCache.get(key, mappingFunction);
ctx.stop();
if (!async) {
write((K) key, value);
}
broadcast(key, value);
return value;
- } catch (ExecutionException e) {
+ } catch (RuntimeException e) {
stats.markException();
throw e;
- }
+ }
}
@Override
- public ImmutableMap<K, V> getAllPresent(
- Iterable<?> keys) {
+ public Map<K, V> getAllPresent(
+ Iterable<? extends K> keys) {
Iterable<K> typedKeys = (Iterable<K>) keys;
memCacheMetadata.incrementAll(keys);
- ImmutableMap<K, V> result = memCache.getAllPresent(keys);
+ Map<K, V> result = memCache.getAllPresent(keys);
memCacheMetadata.removeAll(IterableUtils.filter(typedKeys, x -> !result.keySet().contains(x)));
return result;
}
@@ -261,28 +257,21 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
broadcast(key, value);
}
- @SuppressWarnings("unchecked")
@Override
- public void invalidate(Object key) {
+ public void invalidate(K key) {
memCache.invalidate(key);
memCacheMetadata.remove(key);
if (async) {
- writeQueue.addInvalidate(singleton((K) key));
+ writeQueue.addInvalidate(singleton(key));
} else {
- write((K) key, null);
+ write(key, null);
}
- broadcast((K) key, null);
+ broadcast(key, null);
stats.markInvalidateOne();
}
@Override
- public void putAll(Map<? extends K, ? extends V> m) {
- memCacheMetadata.putAll(m.keySet());
- memCache.putAll(m);
- }
-
- @Override
- public void invalidateAll(Iterable<?> keys) {
+ public void invalidateAll(Iterable<? extends K> keys) {
memCache.invalidateAll(keys);
memCacheMetadata.removeAll(keys);
}
@@ -296,12 +285,12 @@ class NodeCache<K extends CacheValue, V extends CacheValue>
}
@Override
- public long size() {
- return memCache.size();
+ public long estimatedSize() {
+ return memCache.estimatedSize();
}
@Override
- public CacheStats stats() {
+ public CacheStatsSnapshot stats() {
return memCache.stats();
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
index 16df03a212..c3a2b3e225 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
@@ -27,7 +27,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
index 301c127dd3..621f753c3b 100755
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStore.java
@@ -50,9 +50,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
-import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
@@ -61,7 +59,7 @@ import java.util.zip.GZIPOutputStream;
import javax.sql.DataSource;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.commons.collections.IteratorUtils;
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
@@ -838,7 +836,7 @@ public class RDBDocumentStore implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return nodesCache.getCacheStats();
}
@@ -1513,45 +1511,38 @@ public class RDBDocumentStore implements DocumentStore {
}
}
}
- try {
- try (CacheLock lock = acquireLockFor(id)) {
- // caller really wants the cache to be cleared
- if (maxCacheAge == 0) {
- invalidateNodesCache(id, true);
- doc = null;
+ try (CacheLock lock = acquireLockFor(id)) {
+ // caller really wants the cache to be cleared
+ if (maxCacheAge == 0) {
+ invalidateNodesCache(id, true);
+ doc = null;
+ }
+ final NodeDocument cachedDoc = doc;
+ doc = nodesCache.get(id, k -> {
+ NodeDocument loadedDoc = (NodeDocument) readDocumentUncached(collection, id, cachedDoc);
+ if (loadedDoc != null) {
+ loadedDoc.seal();
}
- final NodeDocument cachedDoc = doc;
- doc = nodesCache.get(id, new Callable<NodeDocument>() {
- @Override
- public NodeDocument call() throws Exception {
- NodeDocument doc = (NodeDocument) readDocumentUncached(collection, id, cachedDoc);
- if (doc != null) {
- doc.seal();
- }
- return wrap(doc);
- }
- });
- // inspect the doc whether it can be used
- long lastCheckTime = doc.getLastCheckTime();
- if (lastCheckTime != 0 && (maxCacheAge == 0 || maxCacheAge == Integer.MAX_VALUE)) {
- // we either just cleared the cache or the caller does
- // not care;
- } else if (lastCheckTime != 0 && (System.currentTimeMillis() - lastCheckTime < maxCacheAge)) {
- // is new enough
- } else {
- // need to at least revalidate
- NodeDocument ndoc = (NodeDocument) readDocumentUncached(collection, id, cachedDoc);
- if (ndoc != null) {
- ndoc.seal();
- }
- doc = wrap(ndoc);
- nodesCache.put(doc);
+ return wrap(loadedDoc);
+ });
+ // inspect the doc whether it can be used
+ long lastCheckTime = doc.getLastCheckTime();
+ if (lastCheckTime != 0 && (maxCacheAge == 0 || maxCacheAge == Integer.MAX_VALUE)) {
+ // we either just cleared the cache or the caller does
+ // not care;
+ } else if (lastCheckTime != 0 && (System.currentTimeMillis() - lastCheckTime < maxCacheAge)) {
+ // is new enough
+ } else {
+ // need to at least revalidate
+ NodeDocument ndoc = (NodeDocument) readDocumentUncached(collection, id, cachedDoc);
+ if (ndoc != null) {
+ ndoc.seal();
}
+ doc = wrap(ndoc);
+ nodesCache.put(doc);
}
- return castAsT(unwrap(doc));
- } catch (ExecutionException e) {
- throw new IllegalStateException("Failed to load document with " + id, e);
}
+ return castAsT(unwrap(doc));
}
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
index 8ffb8796b1..3223c5db29 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LeaseCheckDocumentStoreWrapper.java
@@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.ClusterNodeInfo;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
@@ -213,7 +213,7 @@ public final class LeaseCheckDocumentStoreWrapper implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return leaseChecking(delegate::getCacheStats);
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
index 099eca91de..1db5af0944 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/LoggingDocumentStoreWrapper.java
@@ -20,7 +20,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
@@ -366,12 +366,12 @@ public class LoggingDocumentStoreWrapper implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
try {
logMethod("getCacheStats");
- return logResult(new Callable<Iterable<CacheStats>>() {
+ return logResult(new Callable<Iterable<AbstractCacheStats>>() {
@Override
- public Iterable<CacheStats> call() throws Exception {
+ public Iterable<AbstractCacheStats> call() throws Exception {
return store.getCacheStats();
}
});
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
index 8b59b5d416..b870da9a23 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/SynchronizingDocumentStoreWrapper.java
@@ -19,7 +19,7 @@ package org.apache.jackrabbit.oak.plugins.document.util;
import java.util.List;
import java.util.Map;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
@@ -154,7 +154,7 @@ public class SynchronizingDocumentStoreWrapper implements DocumentStore {
}
@Override
- public synchronized Iterable<CacheStats> getCacheStats() {
+ public synchronized Iterable<AbstractCacheStats> getCacheStats() {
return store.getCacheStats();
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/ThrottlingDocumentStoreWrapper.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/ThrottlingDocumentStoreWrapper.java
index d0c6471cbd..d1f6417fd2 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/ThrottlingDocumentStoreWrapper.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/ThrottlingDocumentStoreWrapper.java
@@ -16,7 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.document.util;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
@@ -233,7 +233,7 @@ public class ThrottlingDocumentStoreWrapper implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return store.getCacheStats();
}
diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
index 974ef43171..4e3dbbb708 100644
--- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
+++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/TimingDocumentStoreWrapper.java
@@ -25,7 +25,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
@@ -423,10 +423,10 @@ public class TimingDocumentStoreWrapper implements DocumentStore {
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
try {
long start = now();
- Iterable<CacheStats> result = base.getCacheStats();
+ Iterable<AbstractCacheStats> result = base.getCacheStats();
updateAndLogTimes("getCacheStats", start, 0, 0);
return result;
} catch (Exception e) {
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AsyncCacheTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AsyncCacheTest.java
index b983a1b7cd..9fc5bafd7e 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AsyncCacheTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/AsyncCacheTest.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertNull;
import java.io.File;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.junit.Rule;
import org.junit.Test;
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
index fe200862d7..6289c23252 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
@@ -21,7 +21,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats;
import org.jetbrains.annotations.NotNull;
@@ -215,7 +215,7 @@ public class CountingDocumentStore implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return delegate.getCacheStats();
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DisableCacheTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DisableCacheTest.java
index 6abbbb2731..22d8f5fad6 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DisableCacheTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DisableCacheTest.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertEquals;
import java.io.File;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -50,6 +50,7 @@ public class DisableCacheTest {
DEFAULT_PREV_NO_PROP_CACHE_PERCENTAGE);
DocumentNodeStore nodeStore = builder.getNodeStore();
Cache<PathRev, DocumentNodeState> cache = nodeStore.getNodeCache();
- assertEquals(0, cache.size());
+ cache.cleanUp();
+ assertEquals(0, cache.estimatedSize());
}
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java
index 324473fabf..4a9295fafa 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentMKBuilderTest.java
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.plugins.document;
import com.mongodb.client.MongoClient;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.commons.collections.IterableUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -74,11 +74,11 @@ public class DocumentMKBuilderTest extends AbstractMongoConnectionTest {
@Test
public void lazyInit() throws Exception {
- Iterable<CacheStats> cacheStats = mk.getDocumentStore().getCacheStats();
+ Iterable<AbstractCacheStats> cacheStats = mk.getDocumentStore().getCacheStats();
assertNotNull(cacheStats);
assertEquals(2, IterableUtils.size(cacheStats));
- CacheStats docCacheStats = IterableUtils.get(cacheStats, 0);
- CacheStats prevDocCacheStats = IterableUtils.get(cacheStats, 1);
+ AbstractCacheStats docCacheStats = IterableUtils.get(cacheStats, 0);
+ AbstractCacheStats prevDocCacheStats = IterableUtils.get(cacheStats, 1);
assertEquals("Document-Documents", docCacheStats.getName());
assertEquals("Document-PrevDocuments", prevDocCacheStats.getName());
assertEquals(expectedDocCacheSize, docCacheStats.getMaxTotalWeight());
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilderTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilderTest.java
index ae10d8fd09..0ba38ed82b 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilderTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreBuilderTest.java
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.plugins.document;
import java.lang.reflect.Method;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.cache.NodeDocumentCache;
import org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
@@ -50,7 +50,7 @@ public class DocumentNodeStoreBuilderTest {
DocumentStore store = new MemoryDocumentStore();
NodeDocumentCache cache = DocumentNodeStoreBuilder.newDocumentNodeStoreBuilder()
.buildNodeDocumentCache(store, new StripedNodeDocumentLocks());
- Iterable<CacheStats> stats = cache.getCacheStats();
+ Iterable<AbstractCacheStats> stats = cache.getCacheStats();
Assert.assertNotNull(stats);
Assert.assertTrue(stats.iterator().hasNext());
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
index a53007342b..aadc7ee8cc 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentStoreWrapper.java
@@ -19,7 +19,7 @@ package org.apache.jackrabbit.oak.plugins.document;
import java.util.List;
import java.util.Map;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats;
import org.jetbrains.annotations.NotNull;
@@ -150,7 +150,7 @@ public class DocumentStoreWrapper implements DocumentStore {
}
@Override
- public Iterable<CacheStats> getCacheStats() {
+ public Iterable<AbstractCacheStats> getCacheStats() {
return store.getCacheStats();
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PreviousDocCacheTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PreviousDocCacheTest.java
index a44961497d..1bc4fb16c5 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PreviousDocCacheTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PreviousDocCacheTest.java
@@ -17,7 +17,7 @@
package org.apache.jackrabbit.oak.plugins.document;
import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.commons.collections.IteratorUtils;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -55,9 +55,9 @@ public class PreviousDocCacheTest extends AbstractMongoConnectionTest {
splitDocs(ns, SPLIT_THRESHOLD);
}
- CacheStats nodesCache = null;
- CacheStats prevDocsCache = null;
- for (CacheStats cacheStats : docStore.getCacheStats()) {
+ AbstractCacheStats nodesCache = null;
+ AbstractCacheStats prevDocsCache = null;
+ for (AbstractCacheStats cacheStats : docStore.getCacheStats()) {
if ("Document-Documents".equals(cacheStats.getName())) {
nodesCache = cacheStats;
} else if ("Document-PrevDocuments".equals(cacheStats.getName())) {
@@ -81,7 +81,7 @@ public class PreviousDocCacheTest extends AbstractMongoConnectionTest {
validateFullyLoadedCache(docStore, SPLIT_THRESHOLD, nodesCache, prevDocsCache);
}
- private void validateFullyLoadedCache(DocumentStore docStore, int splitThreshold, CacheStats nodesCache, CacheStats prevDocsCache) {
+ private void validateFullyLoadedCache(DocumentStore docStore, int splitThreshold, AbstractCacheStats nodesCache, AbstractCacheStats prevDocsCache) {
assertEquals("Nodes cache must have 2 elements - '/' and intermediate split doc",
2, nodesCache.getElementCount());
assertEquals("Unexpected number of leaf prev docs", splitThreshold + 1, prevDocsCache.getElementCount());
@@ -96,8 +96,8 @@ public class PreviousDocCacheTest extends AbstractMongoConnectionTest {
assertEquals("Prev docs cache should not have a miss", 0, prevDocsCache.getMissCount());
}
- private void resetStats(CacheStats ... cacheStatses) {
- for (CacheStats cacheStats : cacheStatses) {
+ private void resetStats(AbstractCacheStats ... cacheStatses) {
+ for (AbstractCacheStats cacheStats : cacheStatses) {
cacheStats.resetStats();
}
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/Sweep2Test.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/Sweep2Test.java
index 97549e9951..63f848338e 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/Sweep2Test.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/Sweep2Test.java
@@ -47,7 +47,7 @@ import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import junitx.util.PrivateAccessor;
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java
index 8950951f9e..a3b3962b9c 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java
@@ -101,7 +101,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
-import org.apache.jackrabbit.guava.common.cache.Cache;
+import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.commons.collections.AbstractIterator;
import com.mongodb.ReadPreference;
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
index 713ed7d3c2..c6f6ca6da8 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
@@ -24,12 +24,11 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.api.Cache;
+import org.apache.jackrabbit.oak.cache.impl.lirs.LirsCacheAdapter;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
@@ -100,7 +99,7 @@ public class CacheChangesTrackerTest {
}
@Test
- public void testGetLoaderAffectsTracker() throws ExecutionException {
+ public void testGetLoaderAffectsTracker() {
NodeDocumentCache cache = createCache();
Path parent = Path.fromString("/parent");
CacheChangesTracker tracker = cache.registerTracker(getKeyLowerLimit(parent), getKeyUpperLimit(parent));
@@ -110,12 +109,7 @@ public class CacheChangesTrackerTest {
cache.getIfPresent("2:/parent/xyz");
assertFalse(tracker.mightBeenAffected("2:/parent/xyz"));
- cache.get("2:/parent/xyz", new Callable<NodeDocument>() {
- @Override
- public NodeDocument call() throws Exception {
- return createDoc("2:/parent/xyz");
- }
- });
+ cache.get("2:/parent/xyz", k -> createDoc("2:/parent/xyz"));
assertTrue(tracker.mightBeenAffected("2:/parent/xyz"));
}
@@ -158,10 +152,10 @@ public class CacheChangesTrackerTest {
}
private NodeDocumentCache createCache() {
- Cache<CacheValue, NodeDocument> nodeDocumentsCache = new CacheLIRS<CacheValue, NodeDocument>(10);
- Cache<StringValue, NodeDocument> prevDocumentsCache = new CacheLIRS<StringValue, NodeDocument>(10);
- CacheStats nodeDocumentsCacheStats = Mockito.mock(CacheStats.class);
- CacheStats prevDocumentsCacheStats = Mockito.mock(CacheStats.class);
+ Cache<CacheValue, NodeDocument> nodeDocumentsCache = new LirsCacheAdapter<>(new CacheLIRS<CacheValue, NodeDocument>(10));
+ Cache<StringValue, NodeDocument> prevDocumentsCache = new LirsCacheAdapter<>(new CacheLIRS<StringValue, NodeDocument>(10));
+ AbstractCacheStats nodeDocumentsCacheStats = Mockito.mock(AbstractCacheStats.class);
+ AbstractCacheStats prevDocumentsCacheStats = Mockito.mock(AbstractCacheStats.class);
NodeDocumentLocks locks = new StripedNodeDocumentLocks();
return new NodeDocumentCache(nodeDocumentsCache, nodeDocumentsCacheStats, prevDocumentsCache, prevDocumentsCacheStats, locks);
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCacheTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCacheTest.java
index 8ab1f82df8..eafe2607a9 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCacheTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCacheTest.java
@@ -16,9 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.document.cache;
-import java.util.concurrent.ExecutionException;
-
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.Document;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
@@ -72,40 +70,35 @@ public class NodeDocumentCacheTest {
// cache. the cache must not accept this outdated document.
cache.putNonConflictingDocs(queryTracker, singleton(current));
- assertEquals(updated.getModCount(), cache.get(ID, () -> updated).getModCount());
+ assertEquals(updated.getModCount(), cache.get(ID, k -> updated).getModCount());
}
@Test
public void getWithCallableLoadsDocumentOnMiss() throws Exception {
NodeDocument doc = createDocument(1L);
- NodeDocument loaded = cache.get(ID, () -> doc);
+ NodeDocument loaded = cache.get(ID, k -> doc);
assertEquals(doc.getModCount(), loaded.getModCount());
}
@Test
- public void getWithCallableReturnsCachedDocumentOnHit() throws Exception {
+ public void getWithFunctionReturnsCachedDocumentOnHit() {
NodeDocument doc = createDocument(1L);
cache.put(doc);
// loader should not be called since doc is already cached
- NodeDocument loaded = cache.get(ID, () -> {
+ NodeDocument loaded = cache.get(ID, k -> {
throw new RuntimeException("loader must not be called on cache hit");
});
assertEquals(doc.getModCount(), loaded.getModCount());
}
@Test
- public void getWithCallableWrapsCheckedLoaderFailureInExecutionException() {
- Exception failure = new Exception("simulated load failure");
+ public void getWithFunctionPropagatesRuntimeException() {
+ RuntimeException failure = new RuntimeException("simulated load failure");
try {
- cache.get(ID, () -> {
- // This verifies the existing Oak-visible checked-exception
- // contract, not raw runtime propagation.
- throw failure;
- });
- fail("expected ExecutionException");
- } catch (ExecutionException e) {
- assertEquals(failure, e.getCause());
- assertEquals("simulated load failure", e.getCause().getMessage());
+ cache.get(ID, k -> { throw failure; });
+ fail("expected RuntimeException");
+ } catch (RuntimeException e) {
+ assertEquals(failure, e);
}
}
@@ -133,7 +126,7 @@ public class NodeDocumentCacheTest {
@Test
public void getCacheStatsReturnsNonEmptyIterable() {
- Iterable<CacheStats> statsIterable = cache.getCacheStats();
+ Iterable<AbstractCacheStats> statsIterable = cache.getCacheStats();
assertNotNull(statsIterable);
assertTrue(statsIterable.iterator().hasNext());
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/JournalIT.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/JournalIT.java
index 1ce50a7e1a..7c64ca0c3d 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/JournalIT.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/JournalIT.java
@@ -21,7 +21,7 @@ import java.util.Set;
import com.mongodb.ReadPreference;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.plugins.document.AbstractJournalTest;
import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
@@ -229,7 +229,7 @@ public class JournalIT extends AbstractJournalTest {
}
long count = 0;
- for (CacheStats cacheStats : ds.getCacheStats()) {
+ for (AbstractCacheStats cacheStats : ds.getCacheStats()) {
count += cacheStats.getElementCount();
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoRevisionGCTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoRevisionGCTest.java
index 05f7f00df8..fb5b866f5d 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoRevisionGCTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoRevisionGCTest.java
@@ -154,7 +154,7 @@ public class MongoRevisionGCTest extends AbstractMongoConnectionTest {
String prevId = prev.getId();
assertNotNull(prevId);
cache.invalidate(prevId);
- cache.get(prevId, () -> new NodeDocument(store, clock.getTime()));
+ cache.get(prevId, k -> new NodeDocument(store, clock.getTime()));
// must succeed without exception
try {
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
index a9feeff373..0c0187898e 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
@@ -19,7 +19,6 @@
package org.apache.jackrabbit.oak.plugins.document.persistentCache;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.guava.common.cache.RemovalCause;
import org.apache.jackrabbit.oak.cache.api.EvictionCause;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.commons.collections.ListUtils;
@@ -68,16 +67,13 @@ public class AsyncQueueTest {
FileUtils.deleteDirectory(new File("target/cacheTest"));
pCache = new PersistentCache("target/cacheTest");
final AtomicReference<NodeCache<PathRev, StringValue>> nodeCacheRef = new AtomicReference<NodeCache<PathRev, StringValue>>();
- CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev, StringValue>().maximumSize(1).evictionCallback(new CacheLIRS.EvictionCallback<PathRev, StringValue>() {
- @Override
- public void evicted(@NotNull PathRev key, @Nullable StringValue value, @NotNull RemovalCause cause) {
- if (nodeCacheRef.get() != null) {
- nodeCacheRef.get().evicted(key, value, EvictionCause.valueOf(cause.name()));
- }
+ CacheLIRS<PathRev, StringValue> lirs = new CacheLIRS.Builder<PathRev, StringValue>().maximumSize(1).evictionCallback((key, value, cause) -> {
+ if (nodeCacheRef.get() != null) {
+ nodeCacheRef.get().evicted(key, value, EvictionCause.valueOf(cause.name()));
}
}).build();
nodeCache = (NodeCache<PathRev, StringValue>) pCache.wrap(builderProvider.newBuilder().getNodeStore(),
- null, cache, CacheType.NODE);
+ null, new org.apache.jackrabbit.oak.cache.impl.lirs.LirsCacheAdapter<>(lirs), CacheType.NODE);
nodeCacheRef.set(nodeCache);
CacheWriteQueueWrapper writeQueue = new CacheWriteQueueWrapper(nodeCache.writeQueue);
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java
index 8a4e9474ef..77e336528b 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java
@@ -24,8 +24,9 @@ import java.io.File;
import java.util.concurrent.Callable;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
+import org.apache.jackrabbit.oak.cache.api.Cache;
+import org.apache.jackrabbit.oak.cache.impl.lirs.LirsCacheAdapter;
import org.apache.jackrabbit.oak.plugins.document.MemoryDiffCache.Key;
import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
@@ -136,6 +137,6 @@ public class BroadcastTest {
private static Cache<Key, StringValue> openCache(PersistentCache p) {
CacheLIRS<Key, StringValue> cache = new CacheLIRS.Builder<Key, StringValue>().
maximumSize(1).build();
- return p.wrap(null, null, cache, CacheType.DIFF);
+ return p.wrap(null, null, new LirsCacheAdapter<>(cache), CacheType.DIFF);
}
}
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
index 907dcce08e..471d2a182e 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
@@ -26,8 +26,9 @@ import java.io.File;
import java.io.FileOutputStream;
import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
+import org.apache.jackrabbit.oak.cache.api.Cache;
+import org.apache.jackrabbit.oak.cache.impl.lirs.LirsCacheAdapter;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.PathRev;
@@ -54,9 +55,9 @@ public class CacheTest {
out.write("corrupt".getBytes());
out.close();
PersistentCache pCache = new PersistentCache("target/cacheTest");
- CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev, StringValue>().
- maximumSize(1).build();
- Cache<PathRev, StringValue> map = pCache.wrap(null, null, cache, CacheType.DIFF);
+ Cache<PathRev, StringValue> map = pCache.wrap(null, null,
+ new LirsCacheAdapter<>(new CacheLIRS.Builder<PathRev, StringValue>().maximumSize(1).build()),
+ CacheType.DIFF);
String largeString = new String(new char[1024 * 1024]);
for (int counter = 0; counter < 10; counter++) {
long end = System.currentTimeMillis() + 100;
diff --git a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCacheCompatibilityTest.java b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCacheCompatibilityTest.java
index f9a52f6304..16e53a6de3 100644
--- a/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCacheCompatibilityTest.java
+++ b/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCacheCompatibilityTest.java
@@ -17,9 +17,9 @@
package org.apache.jackrabbit.oak.plugins.document.persistentCache;
import java.io.File;
-import java.util.concurrent.ExecutionException;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
+import org.apache.jackrabbit.oak.cache.impl.lirs.LirsCacheAdapter;
import org.apache.jackrabbit.oak.plugins.document.MemoryDiffCache;
import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.Revision;
@@ -128,20 +128,17 @@ public class PersistentCacheCompatibilityTest {
}
@Test
- public void getWrapsCheckedLoaderFailureInExecutionException() throws Exception {
- // Use a checked loader failure here because NodeCache exposes the same
- // checked get(key, loader) contract as the in-memory cache underneath it.
+ public void getWithFunctionPropagatesRuntimeException() throws Exception {
CacheHandle handle = openDiffCache("loaderFailure");
- Exception failure = new Exception("simulated persistent-cache load failure");
+ RuntimeException failure = new RuntimeException("simulated persistent-cache load failure");
try {
- handle.cache.get(key(7), () -> {
+ handle.cache.get(key(7), k -> {
throw failure;
});
- fail("expected ExecutionException");
- } catch (ExecutionException e) {
- assertSame(failure, e.getCause());
- assertEquals("simulated persistent-cache load failure", e.getCause().getMessage());
+ fail("expected RuntimeException");
+ } catch (RuntimeException e) {
+ assertSame(failure, e);
} finally {
handle.close();
}
@@ -156,7 +153,7 @@ public class PersistentCacheCompatibilityTest {
.build();
@SuppressWarnings("unchecked")
NodeCache<MemoryDiffCache.Key, StringValue> wrapped = (NodeCache<MemoryDiffCache.Key, StringValue>) persistentCache.wrap(
- null, null, base, CacheType.DIFF);
+ null, null, new LirsCacheAdapter<>(base), CacheType.DIFF);
return new CacheHandle(persistentCache, wrapped);
}