HBASE-21859 Add clearRegionLocationCache method for AsyncConnection
authorzhangduo <zhangduo@apache.org>
Fri, 8 Feb 2019 07:29:11 +0000 (15:29 +0800)
committerDuo Zhang <zhangduo@apache.org>
Wed, 13 Feb 2019 02:07:29 +0000 (10:07 +0800)
Signed-off-by: Guanghao Zhang <zghao@apache.org>
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnection.java
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncConnectionImpl.java
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java
hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRegionLocator.java
hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncRegionLocator.java

index 5640eb3..564d4db 100644 (file)
@@ -53,6 +53,16 @@ public interface AsyncConnection extends Closeable {
   AsyncTableRegionLocator getRegionLocator(TableName tableName);
 
   /**
+   * Clear all the entries in the region location cache, for all the tables.
+   * <p/>
+   * If you only want to clear the cache for a specific table, use
+   * {@link AsyncTableRegionLocator#clearRegionLocationCache()}.
+   * <p/>
+   * This may cause performance issue so use it with caution.
+   */
+  void clearRegionLocationCache();
+
+  /**
    * Retrieve an {@link AsyncTable} implementation for accessing a table.
    * <p>
    * The returned instance will use default configs. Use {@link #getTableBuilder(TableName)} if
index 4a32546..07f62a8 100644 (file)
@@ -353,4 +353,9 @@ class AsyncConnectionImpl implements AsyncConnection {
     return new HBaseHbck(MasterProtos.HbckService.newBlockingStub(
       rpcClient.createBlockingRpcChannel(masterServer, user, rpcTimeout)), rpcControllerFactory);
   }
+
+  @Override
+  public void clearRegionLocationCache() {
+    locator.clearCache();
+  }
 }
index 1a1f32a..5d5c7c3 100644 (file)
@@ -569,6 +569,10 @@ class AsyncNonMetaRegionLocator {
     }
   }
 
+  void clearCache() {
+    cache.clear();
+  }
+
   // only used for testing whether we have cached the location for a region.
   @VisibleForTesting
   RegionLocations getRegionLocationInCache(TableName tableName, byte[] row) {
index cc2a21b..3eb44b7 100644 (file)
@@ -159,4 +159,9 @@ class AsyncRegionLocator {
       nonMetaRegionLocator.clearCache(tableName);
     }
   }
+
+  void clearCache() {
+    metaRegionLocator.clearCache();
+    nonMetaRegionLocator.clearCache();
+  }
 }
index 0b51ce8..0a94def 100644 (file)
@@ -49,6 +49,7 @@ import org.apache.hadoop.hbase.testclassification.ClientTests;
 import org.apache.hadoop.hbase.testclassification.MediumTests;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Threads;
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.ClassRule;
@@ -109,6 +110,11 @@ public class TestAsyncRegionLocator {
     TEST_UTIL.shutdownMiniCluster();
   }
 
+  @After
+  public void tearDownAfterTest() {
+    LOCATOR.clearCache();
+  }
+
   @Test
   public void testTimeout() throws InterruptedException, ExecutionException {
     SLEEP_MS = 1000;