hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chenh...@apache.org
Subject hbase git commit: HBASE-15674 HRegionLocator#getAllRegionLocations should put the results in cache
Date Thu, 21 Apr 2016 06:40:58 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1.2 adfd8bb48 -> 3af736a95


HBASE-15674 HRegionLocator#getAllRegionLocations should put the results in cache

Conflicts:
	hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
	hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/3af736a9
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/3af736a9
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/3af736a9

Branch: refs/heads/branch-1.2
Commit: 3af736a95ddca817dedb12aaf7e7d9f6a4e97746
Parents: adfd8bb
Author: chenheng <chenheng@apache.org>
Authored: Thu Apr 21 14:16:06 2016 +0800
Committer: chenheng <chenheng@apache.org>
Committed: Thu Apr 21 14:34:12 2016 +0800

----------------------------------------------------------------------
 .../hadoop/hbase/client/ClusterConnection.java     |  3 +++
 .../hadoop/hbase/client/ConnectionAdapter.java     |  6 ++++++
 .../hadoop/hbase/client/ConnectionManager.java     |  3 ++-
 .../hadoop/hbase/client/ConnectionUtils.java       |  1 +
 .../apache/hadoop/hbase/client/HRegionLocator.java |  6 +++++-
 .../hadoop/hbase/client/TestFromClientSide.java    | 17 +++++++++++++++++
 6 files changed, 34 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/3af736a9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
index f4d464f..ec7f471 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClusterConnection.java
@@ -83,6 +83,9 @@ public interface ClusterConnection extends HConnection {
   @Override
   void clearRegionCache();
 
+
+  void cacheLocation(final TableName tableName, final RegionLocations location);
+
   /**
    * Allows flushing the region cache of all locations that pertain to
    * <code>tableName</code>

http://git-wip-us.apache.org/repos/asf/hbase/blob/3af736a9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
index 040fa6f..4e3e55e 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionAdapter.java
@@ -244,6 +244,12 @@ abstract class ConnectionAdapter implements ClusterConnection {
     wrappedConnection.clearRegionCache(tableName);
   }
 
+
+  @Override
+  public void cacheLocation(TableName tableName, RegionLocations location) {
+    wrappedConnection.cacheLocation(tableName, location);
+  }
+
   @Override
   public void deleteCachedRegionLocation(HRegionLocation location) {
     wrappedConnection.deleteCachedRegionLocation(location);

http://git-wip-us.apache.org/repos/asf/hbase/blob/3af736a9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
index 46b4fdf..ffef9b6 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionManager.java
@@ -1371,7 +1371,8 @@ class ConnectionManager {
      * @param tableName The table name.
      * @param location the new location
      */
-    private void cacheLocation(final TableName tableName, final RegionLocations location)
{
+    @Override
+    public void cacheLocation(final TableName tableName, final RegionLocations location)
{
       metaCache.cacheLocation(tableName, location);
     }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/3af736a9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
index 647295e..63861be 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionUtils.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ExecutorService;
 import org.apache.commons.logging.Log;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.RegionLocations;
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;

http://git-wip-us.apache.org/repos/asf/hbase/blob/3af736a9/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java
index fa85653..d270607 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HRegionLocator.java
@@ -85,12 +85,16 @@ public class HRegionLocator implements RegionLocator {
 
   @Override
   public List<HRegionLocation> getAllRegionLocations() throws IOException {
+    TableName tableName = getName();
     NavigableMap<HRegionInfo, ServerName> locations =
-        MetaScanner.allTableRegions(this.connection, getName());
+        MetaScanner.allTableRegions(this.connection, tableName);
     ArrayList<HRegionLocation> regions = new ArrayList<>(locations.size());
     for (Entry<HRegionInfo, ServerName> entry : locations.entrySet()) {
       regions.add(new HRegionLocation(entry.getKey(), entry.getValue()));
     }
+    if (regions.size() > 0) {
+      connection.cacheLocation(tableName, new RegionLocations(regions));
+    }
     return regions;
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/3af736a9/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
index d942b63..c801839 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
@@ -43,6 +43,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.hadoop.mapreduce.Cluster;
 import org.apache.log4j.Level;
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.logging.Log;
@@ -6187,4 +6188,20 @@ public class TestFromClientSide {
     assertNull(s.next());
     table.close();
   }
+
+  @Test
+  public void testRegionCache() throws IOException {
+    HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testRegionCache"));
+    HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
+    htd.addFamily(fam);
+    byte[][] KEYS = HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE;
+    Admin admin = TEST_UTIL.getHBaseAdmin();
+    admin.createTable(htd, KEYS);
+    HRegionLocator locator =
+      (HRegionLocator) admin.getConnection().getRegionLocator(htd.getTableName());
+    List<HRegionLocation> results = locator.getAllRegionLocations();
+    int number = ((ConnectionManager.HConnectionImplementation)admin.getConnection())
+      .getNumberOfCachedRegionLocations(htd.getTableName());
+    assertEquals(results.size(), number);
+  }
 }


Mime
View raw message