rishabhdaim commented on code in PR #3071:
URL: https://github.com/apache/jackrabbit-oak/pull/3071#discussion_r3766823845


##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/impl/CacheMaintenanceExecutor.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.cache.impl;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.RejectedExecutionHandler;
+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;
+
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The process-wide pool Caffeine-backed Oak caches run their maintenance 
(eviction, removal
+ * notification, buffer drains) on, instead of {@link 
java.util.concurrent.ForkJoinPool#commonPool()}.
+ */
+public final class CacheMaintenanceExecutor {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(CacheMaintenanceExecutor.class);
+
+    private static final Thread.UncaughtExceptionHandler 
UNCAUGHT_EXCEPTION_HANDLER = (t, e) ->
+            LOG.warn("Uncaught exception in thread {}", t.getName(), e);
+
+    private static final String THREAD_PREFIX = "oak-cache-maintenance-";

Review Comment:
   fixed in 
https://github.com/apache/jackrabbit-oak/pull/3071/commits/9a664888e298537fe6feefb04fdca234204336a5



##########
oak-core-spi/src/main/java/org/apache/jackrabbit/oak/cache/api/CacheBuilder.java:
##########
@@ -255,11 +285,19 @@ private LoadingCache<K, V> buildCaffeine(CacheLoader<K, 
V> loader) {
     @SuppressWarnings({"unchecked", "rawtypes"})
     private Caffeine<K, V> configureCaffeineBuilder() {
         Caffeine caffeineBuilder = Caffeine.newBuilder();
-        if (refreshAfterWrite == null) {
-            // Caffeine uses one executor for both maintenance and refresh 
work.
-            // Run maintenance on the caller thread unless refresh must stay 
asynchronous.
-            caffeineBuilder = caffeineBuilder.executor(Runnable::run);
-        }
+        // Caffeine uses one executor for both maintenance and refresh. A 
refresh loader may make a
+        // remote call; running it inline would block every caller thread that 
triggers a refresh on
+        // that call, which defeats the point of refreshAfterWrite (return the 
stale value, reload in
+        // the background). So refreshing caches always run on Oak's 
maintenance executor, regardless
+        // of the toggle - the tradeoff is that a slow reload can occupy one 
of the pool's threads for
+        // longer, which is preferable to blocking callers. Zero-capacity 
caches are a "disable
+        // caching" idiom relied upon elsewhere for immediate eviction, so 
they always run inline -
+        // otherwise a read immediately following a write could still observe 
the entry before
+        // background maintenance evicts it.
+        boolean zeroCapacity = maximumWeight == 0 || maximumSize == 0;
+        boolean inline = zeroCapacity

Review Comment:
   fixed in 
https://github.com/apache/jackrabbit-oak/pull/3071/commits/9a664888e298537fe6feefb04fdca234204336a5



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to