From 9d382c2f04b7346c91280080f391d84b127be5f9 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Wed, 13 Jun 2018 14:49:48 +0800 Subject: [PATCH] update --- .../org/apache/hadoop/hbase/client/HRegionLocator.java | 14 ++++++-------- .../test/java/org/apache/hadoop/hbase/client/TestHCM.java | 10 ++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) 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 d2706074e2..fadab46ed1 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 @@ -86,14 +86,12 @@ public class HRegionLocator implements RegionLocator { @Override public List getAllRegionLocations() throws IOException { TableName tableName = getName(); - NavigableMap locations = - MetaScanner.allTableRegions(this.connection, tableName); - ArrayList regions = new ArrayList<>(locations.size()); - for (Entry entry : locations.entrySet()) { - regions.add(new HRegionLocation(entry.getKey(), entry.getValue())); - } - if (regions.size() > 0) { - connection.cacheLocation(tableName, new RegionLocations(regions)); + ArrayList regions = new ArrayList<>(); + for (RegionLocations locations : listRegionLocations()) { + for (HRegionLocation location : locations.getRegionLocations()) { + regions.add(location); + } + connection.cacheLocation(tableName, locations); } return regions; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java index e592fa8303..f86a8414cc 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java @@ -18,6 +18,7 @@ */ package org.apache.hadoop.hbase.client; +import static org.apache.hadoop.hbase.HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -739,6 +740,15 @@ public class TestHCM { RegionLocations rl = conn.getCachedLocation(TABLE_NAME, ROW); assertNull("What is this location?? " + rl, rl); + // We're now going to test getAllRegionLocations() whether or not cache all region locations + conn.clearRegionCache(TABLE_NAME); + conn.getRegionLocator(TABLE_NAME).getAllRegionLocations(); + assertNotNull("Can't get cached location for row aaa", + conn.getCachedLocation(TABLE_NAME,Bytes.toBytes("aaa"))); + for(byte[] startKey:KEYS_FOR_HBA_CREATE_TABLE){ + assertNotNull("Can't get cached location for row "+ + Bytes.toString(startKey),conn.getCachedLocation(TABLE_NAME,startKey)); + } // We're now going to move the region and check that it works for the client // First a new put to add the location in the cache conn.clearRegionCache(TABLE_NAME); -- 2.13.3