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

joerghoh 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 045951c9ea OAK-12282 : defining a fixed bound for the 
AbstractDiskCache (#2978)
045951c9ea is described below

commit 045951c9ea5518cb737d369c1b9e12633845c2b0
Author: Patrique Legault <[email protected]>
AuthorDate: Tue Jul 7 12:08:53 2026 -0400

    OAK-12282 : defining a fixed bound for the AbstractDiskCache (#2978)
    
    * OAK-12282 defining a fixed bound for the AbstractDiskCache
    ---------
    
    Co-authored-by: patlego <[email protected]>
---
 .../persistentcache/PersistentDiskCache.java       |  3 +-
 .../persistentcache/PersistentRedisCache.java      |  2 +-
 .../persistentcache/AbstractPersistentCache.java   | 35 ++++++++++++++++++++--
 .../persistentcache/SegmentCacheStats.java         | 11 ++++++-
 .../persistence/persistentcache/package-info.java  |  2 +-
 .../persistentcache/MemoryPersistentCache.java     |  3 +-
 .../persistentcache/PersistentCacheStatsTest.java  |  4 +--
 7 files changed, 51 insertions(+), 9 deletions(-)

diff --git 
a/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
 
b/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
index 2568723938..239cc9148f 100644
--- 
a/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
+++ 
b/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCache.java
@@ -111,7 +111,8 @@ public class PersistentDiskCache extends 
AbstractPersistentCache {
                 () -> maxCacheSizeBytes,
                 () -> Long.valueOf(directory.listFiles().length),
                 () -> FileUtils.sizeOfDirectory(directory),
-                () -> evictionCount.get());
+                () -> evictionCount.get(),
+                () -> discardCount.get());
     }
 
     @Override
diff --git 
a/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentRedisCache.java
 
b/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentRedisCache.java
index 204484e23c..754e657fc5 100644
--- 
a/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentRedisCache.java
+++ 
b/oak-segment-remote/src/main/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentRedisCache.java
@@ -73,7 +73,7 @@ public class PersistentRedisCache extends 
AbstractPersistentCache {
         this.redisPool = new JedisPool(jedisPoolConfig, redisHost, redisPort, 
redisConnectionTimeout,
                 redisSocketTimeout, null, redisDBIndex, null);
         this.segmentCacheStats = new SegmentCacheStats(NAME, 
this::getRedisMaxMemory, this::getCacheElementCount,
-                this::getCurrentWeight, this::getNumberOfEvictedKeys);
+                this::getCurrentWeight, this::getNumberOfEvictedKeys, () -> 
discardCount.get());
     }
 
     private long getCacheElementCount() {
diff --git 
a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/AbstractPersistentCache.java
 
b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/AbstractPersistentCache.java
index e60ae43867..f1641ffb53 100644
--- 
a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/AbstractPersistentCache.java
+++ 
b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/AbstractPersistentCache.java
@@ -22,6 +22,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
 
 import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
 import org.apache.jackrabbit.oak.commons.Buffer;
+import org.apache.jackrabbit.oak.commons.log.LogSilencer;
 import org.apache.jackrabbit.oak.commons.time.Stopwatch;
 import org.apache.jackrabbit.oak.segment.spi.RepositoryNotReachableException;
 import org.jetbrains.annotations.NotNull;
@@ -31,27 +32,53 @@ import org.slf4j.LoggerFactory;
 import java.io.Closeable;
 import java.util.Set;
 import java.util.UUID;
+import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
 public abstract class AbstractPersistentCache implements PersistentCache, 
Closeable {
     private static final Logger logger = 
LoggerFactory.getLogger(AbstractPersistentCache.class);
 
     public static final int THREADS = 
Integer.getInteger("oak.segment.cache.threads", 10);
+    public static final int WRITE_QUEUE_SIZE = 
Integer.getInteger("oak.segment.cache.writeQueueSize", 100);
 
     protected ExecutorService executor;
     protected AtomicLong cacheSize = new AtomicLong(0);
     protected PersistentCache nextCache;
     protected final Set<String> writesPending;
+    protected AtomicLong discardCount = new AtomicLong();
 
     protected SegmentCacheStats segmentCacheStats;
 
+    private final LogSilencer writeQueueFullSilencer = new LogSilencer();
+
     public AbstractPersistentCache() {
-        executor = Executors.newFixedThreadPool(THREADS);
+        AtomicInteger threadCount = new AtomicInteger(0);
+        ThreadFactory threadFactory = r -> {
+            Thread t = new Thread(r, "segment-cache-writer-" + 
threadCount.incrementAndGet());
+            t.setDaemon(true);
+            return t;
+        };
+        BlockingQueue<Runnable> writeQueue = new 
LinkedBlockingQueue<>(WRITE_QUEUE_SIZE);
+        executor = new ThreadPoolExecutor(
+                THREADS, THREADS,
+                0L, TimeUnit.MILLISECONDS,
+                writeQueue,
+                threadFactory,
+                (r, e) -> {
+                    discardCount.incrementAndGet();
+                    if (!writeQueueFullSilencer.silence("writeQueueFull")) {
+                        logger.warn("Segment write task discarded: write queue 
full (capacity={}, totalDiscarded={}){}",
+                                WRITE_QUEUE_SIZE, discardCount.get(), 
LogSilencer.SILENCING_POSTFIX);
+                    }
+                });
         writesPending = ConcurrentHashMap.newKeySet();
     }
 
@@ -148,4 +175,8 @@ public abstract class AbstractPersistentCache implements 
PersistentCache, Closea
     public int getWritesPending() {
         return writesPending.size();
     }
+
+    public long getWriteDiscardCount() {
+        return discardCount.get();
+    }
 }
diff --git 
a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/SegmentCacheStats.java
 
b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/SegmentCacheStats.java
index 541e31aa82..a29148852e 100644
--- 
a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/SegmentCacheStats.java
+++ 
b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/SegmentCacheStats.java
@@ -54,16 +54,21 @@ public class SegmentCacheStats extends AbstractCacheStats {
     @NotNull
     final AtomicLong missCount = new AtomicLong();
 
+    @NotNull
+    private final Supplier<Long> writeDiscardCountSupplier;
+
     public SegmentCacheStats(@NotNull String name,
                              @NotNull Supplier<Long> maximumWeight,
                              @NotNull Supplier<Long> elementCount,
                              @NotNull Supplier<Long> currentWeight,
-                             @NotNull Supplier<Long> evictionCount) {
+                             @NotNull Supplier<Long> evictionCount,
+                             @NotNull Supplier<Long> writeDiscardCount) {
         super(name);
         this.maximumWeight = maximumWeight;
         this.elementCount = requireNonNull(elementCount);
         this.currentWeight = requireNonNull(currentWeight);
         this.evictionCount = evictionCount;
+        this.writeDiscardCountSupplier = requireNonNull(writeDiscardCount);
     }
 
     @Override
@@ -78,6 +83,10 @@ public class SegmentCacheStats extends AbstractCacheStats {
         );
     }
 
+    public long getWriteDiscardCount() {
+        return writeDiscardCountSupplier.get();
+    }
+
     @Override
     public long getElementCount() {
         return elementCount.get();
diff --git 
a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/package-info.java
 
b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/package-info.java
index 0ad0171f1b..96eb50916c 100644
--- 
a/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/package-info.java
+++ 
b/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/package-info.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 @Internal(since = "1.0.0")
-@Version("6.1.0")
+@Version("7.0.0")
 package org.apache.jackrabbit.oak.segment.spi.persistence.persistentcache;
 
 import org.apache.jackrabbit.oak.commons.annotations.Internal;
diff --git 
a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/MemoryPersistentCache.java
 
b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/MemoryPersistentCache.java
index 896a98c8e5..db0135f476 100644
--- 
a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/MemoryPersistentCache.java
+++ 
b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/MemoryPersistentCache.java
@@ -38,7 +38,8 @@ class MemoryPersistentCache extends AbstractPersistentCache {
                 () -> null,
                 () -> null,
                 () -> null,
-                () -> null);
+                () -> null,
+                () -> 0L);
     }
 
     @Override
diff --git 
a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/PersistentCacheStatsTest.java
 
b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/PersistentCacheStatsTest.java
index df2013c26f..7aa5bcedd9 100644
--- 
a/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/PersistentCacheStatsTest.java
+++ 
b/oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/spi/persistence/persistentcache/PersistentCacheStatsTest.java
@@ -170,7 +170,7 @@ public class PersistentCacheStatsTest {
         HashMap<UUID, Buffer> segments = new HashMap<>();
 
         public PersistentCacheImpl() {
-            segmentCacheStats = new SegmentCacheStats("stats", () -> 
maximumWeight, () -> elementCount.get(), () -> currentWeight.get(), () -> 
evictionCount.get());
+            segmentCacheStats = new SegmentCacheStats("stats", () -> 
maximumWeight, () -> elementCount.get(), () -> currentWeight.get(), () -> 
evictionCount.get(), () -> 0L);
         }
 
         long maximumWeight = Long.MAX_VALUE;
@@ -179,7 +179,7 @@ public class PersistentCacheStatsTest {
         AtomicLong evictionCount = new AtomicLong();
 
         void AbstractPersistentCache() {
-            segmentCacheStats = new SegmentCacheStats("stats", () -> 
maximumWeight, () -> elementCount.get(), () -> currentWeight.get(), () -> 
evictionCount.get());
+            segmentCacheStats = new SegmentCacheStats("stats", () -> 
maximumWeight, () -> elementCount.get(), () -> currentWeight.get(), () -> 
evictionCount.get(), () -> 0L);
         }
 
         @Override

Reply via email to