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 09:09:17 UTC

(jackrabbit-oak) branch trunk updated: OAK-12153 : removed guava cache from oak-search (#2843)

This is an automated email from the ASF dual-hosted git repository.

daim pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 70902c40ee OAK-12153 : removed guava cache from oak-search (#2843)
70902c40ee is described below

commit 70902c40ee52e763cd7dd89fd7b9e0be4eb7fc12
Author: Rishabh Kumar <ri...@gmail.com>
AuthorDate: Tue Apr 14 14:39:11 2026 +0530

    OAK-12153 : removed guava cache from oak-search (#2843)
    
    * OAK-12153 : removed guava cache from oak-search
    
    * OAK-12153 : fixed compilation issues
    
    * OAK-12153 : inlined CacheStatsAdaptor
    
    * OAK-12153 : inlined more cache api classes
---
 .../jackrabbit/oak/cache/api/CacheBuilder.java       | 14 ++++++++++++++
 oak-lucene/pom.xml                                   |  4 +++-
 .../index/lucene/LuceneIndexProviderService.java     |  4 ++--
 .../indexer/document/DocumentStoreIndexerBase.java   |  4 ++--
 oak-search/pom.xml                                   |  6 ++++++
 .../oak/plugins/index/search/ExtractedTextCache.java | 20 +++++++++++---------
 6 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheBuilder.java b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheBuilder.java
index d31fabc9d0..1d70aa97b3 100644
--- a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheBuilder.java
+++ b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheBuilder.java
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.oak.cache.api;
 
+import java.time.Clock;
 import java.time.Duration;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Supplier;
 
 import com.github.benmanes.caffeine.cache.Caffeine;
@@ -186,6 +188,18 @@ public final class CacheBuilder<K, V> {
         return this;
     }
 
+    /**
+     * Sets the clock used to measure time for expiry and refresh.
+     * Convenience overload for {@link #ticker(Supplier)}; converts milliseconds to nanoseconds internally.
+     *
+     * @param clock the clock to use (must not be null)
+     * @return this builder
+     */
+    @NotNull
+    public CacheBuilder<K, V> ticker(@NotNull Clock clock) {
+        return ticker(() -> TimeUnit.MILLISECONDS.toNanos(clock.millis()));
+    }
+
     /**
      * Builds and returns a cache with no auto-loading behaviour.
      *
diff --git a/oak-lucene/pom.xml b/oak-lucene/pom.xml
index 9a5e8d17e1..604ea581eb 100644
--- a/oak-lucene/pom.xml
+++ b/oak-lucene/pom.xml
@@ -118,6 +118,8 @@
                 org.apache.lucene.sandbox.*;resolution:=optional,
                 !org.apache.lucene.*,
                 !org.apache.jackrabbit.oak.cache,
+                !org.apache.jackrabbit.oak.cache.api,
+                !org.apache.jackrabbit.oak.cache.impl.caffeine,
                 !com.sun.management.*,
                 !sun.management.*,
                 !sun.misc.*,
@@ -127,7 +129,7 @@
               oak-search;scope=compile|runtime;inline=true,
                 lucene-*;inline=true,
               <!-- TODO FIXME OAK-3598 -->
-              oak-core-spi;inline="org/apache/jackrabbit/oak/cache/AbstractCacheStats.class|org/apache/jackrabbit/oak/cache/CacheStats.class"
+              oak-core-spi;inline="org/apache/jackrabbit/oak/cache/AbstractCacheStats.class|org/apache/jackrabbit/oak/cache/CacheStats.class|org/apache/jackrabbit/oak/cache/api/Cache.class|org/apache/jackrabbit/oak/cache/api/CacheBuilder.class|org/apache/jackrabbit/oak/cache/api/CacheLoader.class|org/apache/jackrabbit/oak/cache/api/CacheStatsAdapter.class|org/apache/jackrabbit/oak/cache/api/CacheStatsSnapshot.class|org/apache/jackrabbit/oak/cache/api/EvictionCause.class|org/apache/jackra [...]
               <!-- TODO FIXME OAK-3598 -->
             </Embed-Dependency>
           </instructions>
diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
index 342c6ac031..0b9019e67a 100644
--- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
+++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexProviderService.java
@@ -34,7 +34,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
 import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
-import org.apache.jackrabbit.oak.cache.CacheStats;
+import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
 import org.apache.jackrabbit.oak.commons.internal.concurrent.ExecutorHelper;
 import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard;
 import org.apache.jackrabbit.oak.plugins.document.spi.JournalPropertyService;
@@ -686,7 +686,7 @@ public class LuceneIndexProviderService {
         if (extractedTextProvider != null){
             registerExtractedTextProvider(extractedTextProvider);
         }
-        CacheStats stats = extractedTextCache.getCacheStats();
+        AbstractCacheStats stats = extractedTextCache.getCacheStats();
         if (stats != null){
             oakRegs.add(registerMBean(whiteboard,
                     CacheStatsMBean.class, stats,
diff --git a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java
index 6ac22bb57f..bf173b3c9e 100644
--- a/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java
+++ b/oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/DocumentStoreIndexerBase.java
@@ -21,7 +21,7 @@ package org.apache.jackrabbit.oak.index.indexer.document;
 import com.codahale.metrics.MetricRegistry;
 import com.mongodb.ConnectionString;
 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.PathUtils;
 import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
 import org.apache.jackrabbit.oak.commons.pio.Closer;
@@ -407,7 +407,7 @@ public abstract class DocumentStoreIndexerBase implements Closeable {
                     }
                 }
                 ExtractedTextCache extractedTextCache = indexerProvider.getTextCache();
-                CacheStats cacheStats = extractedTextCache == null ? null : extractedTextCache.getCacheStats();
+                AbstractCacheStats cacheStats = extractedTextCache == null ? null : extractedTextCache.getCacheStats();
                 log.info("Text extraction cache statistics: {}", cacheStats == null ? "N/A" : cacheStats.cacheInfoAsString());
 
                 progressReporter.reindexingTraversalEnd();
diff --git a/oak-search/pom.xml b/oak-search/pom.xml
index 1610cc444b..36679d4bfc 100644
--- a/oak-search/pom.xml
+++ b/oak-search/pom.xml
@@ -93,6 +93,12 @@
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>oak-core-spi</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>oak-store-spi</artifactId>
diff --git a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/ExtractedTextCache.java b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/ExtractedTextCache.java
index 57911f6a2f..dc3d39571c 100644
--- a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/ExtractedTextCache.java
+++ b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/ExtractedTextCache.java
@@ -23,6 +23,7 @@ import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.time.Duration;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Map.Entry;
@@ -36,11 +37,12 @@ import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import org.apache.jackrabbit.guava.common.cache.Cache;
-import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
-import org.apache.jackrabbit.guava.common.cache.Weigher;
 import org.apache.jackrabbit.oak.api.Blob;
-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.api.CacheBuilder;
+import org.apache.jackrabbit.oak.cache.api.CacheStatsAdapter;
+import org.apache.jackrabbit.oak.cache.api.Weigher;
 import org.apache.jackrabbit.oak.commons.IOUtils;
 import org.apache.jackrabbit.oak.commons.internal.concurrent.ExecutorHelper;
 import org.apache.jackrabbit.oak.plugins.index.fulltext.ExtractedText;
@@ -85,7 +87,7 @@ public class ExtractedTextCache {
 
     private final ConcurrentHashMap<String, String> timeoutMap;
     private final File indexDir;
-    private final CacheStats cacheStats;
+    private final AbstractCacheStats cacheStats;
     private final boolean alwaysUsePreExtractedCache;
     private volatile ExecutorService executorService;
     private volatile int timeoutCount;
@@ -103,13 +105,13 @@ public class ExtractedTextCache {
     public ExtractedTextCache(long maxWeight, long expiryTimeInSecs, boolean alwaysUsePreExtractedCache,
                               File indexDir, StatisticsProvider statisticsProvider) {
         if (maxWeight > 0) {
-            cache = CacheBuilder.newBuilder()
+            cache = CacheBuilder.<String, String>newBuilder()
                     .weigher(EmpiricalWeigher.INSTANCE)
                     .maximumWeight(maxWeight)
-                    .expireAfterAccess(expiryTimeInSecs, TimeUnit.SECONDS)
+                    .expireAfterAccess(Duration.ofSeconds(expiryTimeInSecs))
                     .recordStats()
                     .build();
-            cacheStats = new CacheStats(cache, "ExtractedTextCache",
+            cacheStats = new CacheStatsAdapter(cache, "ExtractedTextCache",
                     EmpiricalWeigher.INSTANCE, maxWeight);
         } else {
             cache = null;
@@ -248,7 +250,7 @@ public class ExtractedTextCache {
     }
 
     @Nullable
-    public CacheStats getCacheStats() {
+    public AbstractCacheStats getCacheStats() {
         return cacheStats;
     }