Apache9 commented on code in PR #7117:
URL: https://github.com/apache/hbase/pull/7117#discussion_r2182990316


##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java:
##########
@@ -91,6 +95,9 @@ class AsyncNonMetaRegionLocator {
 
   private final ConcurrentMap<TableName, TableCache> cache = new 
ConcurrentHashMap<>();
 
+  // A chore service to invalidate table cache which table is not exist or 
disabled.
+  private ChoreService metaCacheInvalidateChoreService;

Review Comment:
   We have a timer in AsyncConnectionImpl, better reuse that thread to do this.



##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java:
##########
@@ -618,4 +631,67 @@ int getNumberOfCachedRegionLocations(TableName tableName) {
     return tableCache.regionLocationCache.getAll().stream()
       .mapToInt(RegionLocations::numNonNullElements).sum();
   }
+
+  private void spawnMetaCacheInvalidateChore(int metaCacheInvalidateInterval) {
+    if (metaCacheInvalidateChoreService == null) {
+      metaCacheInvalidateChoreService = new ChoreService("Meta Cache Chore 
Service");
+    }
+    metaCacheInvalidateChoreService
+      .scheduleChore(getMetaCacheInvalidateChore(metaCacheInvalidateInterval));
+  }
+
+  private ScheduledChore getMetaCacheInvalidateChore(int 
metaCacheInvalidateInterval) {
+    return new ScheduledChore("MetaCacheChore", new Stoppable() {
+      private volatile boolean isStopped = false;
+
+      @Override
+      public void stop(String why) {
+        isStopped = true;
+      }
+
+      @Override
+      public boolean isStopped() {
+        return isStopped;
+      }
+    }, metaCacheInvalidateInterval, metaCacheInvalidateInterval) {
+
+      @Override
+      protected void chore() {
+        invalidateTableCache();
+      }
+    };
+  }
+
+  private void invalidateTableCache() {
+    Set<TableName> cachedTables = cache.keySet();
+    if (!cachedTables.isEmpty()) {
+      boolean shouldInvalidateCache;
+      AsyncAdmin admin = conn.getAdmin();
+      for (TableName tableName : cachedTables) {
+        try {
+          shouldInvalidateCache =
+            FutureUtils.get(admin.isTableDisabled(tableName), 5, 
TimeUnit.SECONDS);

Review Comment:
   If you use timer to do the cleanup then you can not use blocking call here, 
you need to add callback to the returned CompletableFuture to do the cleanup.



-- 
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: issues-unsubscr...@hbase.apache.org

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

Reply via email to