You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ch...@apache.org on 2016/04/21 08:19:57 UTC
hbase git commit: HBASE-15674 HRegionLocator#getAllRegionLocations
should put the results in cache
Repository: hbase
Updated Branches:
refs/heads/master 58f175f0e -> 03f3c392a
HBASE-15674 HRegionLocator#getAllRegionLocations should put the results in cache
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/03f3c392
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/03f3c392
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/03f3c392
Branch: refs/heads/master
Commit: 03f3c392a3ae940f26ddef56e6991a07f2c993f7
Parents: 58f175f
Author: chenheng <ch...@apache.org>
Authored: Thu Apr 21 14:16:06 2016 +0800
Committer: chenheng <ch...@apache.org>
Committed: Thu Apr 21 14:19:39 2016 +0800
----------------------------------------------------------------------
.../hadoop/hbase/client/ClusterConnection.java | 3 +++
.../hbase/client/ConnectionImplementation.java | 3 ++-
.../apache/hadoop/hbase/client/HRegionLocator.java | 7 ++++++-
.../hadoop/hbase/client/TestFromClientSide.java | 16 ++++++++++++++++
4 files changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/03f3c392/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 d348ffc..3027761 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
@@ -86,6 +86,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/03f3c392/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
index 21e7e51..9a7dfc7 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ConnectionImplementation.java
@@ -927,7 +927,8 @@ class ConnectionImplementation implements ClusterConnection, Closeable {
* @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/03f3c392/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 782ab66..4d2311d 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
@@ -83,11 +83,16 @@ public class HRegionLocator implements RegionLocator {
@Override
public List<HRegionLocation> getAllRegionLocations() throws IOException {
+ TableName tableName = getName();
List<Pair<HRegionInfo, ServerName>> locations =
- MetaTableAccessor.getTableRegionsAndLocations(this.connection, getName());
+ MetaTableAccessor.getTableRegionsAndLocations(this.connection, tableName);
ArrayList<HRegionLocation> regions = new ArrayList<>(locations.size());
for (Pair<HRegionInfo, ServerName> entry : locations) {
regions.add(new HRegionLocation(entry.getFirst(), entry.getSecond()));
+
+ }
+ if (regions.size() > 0) {
+ connection.cacheLocation(tableName, new RegionLocations(regions));
}
return regions;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/03f3c392/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 520f210..3549791 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
@@ -6141,4 +6141,20 @@ public class TestFromClientSide {
}
}
}
+
+ @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 = ((ConnectionImplementation)admin.getConnection())
+ .getNumberOfCachedRegionLocations(htd.getTableName());
+ assertEquals(results.size(), number);
+ }
}