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 mi...@apache.org on 2025/09/16 16:34:16 UTC

(jackrabbit-oak) branch persistent_cache_preload updated (8eb86f8941 -> e7d4c084fb)

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

miroslav pushed a change to branch persistent_cache_preload
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git


    from 8eb86f8941 OAK-11932 - add segment prefetching capability for  CachingSegmentReader
     new ceab496ea5 OAK-11932 format
     new 24d2970ce8 OAK-11932 fix the test
     new e7d4c084fb OAK-11932 fix the test

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../CachingSegmentArchiveReader.java               | 31 ++++-------
 .../persistentcache/CachingPersistenceTest.java    | 65 ++++++++++------------
 2 files changed, 42 insertions(+), 54 deletions(-)


(jackrabbit-oak) 01/03: OAK-11932 format

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ceab496ea573144df26481185bba21c4812a7739
Author: Miroslav Smiljanic <mi...@apache.com>
AuthorDate: Tue Sep 16 17:47:33 2025 +0200

    OAK-11932 format
---
 .../CachingSegmentArchiveReader.java               | 31 ++++++---------
 .../persistentcache/CachingPersistenceTest.java    | 46 ++++++++--------------
 2 files changed, 29 insertions(+), 48 deletions(-)

diff --git a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingSegmentArchiveReader.java b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingSegmentArchiveReader.java
index bbf01e557a..9e2ac39c16 100644
--- a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingSegmentArchiveReader.java
+++ b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingSegmentArchiveReader.java
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.segment.spi.persistence.persistentcache;
 
 import org.apache.jackrabbit.oak.commons.Buffer;
 import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
+import org.apache.jackrabbit.oak.segment.data.SegmentData;
 import org.apache.jackrabbit.oak.segment.file.tar.SegmentGraph;
 import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveEntry;
 import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentArchiveReader;
@@ -29,6 +30,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
@@ -36,7 +38,6 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
 
 public class CachingSegmentArchiveReader implements SegmentArchiveReader {
 
@@ -79,25 +80,22 @@ public class CachingSegmentArchiveReader implements SegmentArchiveReader {
         return buf;
     }
 
-    /**
-     * Extract direct references from a segment buffer. Subclasses may override for testing.
-     */
-    private java.util.List<java.util.UUID> extractReferences(Buffer buffer) {
-        var data = org.apache.jackrabbit.oak.segment.data.SegmentData.newSegmentData(buffer);
+    private List<UUID> extractReferences(Buffer buffer) {
+        var data = SegmentData.newSegmentData(buffer);
         int refs = data.getSegmentReferencesCount();
-        java.util.ArrayList<java.util.UUID> out = new java.util.ArrayList<>(refs);
+        ArrayList<UUID> out = new ArrayList<>(refs);
         for (int i = 0; i < refs; i++) {
-            out.add(new java.util.UUID(data.getSegmentReferenceMsb(i), data.getSegmentReferenceLsb(i)));
+            out.add(new UUID(data.getSegmentReferenceMsb(i), data.getSegmentReferenceLsb(i)));
         }
         return out;
     }
 
     private void schedulePrefetch(long msb, long lsb, Buffer buffer) {
         try {
-            java.util.List<java.util.UUID> refs = extractReferences(buffer);
+            List<UUID> refs = extractReferences(buffer);
             int limit = Math.min(refs.size(), prefetchMaxRefs);
             for (int i = 0; i < limit; i++) {
-                final java.util.UUID ref = refs.get(i);
+                final UUID ref = refs.get(i);
                 final long rMsb = ref.getMostSignificantBits();
                 final long rLsb = ref.getLeastSignificantBits();
 
@@ -123,9 +121,7 @@ public class CachingSegmentArchiveReader implements SegmentArchiveReader {
                                 }
                             }
                         } catch (Exception e) {
-                            if (LOG.isDebugEnabled()) {
-                                LOG.debug("Prefetch failed for segment {}", new java.util.UUID(rMsb, rLsb), e);
-                            }
+                            LOG.debug("Prefetch failed for segment {}", new java.util.UUID(rMsb, rLsb), e);
                         } finally {
                             inFlightPrefetch.remove(ref);
                         }
@@ -133,15 +129,12 @@ public class CachingSegmentArchiveReader implements SegmentArchiveReader {
                 } catch (Throwable t) {
                     // If task submission failed (e.g., executor shutting down), undo the registration
                     inFlightPrefetch.remove(ref);
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Prefetch submission failed for segment {}", new java.util.UUID(rMsb, rLsb), t);
-                    }
+                    LOG.debug("Prefetch submission failed for segment {}", new java.util.UUID(rMsb, rLsb), t);
+
                 }
             }
         } catch (Throwable t) {
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Prefetch scheduling failed for segment {}", new java.util.UUID(msb, lsb), t);
-            }
+            LOG.debug("Prefetch scheduling failed for segment {}", new java.util.UUID(msb, lsb), t);
         }
     }
 
diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
index e815e3e0c5..91532eef50 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
@@ -131,8 +131,6 @@ public class CachingPersistenceTest {
 
     @Test
     public void prefetchOnCacheHitLoadsReferences() throws Exception {
-
-        // Create a tar-backed FileStore and build real segments with references
         File dir = getFileStoreFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         SegmentArchiveReader archiveReader = null;
@@ -142,8 +140,10 @@ public class CachingPersistenceTest {
             SegmentReader sr = new CachingSegmentReader(() -> writer, null, 16, 2, NoopStats.INSTANCE);
 
             // Two referenced nodes in separate segments
-            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE); writer.flush();
-            RecordId a2 = writer.writeNode(EmptyNodeState.EMPTY_NODE); writer.flush();
+            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE);
+            writer.flush();
+            RecordId a2 = writer.writeNode(EmptyNodeState.EMPTY_NODE);
+            writer.flush();
 
             // Root node referencing both
             NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
@@ -194,10 +194,9 @@ public class CachingPersistenceTest {
             // seed root
             cache.writeSegment(root.getMostSignificantBits(), root.getLeastSignificantBits(), rootBuffer);
 
-            // Reader under test, delegate reads from real tar archive
             CachingSegmentArchiveReader reader = new CachingSegmentArchiveReader(cache, archiveReader);
 
-            // Act: read root. Since it's a cache hit, prefetch should be scheduled for r1 and r2.
+            // Read root. Since it's a cache hit, prefetch should be scheduled for r1 and r2.
             Buffer got = reader.readSegment(root.getMostSignificantBits(), root.getLeastSignificantBits());
             assertNotNull(got);
 
@@ -217,9 +216,7 @@ public class CachingPersistenceTest {
 
 
     @Test
-    public void skipAlreadyCachedReferencesAreNotPrefetched() throws Exception {
-
-        // Create a tar-backed FileStore and build segments with references
+    public void alreadyCachedReferencesAreNotPrefetched() throws Exception {
         File dir = getFileStoreFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         try {
@@ -241,13 +238,10 @@ public class CachingPersistenceTest {
             UUID r2 = a2.getSegmentId().asUUID();
             UUID root = rootRec.getSegmentId().asUUID();
 
-
-            // Close the FileStore to ensure tar index is written and readable
             fs.close();
             fs = null;
 
 
-            // Open the tar archive and fetch buffers
             TarPersistence tar = new TarPersistence(dir);
             SegmentArchiveManager am = tar.createArchiveManager(false, false,
                     new IOMonitorAdapter(),
@@ -290,21 +284,17 @@ public class CachingPersistenceTest {
             cache.writeSegment(root.getMostSignificantBits(), root.getLeastSignificantBits(), rootBuffer);
             cache.writeSegment(r1.getMostSignificantBits(), r1.getLeastSignificantBits(), buf1);
 
-            // Reader under test, delegate reads from real tar archive
             CachingSegmentArchiveReader reader = new CachingSegmentArchiveReader(cache, archiveReader);
 
-            // Act
             Buffer got = reader.readSegment(root.getMostSignificantBits(), root.getLeastSignificantBits());
             assertNotNull(got);
 
             boolean completed = latch.await(5, TimeUnit.SECONDS);
             assertTrue("Prefetch for non-cached ref did not complete in time", completed);
 
-            // Assert r1 was not written again (still exactly the initial seed), r2 was written once by prefetch
             assertTrue(cache.containsSegment(r1.getMostSignificantBits(), r1.getLeastSignificantBits()));
             assertTrue(cache.containsSegment(r2.getMostSignificantBits(), r2.getLeastSignificantBits()));
-            // r1 write count includes the pre-seed; ensure no additional write happened via prefetch.
-            // Pre-seed performed exactly 1 write for r1, so count should remain 1.
+
             assertEquals(1, r1Writes.get());
             assertEquals(1, r2Writes.get());
 
@@ -325,8 +315,10 @@ public class CachingPersistenceTest {
             SegmentWriter writer = DefaultSegmentWriterBuilder.defaultSegmentWriterBuilder("t").build(fs);
             SegmentReader sr = new CachingSegmentReader(() -> writer, null, 16, 2, NoopStats.INSTANCE);
 
-            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE); writer.flush();
-            RecordId a2 = writer.writeNode(EmptyNodeState.EMPTY_NODE); writer.flush();
+            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE);
+            writer.flush();
+            RecordId a2 = writer.writeNode(EmptyNodeState.EMPTY_NODE);
+            writer.flush();
 
             NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
             builder.setChildNode("ref1", sr.readNode(a1));
@@ -368,13 +360,8 @@ public class CachingPersistenceTest {
                     boolean isR1 = (msb == r1.getMostSignificantBits() && lsb == r1.getLeastSignificantBits());
                     boolean isR2 = (msb == r2.getMostSignificantBits() && lsb == r2.getLeastSignificantBits());
                     super.writeSegment(msb, lsb, buffer);
-                    if (isR1) {
-                        r1Writes.incrementAndGet();
-                    }
-                    if (isR2) {
-                        if (r2Writes.incrementAndGet() == 1) {
-                            latch.countDown();
-                        }
+                    if ((isR1 || isR2) && latch.getCount() > 0) {
+                        latch.countDown();
                     }
                 }
             };
@@ -403,7 +390,6 @@ public class CachingPersistenceTest {
 
     @Test
     public void concurrentCacheHitsDeduplicatePrefetchTasks() throws Exception {
-        // Build segments: root references a1 only, to focus on a single target UUID
         File dir = getFileStoreFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         SegmentArchiveReader archiveReader = null;
@@ -411,7 +397,8 @@ public class CachingPersistenceTest {
             SegmentWriter writer = DefaultSegmentWriterBuilder.defaultSegmentWriterBuilder("t").build(fs);
             SegmentReader sr = new CachingSegmentReader(() -> writer, null, 16, 2, NoopStats.INSTANCE);
 
-            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE); writer.flush();
+            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE);
+            writer.flush();
 
             NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
             builder.setChildNode("ref1", sr.readNode(a1));
@@ -506,7 +493,8 @@ public class CachingPersistenceTest {
             SegmentWriter writer = DefaultSegmentWriterBuilder.defaultSegmentWriterBuilder("t").build(fs);
             SegmentReader sr = new CachingSegmentReader(() -> writer, null, 16, 2, NoopStats.INSTANCE);
 
-            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE); writer.flush();
+            RecordId a1 = writer.writeNode(EmptyNodeState.EMPTY_NODE);
+            writer.flush();
 
             NodeBuilder builder = EmptyNodeState.EMPTY_NODE.builder();
             builder.setChildNode("ref1", sr.readNode(a1));


(jackrabbit-oak) 03/03: OAK-11932 fix the test

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e7d4c084fb235ed88c7cdc986b736bce4a14f584
Author: Miroslav Smiljanic <mi...@apache.com>
AuthorDate: Tue Sep 16 18:34:08 2025 +0200

    OAK-11932 fix the test
---
 .../spi/persistence/persistentcache/CachingPersistenceTest.java  | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
index 7ad701e579..8c03f06da6 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
@@ -45,6 +45,7 @@ import org.apache.jackrabbit.oak.stats.NoopStats;
 import org.jetbrains.annotations.NotNull;
 import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -306,7 +307,6 @@ public class CachingPersistenceTest {
 
     @Test
     public void prefetchDisabledDoesNotScheduleOrWrite() throws Exception {
-        System.setProperty("oak.segment.cache.prefetch.enabled", "false");
 
         File dir = folder.newFolder();
         FileStore fs = fileStoreBuilder(dir).build();
@@ -369,7 +369,14 @@ public class CachingPersistenceTest {
             // Seed root; with prefetch disabled, reading root should not write r1 or r2
             cache.writeSegment(root.getMostSignificantBits(), root.getLeastSignificantBits(), rootBuffer);
 
+            String prev = System.getProperty("oak.segment.cache.prefetch.enabled");
+            System.setProperty("oak.segment.cache.prefetch.enabled", "false");
             CachingSegmentArchiveReader reader = new CachingSegmentArchiveReader(cache, archiveReader);
+            if (prev != null) {
+                System.setProperty("oak.segment.cache.prefetch.enabled", prev);
+            } else {
+                System.clearProperty("oak.segment.cache.prefetch.enabled");
+            }
 
             Buffer got = reader.readSegment(root.getMostSignificantBits(), root.getLeastSignificantBits());
             assertNotNull(got);


(jackrabbit-oak) 02/03: OAK-11932 fix the test

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 24d2970ce8b2d90ed978de890a6ea4b9775b1c62
Author: Miroslav Smiljanic <mi...@apache.com>
AuthorDate: Tue Sep 16 18:27:11 2025 +0200

    OAK-11932 fix the test
---
 .../persistence/persistentcache/CachingPersistenceTest.java    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
index 91532eef50..7ad701e579 100644
--- a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
+++ b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/CachingPersistenceTest.java
@@ -131,7 +131,7 @@ public class CachingPersistenceTest {
 
     @Test
     public void prefetchOnCacheHitLoadsReferences() throws Exception {
-        File dir = getFileStoreFolder();
+        File dir = folder.newFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         SegmentArchiveReader archiveReader = null;
         try {
@@ -217,7 +217,7 @@ public class CachingPersistenceTest {
 
     @Test
     public void alreadyCachedReferencesAreNotPrefetched() throws Exception {
-        File dir = getFileStoreFolder();
+        File dir = folder.newFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         try {
             SegmentWriter writer = DefaultSegmentWriterBuilder.defaultSegmentWriterBuilder("t").build(fs);
@@ -308,7 +308,7 @@ public class CachingPersistenceTest {
     public void prefetchDisabledDoesNotScheduleOrWrite() throws Exception {
         System.setProperty("oak.segment.cache.prefetch.enabled", "false");
 
-        File dir = getFileStoreFolder();
+        File dir = folder.newFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         SegmentArchiveReader archiveReader = null;
         try {
@@ -390,7 +390,7 @@ public class CachingPersistenceTest {
 
     @Test
     public void concurrentCacheHitsDeduplicatePrefetchTasks() throws Exception {
-        File dir = getFileStoreFolder();
+        File dir = folder.newFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         SegmentArchiveReader archiveReader = null;
         try {
@@ -486,7 +486,7 @@ public class CachingPersistenceTest {
     @Test
     public void inFlightDedupIsReleasedAfterDelegateFailure() throws Exception {
         // Build segments: root references a1 only
-        File dir = getFileStoreFolder();
+        File dir = folder.newFolder();
         FileStore fs = fileStoreBuilder(dir).build();
         SegmentArchiveReader archiveReader = null;
         try {