chaijunjie0101 commented on code in PR #7117: URL: https://github.com/apache/hbase/pull/7117#discussion_r2202789874
########## 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: thanks for reviewing, I flow your suggest to reuse the Timer in connection, the UT passed, if you have tine, please review again~,thanks ########## 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. thanks for reviewing, I flow your suggest to reuse the Timer in connection, the UT passed, if you have tine, please review again~,thanks -- 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