You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bb...@apache.org on 2022/04/22 11:53:06 UTC

[hbase] branch branch-2.4 updated: HBASE-26942 cache region locations when getAllRegionLocations (#4357)

This is an automated email from the ASF dual-hosted git repository.

bbeaudreault pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-2.4 by this push:
     new 7715e37d377 HBASE-26942 cache region locations when getAllRegionLocations (#4357)
7715e37d377 is described below

commit 7715e37d377c1df88925368827d43d1254c9403b
Author: Ruanhui <32...@users.noreply.github.com>
AuthorDate: Fri Apr 22 19:53:01 2022 +0800

    HBASE-26942 cache region locations when getAllRegionLocations (#4357)
    
    Co-authored-by: huiruan <hu...@tencent.com>
    Signed-off-by: Duo Zhang <zh...@apache.org>
    Signed-off-by: Bryan Beaudreault <bb...@apache.org>
---
 .../hadoop/hbase/client/AsyncNonMetaRegionLocator.java     |  2 +-
 .../hadoop/hbase/client/AsyncTableRegionLocatorImpl.java   |  9 +++++++--
 .../hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java | 14 ++++++++++++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java
index 5798ee5f1fb..6896a2970b0 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncNonMetaRegionLocator.java
@@ -649,7 +649,7 @@ class AsyncNonMetaRegionLocator {
     }
   }
 
-  private void addLocationToCache(HRegionLocation loc) {
+  void addLocationToCache(HRegionLocation loc) {
     addToCache(getTableCache(loc.getRegion().getTable()), createRegionLocations(loc));
   }
 
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableRegionLocatorImpl.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableRegionLocatorImpl.java
index fa3ea1ca4df..da777199d61 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableRegionLocatorImpl.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncTableRegionLocatorImpl.java
@@ -17,6 +17,8 @@
  */
 package org.apache.hadoop.hbase.client;
 
+import static org.apache.hadoop.hbase.util.FutureUtils.addListener;
+
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
@@ -58,8 +60,11 @@ class AsyncTableRegionLocatorImpl implements AsyncTableRegionLocator {
       return conn.registry.getMetaRegionLocations()
         .thenApply(locs -> Arrays.asList(locs.getRegionLocations()));
     }
-    return AsyncMetaTableAccessor.getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME),
-      tableName);
+    CompletableFuture<List<HRegionLocation>> future = AsyncMetaTableAccessor
+            .getTableHRegionLocations(conn.getTable(TableName.META_TABLE_NAME), tableName);
+    addListener(future, (locs, error) -> locs.forEach(loc -> conn.getLocator()
+      .getNonMetaRegionLocator().addLocationToCache(loc)));
+    return future;
   }
 
   @Override
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java
index 76c0b9e49aa..4849b3aa80a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncNonMetaRegionLocator.java
@@ -25,6 +25,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 
 import java.io.IOException;
@@ -467,4 +468,17 @@ public class TestAsyncNonMetaRegionLocator {
     IntStream.range(0, 100).parallel()
         .forEach(i -> LOCATOR.updateCachedLocationOnError(loc, new NotServingRegionException()));
   }
+
+  @Test
+  public void testCacheLocationWhenGetAllLocations() throws Exception {
+    createMultiRegionTable();
+    AsyncConnectionImpl conn = (AsyncConnectionImpl)
+      ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
+    conn.getRegionLocator(TABLE_NAME).getAllRegionLocations().get();
+    List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(TABLE_NAME);
+    for (RegionInfo region : regions) {
+      assertNotNull(conn.getLocator().getNonMetaRegionLocator()
+        .getRegionLocationInCache(TABLE_NAME, region.getStartKey()));
+    }
+  }
 }