chia7712 commented on code in PR #19961:
URL: https://github.com/apache/kafka/pull/19961#discussion_r2193010971


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/AbstractIndex.java:
##########
@@ -288,12 +282,10 @@ public void closeHandler() {
         // However, in some cases it can pause application threads(STW) for a 
long moment reading metadata from a physical disk.
         // To prevent this, we forcefully cleanup memory mapping within proper 
execution which never affects API responsiveness.
         // See https://issues.apache.org/jira/browse/KAFKA-4614 for the 
details.
-        lock.lock();
-        try {
-            safeForceUnmap();
-        } finally {
-            lock.unlock();
-        }
+        inLockThrows(() ->

Review Comment:
   ```java
   inLockThrows(() -> inRemapWriteLockThrows(this::safeForceUnmap));
   ```



##########
server-common/src/main/java/org/apache/kafka/server/util/LockUtils.java:
##########
@@ -49,4 +57,73 @@ public static <T> T inLock(Lock lock, Supplier<T> supplier) {
             lock.unlock();
         }
     }
+
+    /**
+     * Executes the given {@link Runnable} within the context of the specified 
{@link Lock}.
+     * The lock is acquired before executing the runnable and released after 
the execution,
+     * ensuring that the lock is always released, even if an exception is 
thrown.
+     *
+     * @param lock     the lock to be acquired and released
+     * @param runnable the runnable to be executed within the lock context
+     * @throws NullPointerException if either {@code lock} or {@code runnable} 
is null
+     */
+    public static void inLock(Lock lock, Runnable runnable) {

Review Comment:
   Excuse me, have we considered replacing `inLock` by `inLockThrows`? Keeping 
both varieties seems a bit verbose to me.



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to