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/29 06:18:29 UTC

(jackrabbit-oak) branch trunk updated: OAK-12199 : fixed issue where we were silently dropped creation of persistent caches (#2877)

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

rishabhdaim 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 179d73869e OAK-12199 : fixed issue where we were silently dropped creation of persistent caches (#2877)
179d73869e is described below

commit 179d73869ee4b9e0b9bfd0f0fdb9a8e69561e821
Author: Rishabh Kumar <ri...@gmail.com>
AuthorDate: Wed Apr 29 11:48:23 2026 +0530

    OAK-12199 : fixed issue where we were silently dropped creation of persistent caches (#2877)
---
 .../plugins/document/DocumentNodeStoreBuilder.java | 14 +---
 .../document/DocumentNodeStoreBuilderTest.java     | 97 ++++++++++++++++++++++
 2 files changed, 99 insertions(+), 12 deletions(-)

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 3fd1bc87e9..1a744b1255 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
@@ -986,21 +986,11 @@ public class DocumentNodeStoreBuilder<T extends DocumentNodeStoreBuilder<T>> {
     }
 
     public org.apache.jackrabbit.oak.cache.api.Cache<CacheValue, StringValue> buildMemoryDiffCache() {
-        return org.apache.jackrabbit.oak.cache.api.CacheBuilder
-                .<CacheValue, StringValue>newBuilder()
-                .maximumWeight(getMemoryDiffCacheSize())
-                .weigher((k, v) -> weigher.weigh(k, v))
-                .recordStats()
-                .build();
+        return buildCache(CacheType.DIFF, getMemoryDiffCacheSize(), null, null);
     }
 
     public org.apache.jackrabbit.oak.cache.api.Cache<RevisionsKey, LocalDiffCache.Diff> buildLocalDiffCache() {
-        return org.apache.jackrabbit.oak.cache.api.CacheBuilder
-                .<RevisionsKey, LocalDiffCache.Diff>newBuilder()
-                .maximumWeight(getLocalDiffCacheSize())
-                .weigher((k, v) -> weigher.weigh(k, v))
-                .recordStats()
-                .build();
+        return buildCache(CacheType.LOCAL_DIFF, getLocalDiffCacheSize(), null, null);
     }
 
     public Cache<CacheValue, NodeDocument> buildDocumentCache(DocumentStore docStore) {
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 0ba38ed82b..dff4d9b7d0 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
@@ -16,15 +16,26 @@
  */
 package org.apache.jackrabbit.oak.plugins.document;
 
+import java.io.File;
+import java.util.HashMap;
 import java.lang.reflect.Method;
+import java.util.Map;
 
+import org.apache.jackrabbit.oak.cache.CacheValue;
 import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
+import org.apache.jackrabbit.oak.cache.api.Cache;
 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;
+import org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType;
+import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache;
+import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCacheStats;
+import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
 import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
 import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 /**
  * Tests for {@link DocumentNodeStoreBuilder} cache configuration.
@@ -33,6 +44,9 @@ import org.junit.Test;
  */
 public class DocumentNodeStoreBuilderTest {
 
+    @Rule
+    public final TemporaryFolder temp = new TemporaryFolder(new File("target"));
+
     @Test
     public void buildNodeDocumentCacheReturnsNonNull() {
         // Verify the builder can construct the node-document cache with the default
@@ -109,6 +123,89 @@ public class DocumentNodeStoreBuilderTest {
         Assert.assertEquals(document.getModCount(), ((NodeDocument) cached).getModCount());
     }
 
+    @Test
+    public void buildMemoryDiffCacheCreatesPersistentCacheStats() throws Exception {
+        String cacheDir = temp.newFolder().getAbsolutePath() + ",-async";
+        MemoryDiffCache.Key key = new MemoryDiffCache.Key(
+                Path.fromString("/diff-memory"),
+                new RevisionVector(new Revision(1, 0, 1)),
+                new RevisionVector(new Revision(2, 0, 1)));
+
+        DocumentNodeStoreBuilder<?> builder = DocumentNodeStoreBuilder.newDocumentNodeStoreBuilder()
+                .setPersistentCache(cacheDir);
+        try {
+            Cache<CacheValue, StringValue> cache = builder.buildMemoryDiffCache();
+            PersistentCacheStats persistentStats = PersistentCache.getPersistentCacheStats(cache);
+
+            Assert.assertNotNull("Expected persistent wrapper for " + CacheType.DIFF, persistentStats);
+            Assert.assertTrue("Expected persistent cache stats map entry for " + CacheType.DIFF,
+                    builder.getPersistenceCacheStats().containsKey(CacheType.DIFF.name()));
+
+            cache.put(key, StringValue.fromString("memory-diff-value"));
+        } finally {
+            closeCaches(builder);
+        }
+
+        DocumentNodeStoreBuilder<?> reopenedBuilder = DocumentNodeStoreBuilder.newDocumentNodeStoreBuilder()
+                .setPersistentCache(cacheDir);
+        try {
+            Cache<CacheValue, StringValue> reopened = reopenedBuilder.buildMemoryDiffCache();
+            StringValue value = reopened.getIfPresent(key);
+            Assert.assertNotNull("Expected persisted DIFF entry to be readable after reopen", value);
+            Assert.assertEquals("memory-diff-value", value.asString());
+        } finally {
+            closeCaches(reopenedBuilder);
+        }
+    }
+
+    @Test
+    public void buildLocalDiffCacheCreatesPersistentCacheStats() throws Exception {
+        String cacheDir = temp.newFolder().getAbsolutePath() + ",-async";
+        RevisionsKey key = new RevisionsKey(
+                new RevisionVector(new Revision(3, 0, 1)),
+                new RevisionVector(new Revision(4, 0, 1)));
+        Map<Path, String> changes = new HashMap<>();
+        changes.put(Path.fromString("/diff-local"), "+\"child\":{}");
+        LocalDiffCache.Diff expected = new LocalDiffCache.Diff(changes, 0);
+
+        DocumentNodeStoreBuilder<?> builder = DocumentNodeStoreBuilder.newDocumentNodeStoreBuilder()
+                .setPersistentCache(cacheDir);
+        try {
+            Cache<RevisionsKey, LocalDiffCache.Diff> cache = builder.buildLocalDiffCache();
+            PersistentCacheStats persistentStats = PersistentCache.getPersistentCacheStats(cache);
+
+            Assert.assertNotNull("Expected persistent wrapper for " + CacheType.LOCAL_DIFF, persistentStats);
+            Assert.assertTrue("Expected persistent cache stats map entry for " + CacheType.LOCAL_DIFF,
+                    builder.getPersistenceCacheStats().containsKey(CacheType.LOCAL_DIFF.name()));
+
+            cache.put(key, expected);
+        } finally {
+            closeCaches(builder);
+        }
+
+        DocumentNodeStoreBuilder<?> reopenedBuilder = DocumentNodeStoreBuilder.newDocumentNodeStoreBuilder()
+                .setPersistentCache(cacheDir);
+        try {
+            Cache<RevisionsKey, LocalDiffCache.Diff> reopened = reopenedBuilder.buildLocalDiffCache();
+            LocalDiffCache.Diff value = reopened.getIfPresent(key);
+            Assert.assertNotNull("Expected persisted LOCAL_DIFF entry to be readable after reopen", value);
+            Assert.assertEquals(expected, value);
+        } finally {
+            closeCaches(reopenedBuilder);
+        }
+    }
+
+    private static void closeCaches(DocumentNodeStoreBuilder<?> builder) {
+        PersistentCache cache = builder.getPersistentCache();
+        if (cache != null) {
+            cache.close();
+        }
+        PersistentCache journalCache = builder.getJournalCache();
+        if (journalCache != null) {
+            journalCache.close();
+        }
+    }
+
     private static Object invoke(Object target, String methodName, Class<?> parameterType, Object argument)
             throws Exception {
         Method method = target.getClass().getMethod(methodName, parameterType);