Apache9 commented on code in PR #7117: URL: https://github.com/apache/hbase/pull/7117#discussion_r2232993544
########## hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java: ########## @@ -618,4 +635,60 @@ int getNumberOfCachedRegionLocations(TableName tableName) { return tableCache.regionLocationCache.getAll().stream() .mapToInt(RegionLocations::numNonNullElements).sum(); } + + private TimerTask getInvalidateMetaCacheTask(long metaCacheInvalidateInterval) { + return new TimerTask() { + @Override + public void run(Timeout timeout) throws Exception { + FutureUtils.addListener(invalidateTableCache(), (res, err) -> { + if (err != null) { + LOG.warn("InvalidateTableCache failed.", err); + } + AsyncConnectionImpl.RETRY_TIMER.newTimeout(this, metaCacheInvalidateInterval, + TimeUnit.MILLISECONDS); + }); + } + }; + } + + private CompletableFuture<Void> invalidateTableCache() { + CompletableFuture<Void> future = new CompletableFuture<>(); + Iterator<TableName> tbnIter = cache.keySet().iterator(); + AsyncAdmin admin = conn.getAdmin(); + invalidateCache(future, tbnIter, admin); + return future; + } + + private void invalidateCache(CompletableFuture<Void> future, Iterator<TableName> tbnIter, + AsyncAdmin admin) { + if (tbnIter.hasNext()) { + TableName tableName = tbnIter.next(); + FutureUtils.addListener(admin.isTableDisabled(tableName), (tableDisabled, err) -> { + boolean shouldInvalidateCache = false; + if (err != null) { + if (err instanceof TableNotFoundException) { + LOG.info("Table {} was not exist, will invalidate it's cache.", tableName); Review Comment: it's -> its ########## hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java: ########## @@ -253,6 +257,19 @@ private boolean tryComplete(LocateRequest req, CompletableFuture<RegionLocations default: // Doing nothing } + + // The interval of invalidate meta cache task, + // if disable/delete table using same connection or usually create a new connection, no need to + // set it. + // Suggest set it to 24h or a higher value, because disable/delete table usually not very + // frequently. + long metaCacheInvalidateInterval = conn.getConfiguration() + .getLong("hbase.client.connection.metacache.invalidate-interval.ms", 0L); + if (metaCacheInvalidateInterval > 0) { + TimerTask invalidateMetaCacheTask = getInvalidateMetaCacheTask(metaCacheInvalidateInterval); + AsyncConnectionImpl.RETRY_TIMER.newTimeout(invalidateMetaCacheTask, Review Comment: Better pass this retryTimer in so it is a bit easier for us to write UTs. -- 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