wchevreuil commented on code in PR #8904:
URL: https://github.com/apache/hbase/pull/8904#discussion_r4612550702


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java:
##########
@@ -138,6 +138,12 @@ public class BucketCache implements BlockCache, HeapSize {
   private static final String STRONG_REF_KEY = 
"hbase.bucketcache.offsetlock.usestrongref";
   private static final boolean STRONG_REF_DEFAULT = false;
 
+  /**
+   * Frequency in seconds to clean up the underlying IdReadWriteLock 
ObjectPool (default: 10s)
+   */
+  static final String LOCK_JANITOR_PERIOD_CONFIG_NAME = 
"hbase.bucketcache.lock.janitor.period";
+  private static final int DEFAULT_LOCK_JANITOR_PERIOD = 10;

Review Comment:
   nit: let's follow property naming conventions for periods, by mentioning the 
unit explicitly:
   
   `hbase.bucketcache.lock.janitor.period.seconds`



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java:
##########
@@ -1010,6 +1035,31 @@ public void run() {
     }
   }
 
+  /**
+   * Cleans up stale lock references from the underlying ObjectPool.
+   */
+  private static class LockJanitorThread extends Thread {
+    private final IdReadWriteLockWithObjectPool<Long> offsetLock;
+
+    public LockJanitorThread(IdReadWriteLockWithObjectPool<Long> offsetLock) {
+      super("BucketCacheLockJanitor");
+      setDaemon(true);
+      this.offsetLock = offsetLock;
+    }
+
+    @Override
+    public void run() {
+      if (LOG.isTraceEnabled()) {
+        int sizeBefore = offsetLock.getPoolSize();
+        offsetLock.purge();
+        int sizeAfter = offsetLock.getPoolSize();
+        LOG.trace("LockJanitor purged lock pool: size {} -> {}", sizeBefore, 
sizeAfter);
+      } else {
+        offsetLock.purge();
+      }
+    }
+  }

Review Comment:
   As this may be used wherever IdReadWriteLockWithObjectPool is required, it 
would be better to define it as a top level class under 
org.apache.hadoop.hbase.util?



##########
hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java:
##########
@@ -268,6 +274,11 @@ protected enum CacheState {
     Executors.newScheduledThreadPool(1,
       new 
ThreadFactoryBuilder().setNameFormat("BucketCacheStatsExecutor").setDaemon(true).build());
 
+  /** Janitor thread schedule pool (critical cleanup, don't remove) */
+  private transient final ScheduledExecutorService janitorThreadPool =
+    Executors.newScheduledThreadPool(1,
+      new 
ThreadFactoryBuilder().setNameFormat("BucketCacheJanitor").setDaemon(true).build());

Review Comment:
   nit: rename thread to: BucketCacheRWLockJanitor



-- 
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