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


##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java:
##########
@@ -618,4 +635,48 @@ 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 {
+        invalidateTableCache();
+        AsyncConnectionImpl.RETRY_TIMER.newTimeout(this, 
metaCacheInvalidateInterval,
+          TimeUnit.MILLISECONDS);
+      }
+    };
+  }
+
+  private void invalidateTableCache() {
+    // Should not throw any exception from here, it will affect schedule a new 
specified TimerTask.
+    Set<TableName> cachedTables = cache.keySet();
+    if (!cachedTables.isEmpty()) {
+      AsyncAdmin admin = conn.getAdmin();
+      for (TableName tableName : cachedTables) {
+        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);
+              shouldInvalidateCache = true;
+            } else {
+              // If other exception occurred, just skip to invalidate it cache.
+              LOG.warn("Get table state of {} failed, skip to invalidate it's 
cache.", tableName,
+                err);
+              return;
+            }
+          } else if (tableDisabled != null && tableDisabled) {

Review Comment:
   Typically we do not need null check here.



##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java:
##########
@@ -618,4 +635,48 @@ 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 {
+        invalidateTableCache();
+        AsyncConnectionImpl.RETRY_TIMER.newTimeout(this, 
metaCacheInvalidateInterval,
+          TimeUnit.MILLISECONDS);
+      }
+    };
+  }
+
+  private void invalidateTableCache() {
+    // Should not throw any exception from here, it will affect schedule a new 
specified TimerTask.
+    Set<TableName> cachedTables = cache.keySet();
+    if (!cachedTables.isEmpty()) {
+      AsyncAdmin admin = conn.getAdmin();
+      for (TableName tableName : cachedTables) {

Review Comment:
   To reduce the pressure to HMaster, I suggest here we do the request one by 
one, i.e, send a new isTableDisabled request in the callback of the previous 
request.
   
   And in the last callback, we schedule the new timer task.



##########
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java:
##########
@@ -618,4 +635,48 @@ 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 {
+        invalidateTableCache();
+        AsyncConnectionImpl.RETRY_TIMER.newTimeout(this, 
metaCacheInvalidateInterval,

Review Comment:
   We should not put this line here, as the above method is also asynchronous...
   
   We need to reschedule the timer task in the callbacks...



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